Sunday, March 20, 2016

19th century radio technology meets the Beaglebone

In my last post, I described how I made a spark-gap transmitter and receiver. For the transmitter, I used a car's ignition coil to produce high voltage sparks, and for the receiver, I used a coherer to detect the transmissions. A coherer is a simple device - it consists of iron filings between two electrodes. Normally the filings have very high electrical resistance (tens of megaohms), but when the coherer detects electromagnetic waves, its resistance drops to about 10-20 ohms.

Back in the day, spark gap transmitters and coherers were widely used for wireless communication. One of the early pioneers in the field of wireless communication was  Arthur "Artie" Moore. He has a very interesting story. As a teenager, he built a steam engine using water-wheel driven lathe, and entered the model in a competition. He received as his prize a book by Sir Oliver Lodge titled "Modern Views of Electricity" which sparked his interest in the world of wireless. He, along with his friend Richard Jenkins, began to experiment with the ideas presented in Lodge’s book. They successfully built their own spark-gap transmitter and coherer receiver and taught themselves Morse code. Artie built a little radio station in his attic, and he would stay there all night listening to signals emanating from ships traveling the coastal waters around Wales.

Artie Moore's radio shack

In the early hours of 15 April, 1912, Artie received a faint Morse code signal on his coherer receiver:

"CQD Titanic 41.44N 50.24W."

CQD meant "come quickly distress."  In its next message, the ship also used the newer SOS signal -

"CQD CQD SOS de MGY Position 41.44N 50.24W. Require immediate assistance. Come at once. We have struck an iceberg. Sinking."

Artie was copying the signals, hardly believing the words he was writing. The final transmission he received was - "Come as quickly as possible old man; our engine-room is filling up to the boilers."

The RMS Titanic was sinking in the North Atlantic with more than 2,000 passengers and crew, and Artie was receiving the oceanliner’s final distress calls almost 3,000 miles away on his homemade radio. Artie continued to copy the increasingly desperate messages until the Titanic went silent about two hours after the first distress call.

The news of the disaster had not reached UK at that time, and no one believed Artie when he said that the Titanic was sinking. They thought that the Titanic was unsinkable. It was only two days later when it was announced in the national press, people realized he had been right. The receiving of these signals is believed to be the only land-based reception of the Titanic’s last transmissions in the UK, possibly the world.

Titanic's wireless room replica

The receiver

Getting back to our story, I built my own coherer in a vinyl tube with iron filings:

Iron filings coherer

A problem with the coherer is that once it gets activated, a physical tap is needed to reset it so that it can receive signals again. The system that resets a coherer is called a decoherer. I built a decoherer mechanism using a doorbell. Whenever the coherer gets triggered, it switches on a doorbell, and the bell's hammer hits the coherer and resets it.

Decoherer mechanism

The coherer cannot drive the bell directly, because it draws a lot of current. So, I use a transistor to amplify the signal from the coherer, and the transistor drives a small relay. The relay switches on the doorbell.

Receiver circuit

I connected the receiver to a Beaglebone to decode the received signals. I use an optoisolator to connect the output of the receiver to the Beaglebone. The optoisolator is an extra safety precaution to ensure that the Beaglebone is protected from any unwanted transients in the receiver circuit. I also added a flyback diode on the doorbell’s electromagnet to protect the optoisolator. Lastly, you’ll notice that there’s a brown capacitor in the doorbell to reduce sparking on the contacts. This is not necessary, but it should extend the life of the contacts.

The transmitter

In my previous post, I used a 555 timer-based ignition coil driver in my transmitter. I kept blowing the MOSFETs in that circuit from the inductive kickback produced by the ignition coil. So, I built the driver using a relay instead. The relay has been wired as an oscillator so that it turns the ignition coil on and off very quickly. This electromechanical driver is simpler and a lot more reliable. There's an automotive ballast resistor in the circuit to reduce the current on the primary side. I also salvaged a capacitor (aka condenser) from a car and put it across the relay's poles to reduce arcing on the relay. It's a standard ignition coil capacitor, and it filters out the inductive kickback coming from the coil.

Transmitter circuit (ignition coil driver)
Spark-gap transmitter

It is important to know that operating spark-transmitters is illegal because they create lots of RF interference. This transmitter can be operated without an antenna to keep the signals from going too far. 

Connecting the coherer to a Beaglebone and decoding Morse code!

I connected my coherer to a Beaglebone, and wrote some Python code to decode the messages it receives back to text (receiver circuit above explains the circuit connections). You can find my code here.

Here is a video of the system automatically decoding Morse code signals!

A strange phenomenon

