Genetics is not that hard (Sort of )

A few months ago, while aimlessly browsing youtube videos, i came across this great channel The Thought Emporium . I was initially browsing for some SDR / Radio telescopy related stuff and this guy does some of it.

But while watching his other videos, i came across some biology stuff ( he does a lot of those, along with laser / quantum physics and everything in between )

What really got me hooked was a specific video of his. ( Justin ) is Lactose Intolerant. So he went about creating “cure” for his condition. He successfully performed “Gene Therapy” on himself by injecting plasmids ( Basically DNA ) via viruses as delivery mechanisms to his digestive tract which produce the enzyme ( Lactase) which in turn breaks down the primary sugar of milk / milk based food items ( Lactose )

I was really surprised that it was even possible for an individual to accomplish this. So, i decided to investigate further.

Easy way to learn molecular biology basics

I am a engineer by profession and a hacker / scientist by passion. Having no interest in learning anatomy i never considered picking up biology as a hobby, but i had no idea biology ( molecular biology ) would be so fun. So i decided on going through some online stuff. after looking at sheer overwhelming overload of information, i realized that i need something short, to the point resource which is easy to understand and is not a dry “textbook” which makes me sleep whenever i try to read it.

So i came across this book

The Manga Guide to molecular biology
The manga guide to molecular biology

Yep, you read it right. Manga. It’s a very basic guide to building blocks of molecular biology – woven into a story which while mediocre, keeps the flow and pace of information very natural.

DNA & RNA

From this book, i learned the basics of molecular biology – Basically there are 4 nucleotides – Adenine,Thymine,Guanine and Cytocine ( A,T,G,C ) in human DNA. Now due to the molecular structure of these nucleotides, A always bonds with T and G always bonds with C

Almost each cell in the body, contains a nucleus ( depending on the type of organism, and cell type nucleus might be present or absent ). This nucleus contains the DNA, which is a long chains of AT and GC pairs woven together in double helix pattern.

RNA is just a single strand as opposed to the double stranded DNA

Proteins

Proteins are the building blocks of the body, everything in our body ( almost everything ) is made up of proteins. Skin, nails, tissues, Hormones, blood – everything is either a protein, or a combination of multiple types of proteins

Proteins are made up of amino acids, and there are a total of 21 known molecules, which combine in long chains to make up a single protein. The DNA, with its sequence of 3 base pairs ( called codons ) code for one molecule of building block of protein

As you can see from the above image, 3 Base pairs of DNA codes for a instruction of a single molecule of an amino acid( out of 20 possible), and these sequence of amino acids, in turn form long chains, which are proteins .

Out bodies are, in turn made up of Water, proteins and Carbs and lipids ( basically oily, fat-like substances )

Average Human Body Composition

So, to me it all looks very much like computers. The building blocks are binary ( AT might be thought as 1 , GC as 0). Now these 1’s and 0’s together form instructions which form protiens, which can be thought of as macros/function depending on the type of organism. now these functions combine together to form larger Routines ( Lets consider them as objects maybe ? – analogous to cells) which in turn makes up the entire program ( body ) work.

What really fascinates me is, a lot of these DNA sequences are shared between different organisms .

Image courtesy 23andme

So essentially, what it means is the building blocks for all organisms are same. and what we can do, is pick-up/isolate traits/genetic makeup from one organism and plant it into other organism(okay its wayyy more complex than it sounds), and that is my friends – Bioengineering.

Over the next few articles, ill go into various concepts of bioengineering, equipment builds, and a “Hello World” of bioengineering. Yes, its a costly hobby, but its magical to see your experiments manifest in living organism.I will be majorly working with Plants & Microbes initially due to ethical reasons – At least till i have learned enough to not screw things up royally.

Here is a teaser of whats to come

  1. The hello World of biotech, Bacterial Transformation of E.Coli Bacteria using GFP Plasmid (Essentially, modifying the E.Coli bacteria with DNA from Jellyfish to produce green florescence)
  2. DIY Biolab – Making your own DIY-Biolab ( India specific version )

Happy (Bio) Hacking 🙂

Reverse Engineering a wireless doorbell and performing a replay attack – Part1

I have a two-floor individual house and I am generally upstairs with my headphones on and the main door locked. Because of this, neither my grandparents (living downstairs) nor the visitors are able to reach me

So I decided to install a doorbell and settled on the below-shown doorbell from Amazon India, the problem is, this bell has two receivers and one transmitter. This solved my visitor issue( one receiver upstairs ) but my grandparents were still not able to reach me. So I obviously did not buy a new bell and decided to reverse engineer this bell itself to make a second transmitter.

Doorbell ( Phoenix waterproof doorbell ) @ Amazon.in
Phoenix wireless doorbell @Amazon.in