While I was testing my program with the coherer, a loose wire in the receiver's circuit got disconnected, and the decoherer (bell) stopped working. To my surprise, I noticed that my program continued to receive the signals I was sending, and it was even correctly decoding them back to text! How could the system work if the decoherer wasn't even resetting the coherer? I disconnected the Beaglebone from the receiver, and just kept the interface circuit (the optoisolator) connected to it. Now, the receiver wasn't even connected to the Beaglebone. I started sending signals with my transmitter, and to my surprise, the same thing happened again. The Beaglebone was receiving the signals and decoding them! It took me a moment to realize that I had accidentally built a crystal radio (aka cat's-whisker radio). The LED inside the optoisolator was receiving the RF from the spark transmissions, and lighting up. The photo-transistor darlington pair in the optoisolator was amplifying this weak signal, and this was changing the state of the Beaglebone's GPIO pin. How interesting!

This "unintentionally made" crystal radio receiver doesn't have a very good range (only a couple of feet), but I’m sure it could be improved upon to make a more sensitive receiver (and without any mechanical parts).

I hope you enjoyed this project as much as I did. I'd love to hear your thoughts and comments.

EDIT: There is a better explanation for the strange behavior of the 4N33 optoisolator. I received this comment from Perry Harrington on Hackaday:

"If you look at the 4N33, the base of the darlington pair is brought out to a pin. This pin is left necessarily floating, but a darlington pair has typically a ~10,000 gain, so even a small current on this floating base will result in the pair amplifying a current. The bias transistor will have 3.3ma of current flow through it when fully triggered. My experience with 3.3v logic is that it has a ~2.7v input trigger threshold, so you’re looking at about 2.7ma flowing through the darlington to trigger the BBB. If my math is right, it would take about 270na of stray current to trigger the darlington of the optoisolator without a current being present on the LED.

You could probably replicate the results with a TIP120 wired up the same, with the base pin floating. If you are using a breadboard, the grid tie it is connected to would act as an antenna."

Tuesday, November 17, 2015

Rediscovering the magic of wireless communication


In this modern age of high tech gadgets, it is easy to take the technology around us for granted. If we look at the world around us as if we have never seen it before, it would be impossible not to be filled with awe and wonder.  In this article, I will tell you the story behind one of the most important technological inventions of modern times - wireless communication. I will also describe some of my own experiments with high voltage spark transmitters and coherers! But before I talk about those, a little background is necessary to appreciate how they work. We’ll have to step into the shoes of the early pioneers in the field of electricity and see the world in a completely different way!
Many years ago, when there were no cell phones or Internet, a great scientist by the name of Michael Faraday speculated the existence of electromagnetic waves when he observed the influence of magnetic fields on polarized light (Faraday Effect). Faraday speculated that light could be a form of electromagnetic disturbance propagating through space. However, this idea was received with considerable skepticism, and it was rejected by everyone until a mathematician by the name of James Clerk Maxwell proved it mathematically in his paper “The Dynamical Theory of the Electromagnetic Field” (1865). Maxwell predicted the existence of electromagnetic waves that could travel indefinitely at the speed of light until absorbed. He proved their existence mathematically without any experimental proof.

About thirteen years later, David Edward Hughes (an Anglo-American concertina player and inventor) observed something very bizarre. When working on his Induction Balance, a loose contact was creating sparks. Hughes noticed that a telephone circuit connected to his carbon microphone on the other side of the room was somehow picking up that noise. He took the telephone circuit outside, and he could still hear the clicks made from the induction coil up to 500 yards away! You could consider this the first mobile phone call in history. Hughes wrote -

“Further researches proved that an interrupted current in any coil gave out at each interruption such intense extra currents that the whole atmosphere of the room (or in several rooms distant) would have a momentary invisible charge, which became evident if a microphonic joint was used as a receiver with a telephone. This led me to experiment upon the best form of a receiver for these invisible electric waves, which evidently permeated great distances, and through all apparent obstacles such as walls &c. I found that all microphonic contacts or joints are extremely sensitive.”

Apparently, when Hughes showed this to members of the Royal Society, the scientists thought it was merely the result of induction. They did not realize that Hughes had accidentally discovered the electromagnetic waves that Maxwell and Faraday had predicted. Hughes never published his findings.

Hughes wireless apparatus, a modified version of his carbon microphone detector (left), and a clockwork driven spark transmitter and battery (right) (source)

In the 1880s, physicist Heinrich Hertz was trying to confirm the existence of Maxwell’s electromagnetic waves. After observing induced sparking in a Riess spiral, Hertz concluded that this phenomenon could be used to detect the waves. He set up a spark gap transmitter, and a receiver (which consisted of wire loop with a small spark gap). Hertz thought that if the spark gap transmitter created electromagnetic waves, the wire loop antenna would pick it up, and he would see a small spark at the gap in the antenna. Hertz would look at that gap in a dark room with a magnifying glass to see if any sparks appeared.


Around the same time, a scientist named Oliver Lodge was investigating some issues with lightning rods. To simulate lightning, he was using two Leyden jars to create high voltage sparks. He had two wires connected to the gap (as shown in the figure below) with multiple spark gaps between them. He observed that when the Leyden jars discharged, sparks appeared at all the spark gaps simultaneously. He also noticed that sparks at certain locations were more intense than others. In a darkened room, he could clearly see a visible glow between the wires at one-half wavelength intervals. When Lodge saw this pattern, he knew that he had discovered the electromagnetic waves predicted by Maxwell.

Oliver Lodge's experiment (source: "Oliver Lodge: Almost the Father of Radio" by James Rybak)

Hertz also saw the spark he was hoping to see. Through the experiments of Lodge and Hertz, the existence of Maxwell’s elusive electromagnetic waves was finally confirmed.

Lodge went on to design better devices (detectors) to detect these waves. The detector that Lodge used was called a “coherer”. I think it was based on the idea of Hughe’s carbon microphone detector. A coherer consists of iron filings between two electrodes. Normally, the resistance between the two electrodes is very high. When a spark is created, the resistance between the electrodes drops.

My homemade coherer

After reading the story behind the discovery of electromagnetic waves, I wanted to make my own coherer. The amazing thing about the coherer is how simple it is. Why it works is also mysterious. It seems the electromagnetic waves somehow magnetize the filings, and they get closer to each other. I built my coherer inside a vinyl tube with iron filings between two ¼” bolts.

I noticed that a very small amount of filings is required between the bolts for the coherer to work. Also, the performance of the coherer depends a lot on the gap between the bolts. I adjust the gap by first pushing the bolts until my multimeter (in continuity checking mode) beeps. Then, I pull the bolts out just a little until it stops beeping. That seems to be the perfect gap. Normally, the resistance between the two bolts will be very high - in megaohms. When the coherer detects electromagnetic waves, the resistance drops to 10-20 ohms. Normally the coherer will stay in this state of low resistance, and you have to tap it to decohere it. I am thinking about making an automatic tapping mechanism with an electromagnet.

Spark-gap transmitter

To test my coherer, I used a piezoelectric stove lighter. The electric spark created by the lighter was able to trigger the coherer, but it was not very reliable. So, I decided to build a better spark transmitter. I went to a junkyard and salvaged an ignition coil from a car. An ignition coil is a step-up transformer which converts 12V (from the car’s battery) to 20,000V-30,000V. This high voltage is sent to the spark plug to create sparks.

There are different kinds of ignition coils. To identify the coils, you could measure the resistance on the primary and secondary coils. The primary coil should have a very low resistance in the range of 0.4 to 2 ohms, and the secondary should have high resistance in the range of 6K to 15K ohms.
To test the coil, I connected a 9V battery to the coil’s primary. That was enough to create a spark on the secondary coil. When I told my dad about it, he shared his wisdom on how a car’s ignition system works, and said that I could improve the sparks if I add a capacitor across the contact point. In a car’s ignition system, there is a capacitor (aka condenser) across the contact breaker. This capacitor absorbs the back-EMF generated by the ignition coil, and reduces arcing on the primary side. This has two benefits. The first is that it improves the life of the contact breaker by reducing burning, and the second benefit is that it results in more intense sparks on the secondary. This is because the magnetic field collapses quicker when the capacitor absorbs the transient back-EMF generated  on the primary side, and this increases the induced EMF on the secondary.

So, I looked around in my workspace for a capacitor with a high enough voltage rating, but didn’t find any. Then, I got an idea while watching BBC’s “Shock and Awe: The Story of Electricity” presented by Jim Al-Khalili). In this show, they described how a Dutch scientist by the name of Pieter van Musschenbroek discovered how to store electricity. Before Musschenbroek’s discovery, people could generate electricity with devices like the Hauksbee generator, but did not know how to store it. In those days, people believed that electricity was like an invisible fluid. Using this analogy, Musschenbroek thought that if electricity is like a fluid, it should be possible to store it in a jar, just like we store water! So, he filled a jar with water, and used that to store electricity. He made what’s called a Leiden (or Leyden) jar (named after a Dutch town named Leiden). The Leyden jar was the first capacitor.