Reverse Engineering the transmission signal

The next step is to figure out which frequency band the transmitter is operating on. We can do this with an SDR and SDR software. You have various choices for the software, but I prefer either SDR# ( Windows ) or GQRX ( Linux and Mac )
https://airspy.com/download/ ( SDR#)
http://gqrx.dk/download (GQRX )

I had an SDR( Software defined radio ) lying around ( RTL-SDR v3 ), so I decided to use it. You can buy one from RadioJitter in India. These guys are official distributors for the RTL-SDR dongle.

RTL-SDR v3
rtl-sdr V3

This SDR is widely supported in various software.

Before you plug in the SDR to your USB port, make sure the antenna is connected.

Doorbell Frequencies

Depending on which country you are in, there are some frequency bands allowed by the government for general purpose use. For example in India, they are 433mhz and 865-867mhz. However, if you have cheap Chinese clones, they sometimes disregard the law and might operate on different frequencies
Here are the common frequencies consumer RF equipment generally operate on:

  • 315Mhz
  • 433Mhz
  • 915mhz

This Wikipedia article covers ism band( industrial, scientific and medical) across various countries. https://en.wikipedia.org/wiki/ISM_band

If you cannot find your signal around these frequencies ( these are actually bands, the width of the band varies, for example for 433mhz, the bandwidth is 1.7Mhz and center is 433.93Mhz which essentially means the bell can operate +- 1.72 Mhz from 433.92Mhz ( in India )

Let’s fire up GQRX( or SDR# depending on your OS ) and see which frequency our doorbell is transmitting at!

Video of Using GQRX to select the correct frequency

As the above video shows, the remote is transmitting at roughly 433.86Mhz. We don’t really need to know the exact frequency, as these transmitters ( and receivers ) generally work across a wide band, not just the mid-frequency of that band ( in our case, the mid-frequency for 433 MHz band is 433.92Mhz )

Now that we know the frequency of our doorbell transmitter, lets capture and analyze the signal

Capturing and Analysing the Signal

We can use various tools to capture the signal. As we already have the SDR, we will use it as the hardware. We can use either command line tools or the SDR software itself to record the signal. The signal itself is a waveform, so we can capture it as an audio and analyze it later using various tools. Both GQRX and SDR# offers functionality to capture the signal, however, I prefer command line tools.

#1 Using RTL_433

We will be using a tool called rtl_433 to capture the data. This tool offers various analysis options also and is very feature rich. You can download it from

https://github.com/merbanan/rtl_433

Once installed ( as per instructions mentioned in the link above ) open your command line and type the following command

rtl_433 -S all -f 433.83M

where 433.8Mhz is the frequency we figured out earlier from GQRX. -S stands for save all signals, -f specifies the frequency. This command will save the signals received by the SDR into a file in the current directory.

capturing and saving the transmitted signal via rtl_433

The above screenshot shows that the rtl_433 tool was able to capture and save the signal in a file called g001_433_8M_250k.cu8. Now we can analyze the waveform. We will use an open source audio editing tool called Audacity (https://sourceforge.net/projects/audacity/) for this. Install and open the tool, and then click on File -> Import -> Raw data

Importing the raw file generated via rtl_433 tool.

Then use the following settings :

Encoding : Unsigned 8 bit PCM
Byte Order : No endianness
channels : 2
sample rate : 250000

Now zoom in, you should be able to see the following output

3 repetitions of the same signal

This shows the waveform that was captured. You will be able to see here that the same pattern is being repeated 3 times. Now let’s zoom in and try to make sense of one repetition of this waveform.

The thick lines are 1 and the gaps are 0. The thin lines are the separators

If you know digital electronics, you know that a high signal is treated as 1 and a low signal is treated as 0. Here we can see that the gap will be 0 and the thick peaks will be one. The small line diving can be thought of as a separator. That is how we get our binary representation of the waveform, which is 00000101010000000000010000

To make this step easy, let’s try doing this with rtl_433. We already saved the waveform as g001_433.8M_250k.cu8. Lets load that file in rtl_433 in analysis mode

rtl_433 -r g001_433.8M_250k.cu8 -a
output of the command rtl_433 -r g001_433.8M_250k.cu8 -a

The output of the command confirms our findings with the manual waveform analysis. We also see that the length is 26bits and the long pulse length is 246. We also see that the same signal is being repeated 3 times.

Now we have everything we need to replicate the signal. We can use various methods to transmit this signal ( we will be covering these methods in other parts of this tutorial. For now, let’s use a 433mhz transmitter module ( you can get it from Amazon ) and Arduino. The module looks like this

433mhz transmitter and reciever
433Mhz transmitter and receiver. The smaller one is the transmitter. We will be using this in our exercise. Clicking on the image will take you to the amazon page.

Now, let’s see how to connect the module to the arduino. We will be using an arduino nano for this.

Your transmitter might look different, however, it will have a data, antenna, VCC and GND pin. Connect the VCC to 5v of nano, GND to GND pin. You can simply connect a wire to an antenna. image courtesy http://www.ignorantofthings.com

The above shows the typical wiring diagram. the data pin can be connected to any digital IO pin. In the above diagram, we are using pin D2. Make sure to power the transmitter with at least 5V ( i tried with 3.3V and found later the minimum required voltage is 3.7V as per the specs.

After prototyping on breadboard, my setup looked like this

Doorbell transmitter on a breadboard

I have used a library called RCSwitch for transmitting the radio signal. This library makes it easy to send the pulses with correct timing.you can download it from https://github.com/sui77/rc-switch. It can also be installed via the Arduino’s library manager ( just search for RCSwitch )


// by Shreyas ubale 
// Jun 14, 2019

#include <RCSwitch.h>

#define TX_PIN 2
// The transmitter is connected to pin 2

// Set the numer of transmission repetitions
#define TX_NUM_REPEAT 3

// Set the pulse length
#define TX_PULSE_LENGTH 320

// The inverted signal received by the SDR using rtl_433 or
// manually decoded from the raw signal
//
// Example:
//   original: 1111100110101110011010111
//   inverted: 0000011001010001100101000
#define TX_SIGNAL "0000010101000000000001000"


RCSwitch mySwitch = RCSwitch();
void setup() {
  // Set the serial baud rate to 115200
  Serial.begin(115200);

  // Automatically sets the TX_PIN to output mode
  mySwitch.enableTransmit(TX_PIN);
  
  // Set the pulse length (RCSwitch default is 320)
  mySwitch.setPulseLength(TX_PULSE_LENGTH);

  // Set the numer of transmission repetitions
  mySwitch.setRepeatTransmit(TX_NUM_REPEAT);

}

void loop() {
  // Wait for 10 seconds
  Serial.println("Ringing door")bell;
  mySwitch.send(TX_SIGNAL);
  delay(10000);
}

In the code above, we are using the TX signal we decoded via rtl_433, and as we figured out from the wave pattern, this signal is being repeated 3 times, so we are emulating that in the code as well.

Now as soon as you flash this code, you should be able to hear your doorbell ring. This will continue every 10s. If you wish to stop, just unplug the arduino. You can also fire up GQRX and listen in to the frequency and verify that the signal you are transmitting matches the signal that was captured via GQRX for decoding.

In the next parts of This blog, we will be exploring various ways of transmitting the signal ( YardStick one, RpiTX on a raspberry pi ) as well as different signal decoding techniques. In the last part, ill go through the whole process of designing a simple but configurable 433mhz push button ( Like Amazon Dash ) which supports wifi as well as RF and can use IFTTT service. So stay tuned 🙂

Please feel free to ask / suggest me anything related.

Happy Hacking!

A Re-found love for electronics

We all know that the IOT phenomenon is on a full swing nowadays. The rapid development of new and low cost devices has fuelled this phenomenon.

A year( or two) ago, i came across a new board, The Raspberry Pi – This is a cheap full blown computer with USB ports, ethernet ports, HDMI and GPIO ports. The best part is GPIO ports which lets you directly interact with hardware.It also lets you install many flavours of linux on it and has a 1Ghz CPU , and a dedicated GPU, which makes it much more powerful then regular Arduino boards.

Raspberry pi 2 Model b+

I did a lot of fun projects with the Raspberry Pi – some of which were software only and some hardware based. The ones i remember are :

  1. A Auto downloading web based torrent client using transmission- can be accessed from anywhere
  2. XBMC ( Now called Kodi ) : As a media library for my newly purchased TV
  3. Ambilight Clone with Ws2801 LED Strip and Raspberry pi
  4. Location based AC Switch with a IR led and Raspberry pi

But as i thought more about automating my home, the cost of raspberry pi became a big factor and  my interest slowly ebbed.

Until recently( a month ago ) when a friend told me about a marvellous new board – The ESP8266, A tiny board which contains a powerful wireless radio, with full TCP Stack and a integrated microcontroller and Almost 19 GPIO pins for a mere Rs150-250.

This sparked my interest. I have spent last 3 weeks ordering, playing and doing awesome stuff with the ESP8266. I have also started re-learning electronics from the ground up. I have re-built my electronics lab ( so to speak ) .

The coming posts on this blog will cover my experiments with the ESP8266, Ardunio , General Electronics and Software( which is my bread and butter ). I am writing a blog for the first time, so please bear with me and feel free to suggest/point out any mistakes/suggestions.

Time to Rock 🙂