Musschenbroek's Leyden jar (source)
I made my own Leyden jar in a bottle filled with salt water. I hammered a nail through the cap and wrapped aluminum foil on the outside. I connected this Leyden jar across my contact point. To my surprise, it actually reduced sparking on the primary side, and made the sparks on the secondary a lot more intense!

Later, I designed an ignition coil driver circuit using a 555 timer for continuous sparks. After a lot of trial and error, and blowing several 555s, this circuit seems to be working reliably.




You could adjust the potentiometers to change the 555’s output waveform, and this also changes the quality of the sparks.

I have also tried connecting two ignition coils (in reverse-parallel configuration) to increase the output voltage. Based on the length of the spark gap and the dielectric breakdown voltage of air, I estimated the voltage to be somewhere around 60,000V! Be very careful when doing these experiments. Contrary to what you may want to believe, 60kV shocks don’t exactly feel pleasant (words of experience). I got lucky. Seriously, be very careful when working with high voltages. Carelessness could be fatal. Don’t get close to the spark gap or to any antenna connected to the transmitter.

Anyway, here’s a video of my spark transmitter and coherer:

This transmitter can reliably trigger the coherer from a distance. I’m now thinking of ways to extend the range. Back in the day, when spark-transmitters were actually used for communication, people realized that adding a high voltage capacitor on the coil’s secondary could increase the gap current by orders of magnitude without changing the transmitter input power. See “How Spark Transmitter’s Work” by Hal Kennedy.

A tuning coil and capacitor could be added to the ignition coil’s secondary to form a tuned circuit. When the capacitor is fully charged, it will discharge through the tuning coil and spark gap which will cause the capacitor and tuning coil to resonate at their resonant frequency. This will reduce the bandwidth of the electromagnetic waves created from the sparks and increase the range of the transmissions.

source: “How Spark Transmitters Work” by Hal Kennedy
By the way, when you have high voltage at your disposal, don’t miss the opportunity to make a Jacbob’s ladder, just like Dr. Frankenstein!

“It’s alive! It’s alive!” - Dr. Frankenstein

Tuesday, June 23, 2015

Motion sensing water gun Tweets photos!

Hello folks! I haven't updated this blog in a long time. I am in San Francisco now, working at Punch Through Design (the makers of the amazing Lightblue Bean). We have a lot of nerf wars happening in our office all the time, so I decided to bring office warfare to the next level by making a motion activated water gun that also takes pictures and posts them on Twitter. I modified the water gun (a motorized Super Soaker), and connected it to the Bean. A PIR sensor is used to detect motion.

I have used Node-RED and Python to link the Bean to a Twitter account. The Node-RED flow runs on a computer, and wirelessly monitors the Bean's serial output. If the Bean detects motion, the computer takes a picture, and uploads it to Twitter. The Node-RED server can also monitor the Twitter account for incoming direct messages. If I send a message with the correct password, I can enable or disable the system. This way I can turn the system off before I enter the office, and turn it on after I leave. It has been driving people crazy here, so I think this project is a success! Check out the tutorial on Instructables (be sure to vote for it if you like it)! :)

Monday, May 09, 2011

Building a computer controlled wireless robot

For a long time, I have been trying to find the cheapest and easiest way to control electronic devices wirelessly using a computer. It can open up a lot of possibilities. For example, you could build a radio controlled relay board, and control it from your computer. You could even control the board with a "small" computer such as an Arduino (or any microcontroller for that matter). If your Arduino has an Ethernet shield, you could use it as a Web server and control your relay board from anywhere in the world (as long as you have access to the Internet of course). There are many things that you could do without creating a mess with wires. I am mainly interested in this because I need a computer controlled wireless robot. A little background -

I have been working on a project at the Mobile Robotics Lab of IISc (Indian Institute of Science), Bangalore, in which I have to design a vision based obstacle avoidance algorithm for robots. What does that mean? Well, I basically have to design a robot that uses nothing but a small camera to identify obstacles in its path. Since image processing and computer vision stuff is usually quite CPU intensive, it is difficult to implement this code on a small robot. Small microcontrollers can't handle that stuff. So, the solution I came up with involves a wireless camera that transmits video to a nearby "big" computer. This big computer runs all the dirty computer vision codes, identifies the obstacles, and then somehow tells the robot how to avoid them. This is where wireless communication comes in.

To create a wireless link, you could rip the guts of a cheap RC car and use its transmitter and receiver to control your robot. That's one technique. I did something similar a few years ago . This time, I wanted to do things a little more elegantly, without destroying an RC car. I found this really inexpensive RF transmitter/receiver pair at a local electronics shop in Bangalore:

They cost only 200 INR (about 4 USD)...both transmitter and receiver. What a steal!

You can also find these online at Sparkfun:

Transmitter -
Receiver -

They cost a little more on Sparkfun, but they're still inexpensive. The ones on Sparkfun operate at 315 Mhz, but the ones I have, operate at 434 Mhz (like this one). I don't think that would make any difference in how you connect them.

To use these cheap RF modules, you could either connect them directly to your microcontroller/computer, or connect them with the help of parallel - serial encoder/decoder ICs.

I used the HT12E (parallel to serial encoder) and the HT12D (serial to parallel decoder) ICs. The HT12E is a 12 bit parallel to serial encoder. Of those 12 bits, 8 bits are the address code, and the remaining 4 bits are data. To send a signal, the address bits on the transmitter and receiver should be the same. It's like a password. You can use a single RF transmitter to control different RF receivers (at the same frequency) by configuring the address bits appropriately. All receivers would have to be set to different addresses. With 8 bits, you can create a total of 256 combinations.

Here's what the serial data coming out of the encoder looks like, in an oscilloscope:

If you look closely, you'll notice that there are 13 peaks (instead of 12). I'm not sure what the first bit is for. (Probably a parity bit?) The 8 bits coming after the first bit make the address, and the last four make the data being sent. You connect your microcontroller's (or computer's) parallel output to the 4 input channels on the encoder. With 4 bits, you can create 16 unique commands. That is enough for my purpose.

For more on how to use these ICs with the Tx/Rx, check out this excellent article -

Here's a flowchart of my system:

I've connected an Arduino to my computer which acts as an interface between the encoder and my computer. Here's the Arduino that I'm using:

It's a ModernDevice BBB Arduino Clone that I received from my friend Tom Boyd. I've been hooked to it ever since I got it! You should definitely get an Arduino if you don't already have one. It's the perfect tool for the programmer who enjoys playing with electronics. And it's also very easy and fun to use!

Tom has some excellent tutorials on electronics and programming on his website that keeps inspiring me! Check out some of his awesome Arduino projects - http://sheepdogguide

The robot I am using is a Microbric Viper robot that I received from Microbric a few years ago. The Microbric Viper comes with an IR module which can be used to communicate with a computer wirelessly. Although I've used it in the past, it's kind of difficult to set up because infrared communication requires line-of-sight. Moreover, the range is quite limited.

I'm not going to get into the details of connecting the encoders/decoders with the RF modules because it is already covered in detail in the article I mentioned earlier. I am however, going to share some difficulties I have faced in using these RF modules.

When I was testing the receiver on a breadboard, I was powering it with an AC to DC adapter. The voltage was fine, but the decoder did not work at all. Why? When I was debugging the circuit with an oscilloscope, I realized that the signal at the encoder side was fine, with 13 distinct peaks. However, when I checked the data at the receiver side, I realized that there was some sort of noise, and the peaks were not distinct. The address bits were too close together and sometimes even merging together. Since the address bits on the decoder side did not match with this noisy data, it rejected it. I figured that this noise could be caused by radio interference noise from the AC to DC adapter. So, I removed it and powered each of them (Tx and Rx) with two AA batteries.

The other thing I noticed is that if you connect the third pin of the RF receiver (which is either marked as "Data" or "CE") to the data-IN pin of the decoder , the circuit won't work. Leave it unconnected.

I'm using a 1/4 wave monopole antenna (6.8 inches) with the RF modules. It's just a single core wire. The range I get is amazing. I think I get about 100-120 ft (through walls), and 1000+ ft outside (line-of-sight)! More than enough for my purpose. When I test it outside, it just keeps working no matter how far I go. So, I don't really know its limit yet!

The Arduino communicates with my computer through a USB to Serial cable. If I want to make the robot move forward, I would send the character '1' to the Arduino. It would recognize this as a command and forward it to the transmitter. I can send four commands to the Arduino - '1', '2', '3' and '4'. On receiving these characters, it sets the appropriate data bits on the encoder and transmits the signal.

Arduino code:

On Windows, I use a C# application to send these commands to the Arduino. On Linux, I just use the terminal. My Arduino shows up as /dev/ttyUSB0. To send the command '1', I write...

echo -n "1" > /dev/ttyUSB0

This makes the robot move forward. For a more interactive session, you can use the screen command:

screen /dev/ttyUSB0 9600

More on this here -

And finally, the thing you were probably waiting for...a video! -

I hope you enjoyed this post. My next step would be to put a wireless camera on this robot and test my obstacle avoidance algorithm. Wish me luck.

I hope the information I've shared helps you build your own radio controlled electronic devices and robots!

So what did you think? I'd love to hear your feedback in the section below.