Aug 29, 2011

Maxbotix Ultrasonic Rangefinder

I said in yesterday’s post that I haven’t had much time to work on projects. With hurricane Irene baring down on the East Coast at the time I am writing this entry, I don’t have anywhere else to go and little else to distract me while I wait out the storm. To pass the time, I decided to start experimenting with a Maxbotix LV EZ4 ultrasonic range finder I purchased from SparkFun a few weeks back. For those who don’t know, Maxbotix makes affordable sonar sensors for distance measurements and whatever else you can come up with. I have seen several small robot builds that use ultrasonic sensors to detect objects in the robot’s path and adjust accordingly. The sensors fire a 42kHz sound wave (beyond the range of human hearing by about 2x) and then record the reflections using the echoes to determine the distance of the object reflecting the wave.

 Figure 1. My Maxbotix LV EZ4 ultrasonic range finder
So why would I want one of these sensors and what am I planning on doing with it? Well, some time back we overloaded our garage with two refrigerators in one parking bay. In order to be able to open both doors and park a car in the bay the car has to be in just the right spot. Since we live in a world governed by electronics I figured hanging a tennis ball from the roof would be too primitive a solution to this pseudo-problem. Instead, I thought it would be cool to mount a sensor on the wall facing the car and have it track the movement of the car as it pulls into the bay. The idea was to rig the sensor to a microcontroller and have it change an RGB LED from green to yellow to red as the car moved closer to the perfect parking spot. At first I was really excited about this project because I thought it had a few unique elements that set it aside from other similar projects. Unfortunately, I have since come to find out that not only is this not a new project, but there are already a few commercial products that do this exact thing (including my traffic light plan…)

After some encouragement, I realized this could still be a learning experience and a fun project even if I do end up spending more time and money than it would take to buy something off the shelf. This entry is really just to show off some of the cool things this sensor can do and how to interpret its outputs. In addition, I will look at a few different configuration options you have when working with these sensors.

These Maxbotix sensors give you three options to read their outputs: analog, serial, and pulse width. The analog is probably the most popular and the simplest to understand. It is also the output I have chosen to start with in my design. The analog output works by increasing the output voltage of the sensor the farther away an object is from its position. Maxbotix specs this relationship at 9.8mV/inch with a minimum distance of 6 inches and a maximum distance of 254 inches (yes we are working in SI units here). That means that the sensor’s output voltage will increase by 9.8mV every time the object you are tracking moves an inch farther away.

The serial output uses the basic transmit (TX) and receive (RX) communication standard and the appropriate COM port on your computer. I am less familiar with this operation, but all you really need to know that it is possible to communicate with the sensor using a serial port hence you are transmitting a digital value, which is typically less noisy and more accurate.  

Lastly, the pulse width output uses low frequency pulses to monitor the object’s distance. The farther away the object is from sensor, the wider the pulse width and vice versa. Figure 2 below is published on MaxBotix’s website and it shows the difference between the analog pin output and the pulse width output.

Figure 2. Maxbotix LV EZ line pulse width versus analog output relationship, Courtesy of Maxbotix

My plan right now is to use a microcontroller to digitally sample the analog output and use the samples to track how close the car is to the ideal spot – meaning I will need to calibrate the sensor to the perfect spot. As the car gets closer I will write a function that controls the weights of red, green, and blue in an RGB piranha superflux LED. Right now I am still debating on whether to fade the LED between the traffic light colors or use discrete color states like a real traffic light. I will probably experiment with both and figure out which I like best, but reader input is always welcome.

Before I get ahead of myself, first thing is first: I need to make sure the sensor works. To make things simple, I built up a quick “acquisition” system using the ultrasonic sensor, my oscilloscope, and a little excel magic (and by magic I mean making a graph). Figure 3 shows the rig I built for testing. You can find my connection diagram at the end of this entry.

 Figure 3. Testing rig for rangefinder

By setting my oscilloscope’s time base to 2.5 seconds/division I automatically put it into roll mode, which means that it slowly tracked the sensors response in nearly real time since it is a digital store oscilloscope (DSO). As you can see in Figure 4, the only problem is that the oscilloscope tracks the output voltage and not the distance.

Figure 4. Oscilloscope readout of rangefinder's analog output voltage

Luckily, my scope can output the samples it uses to construct the waveform in a .CSV file, making it easy to process in excel. Using the 9.8mV/inch spec I was able to convert the recorded measurements into distance. Lastly, I time shifted the scope’s output for causality’s sake. You can see the result in Figure 5 below, though it is mostly a sample of me waving my hands in the front of the sensor and moving them back and forth...hence the sine waves. You may also notice that there are high frequency spikes in the middle of otherwise naturally following waveforms. These are an area of concern for me and right now I am thinking I may need to design either a filter in hardware or using some sort of averaging of the samples in the software to correct the issue.


Figure 5. Oscilloscope output translated into distance data via Microsoft Excel

I did a few more tests using walls as my detection sources and I have to say I am really impressed with the accuracy of the sensor. I tested the measurements I was getting from the sensor against some hand measurements made with a tape measure and they were virtually spot on.

Figure 6. Oscilloscope acquisition connection diagram
I am looking forward to playing around with this thing a bit more in the future, but for now I am pretty happy with the results of this initial test run. If you want one of these sensors to try out for your very own, Sparkfun offers them for about $31 shipped. I encourage you to visit Maxbotix’s website for their sensor selection guide, which is basically a flowchart that will lead you to the best sensor for your application. A good general purpose one is the EZ0 model of the product line I purchased. As promised, the connection diagram I used for my oscilloscope can be seen on the right.

Aug 27, 2011

EE Fundamentals: Series and Parallel, Part 2

It seems so long ago that I actually posted about electronics on this supposed “electronics blog”. I have been sort of busy lately with family and work so I haven’t really made much progress on any projects worth noting. Instead, I figured I would write the second part to the EE fundamentals piece I put up just over two months ago. The first segment looked at finding the equivalent resistance of series and parallel connections. In this entry, I will discuss how voltage and current flow through these two types of connections. Let’s get to it.

In my opinion, when you look at a circuit and attempt to figure out what is going on you need to first identify the types of connections so you can track the distribution of voltages and currents throughout the circuit. That being said, how do we know what the voltages and currents should be? It turns out this is easy to do using ohms law and knowledge of resistances connected in series and parallel – hence why I covered those first.

Series Connection
In series connections, the same current flows through each component connected in series. So if you have two resistors connected in series and you apply a voltage you would see the same current passing through each resistor when examined individually. Figure 1 shows that 4 milliamps of current appears at each point along the circuit path. What that means is that the current flowing into one side of resistor R1 is the same magnitude as the current flowing out of R1, into R2, and out of R2.

Figure 1. Current flow in a sample series circuit

Though each resistor has the same current passing through it, the voltage drops across them are different. According to Ohm’s Law, voltage is equal to current multiplied by resistance, and each resistor has a different resistance. When you do the math it turns out that the voltage drops across each of the resistors add up to the source voltage, another important aspect of circuit analysis (more on this in another EE fundamentals entry). Figure 2 shows, under the same conditions as Figure 1, the voltage drops across both series resistors in the circuit.  

 Figure 2. Voltage drops in a sample series circuit

Parallel Connection
Unlike series circuits, parallel circuits do not have the same current through each resistor (unless the resistors are equal in magnitude). Instead, the current through each resistor is regulated by the voltage across each “branch”. Where current is constant through a series circuit, voltage is constant across all branches of a parallel circuit. In this case the constant voltage is equal to the source voltage (100V) meaning that the current through each resistor is going to be equal to 100V divided by the total resistance in the branch. If you were to add all these currents up, you would find that the sum is equal to the current provided by the voltage source (i.e. battery, external power supply, USB port). Figure 3 shows how this is the case.

 Figure 3. Current and Voltage breakdown of parallel circuit

R1 and R2 are in series so the total resistance of the first branch (reading from left to right) is 25k. In each subsequent branch there is only one resistor present therefore the resistance in each branch is equal to the nominal value of the resistor. This results in a different magnitude of current flowing through each branch.



Now, for anyone paying attention to my last post about series and parallel circuits you might think – hey, can we reduce this circuit down using parallel resistance equivalents and find the total current supplied by the source?  If there were such a person reading this that actually thought that then I would say obviously yes you can, but, since I know no such person exists, let’s go through the steps.



First we should look into the circuit from the source’s perspective. Looking into the circuit from the left (from the voltage source) we see a 25k (effective) resistor in parallel with a 10k resistor and a 5k resistor. Using the steps from my last post we find that the equivalent resistance is equal to approximately 2941.2 ohms. The equivalent model looks like Figure 4 below.

Figure 4. Equivalent circuit of Figure 3

There are two important things to note about this equivalent model. First, the equivalent resistance is lower than any branch resistance in the original parallel circuit as it will ALWAYS be when you find the equivalent resistance of two parallel branches. Second, the voltage is 100V across the equivalent resistance in the circuit, but it is also 100V across each branch of the original circuit.


Series-Parallel Connection

In case you were wondering about series-parallel connections, the same rules apply you just need to identify what types of connections you are seeing. If, for example, you added a 1k resistance in between the source voltage and the three parallel branches from Figure 3, you could still figure out the current drawn from the battery by reducing the 3 branches to their equivalent resistance. However, you would need to add an additional 1k-ohm to the total circuit resistance seen by the source when calculating the total current draw. I have put the example circuit and the measurements in Figure 5. The voltages have been approximated for simplicity. The actual results are around 25.4 and 74.6 volts on the appropriate nodes.

Figure 5. Series-parallel circuit analysis

That’s just about everything I have to say about voltages and currents in series and parallel circuits. I encourage you to look for other sources on the web and practice figuring out how to analyze these types of circuits if you are interested. While I try to explain things as best I can on this site, it’s hard to look at a subject you have studied for some time and try to act as if you are seeing it for the first time. As always, I hope someone will take something positive away from these entries.

Pop Quiz

I like giving these quizzes after the EE fundamentals segments so I think I will make it a regular thing.



Question: Find the total power dissipation in this circuit.



HINT: Power = current * voltage in the circuit element of interest. By summing the power of all the dissipative elements in the circuit, you can find the total dissipation. Assume the wires connecting the resistors are idea conductors - i.e. they do not dissipate power or drop voltage. Good luck.

Aug 3, 2011

Idiotic: Man Attempts Murder with Electric Chair









Not since William Kemmler has an attempted execution by electric chair gone so horribly wrong. In the final installment of this test segment for July, we look at the story of 61-year old Andrew Castle of Lancashire, England. Andrew and his wife had been married for 18 years and to most people in their neighborhood seemed like a perfectly happy couple. However, Andrew’s wife served him with divorce papers back in March of this year, and that’s when he snapped a little. Instead of spiraling down into an emotional blob, Andrew figured the more logical approach would be to try and kill his wife with a homemade electric chair. He spent the next few weeks constructing the metal monstrosity.

The circuitry behind the chair is brain dead simple. The house AC runs into a switch that is connected to the metal contacts of the chair. When a person sits in the chair, they complete the circuit between the two metal contacts and current flows through the person’s body – assuming the switch is flipped. From what I could tell in the article, it seems like the switch had to be manually tripped, which is why Castle needed to get his wife to sit in the chair first.

Andrew Castle Mug Shot, Courtesy of The Guardian
When he had the chair ready to go, Castle lured his wife into their garage to “chat” about their impending divorce. He actually got his wife to sit in the chair, but she figured out something wasn’t right when he tried to knock her out with a rubber mallet. Apparently the plan was to incapacitate her and then throw the switch. The two started fighting in the garage and it eventually spilled out into the street. His wife managed to escape and called the cops. By the time they showed up, Andrew was bleeding out in the back garden from self-inflicted knife wounds. After he failed to kill his wife, he tried to slit his own wrists. In one version of this story I saw, they said he even attempted to kill himself with the chair after he couldn’t kill his wife.

Can you guess why this is an idiotic use of electric power? Castle is not the first person to try and kill his wife, but I think it’s fair to say that he is the first to build his own electrical apparatus to do it. If he had been able to get her into the chair she likely would have been killed. England uses 50Hz, 230V AC on their grid and the circuit breakers don’t trip until you get around 23 amps flowing for 20 milliseconds. I have heard different estimates on the exact value, but it only takes about 5mA across your heart to cause ventricular fibrillation/cardiac arrest. If you are curious as to what happened to Mr. Castle, he is facing 10 years in prison for attempted murder after confessing to trying to kill his wife with a home-made electric chair.


BONUS:
William Kemmler
I thought I would take this opportunity to explain a bit more about William Kemmler. He was a merchant in New York at the time of his conviction. From what I have read he spent most of his time in bars getting trashed. One night, he came home drunk and, in a rage, accused his girlfriend Tillie Ziegler of planning to run away with his friend, believing they were having an affair. After fighting with Tillie for some time, he went to the barn, grabbed a hatchet, and bludgeoned her to death. Afterwards, he went next door to tell his neighbor that he had just murdered his girlfriend.

Kemmler was locked away in Auburn state prison after his conviction on May 10th, 1890. By August of that year, he was poised to become the first person to be executed by electric chair after New York instituted electrocution as the default method of death (replacing hanging). The State decided to use 2000 volts of AC for the electrocution largely because Edison, who was famous for his electrical experiments, publically stated the only thing AC is good for is killing.

After a short legal and ethical battle, the courts eventually sentenced Kemmler to be executed by electric chair on the morning of August 6, 1890. Kemmler was strapped into the chair via 11 leather straps and an electrode connected to his head. With the whole world watching, the switch was flipped and current flowed through his body for 17 seconds before it was switched off. Kemmler’s body tensed and turned bright red as blood vessels under his skin began to rupture. Once the chair was turned off, the doctors went to check his body and to their horror they found that he was still alive. The generator they had chosen to use was not able to supply an ample amount of current to kill him on the first shot. Spectators begged to turn the flow back on, but the generator needed to be recharged. Kemmler was burned everywhere the metal made contact with his skin and the smell of singed flesh filled the common room. He struggled to breathe for the next few minutes while the operators frantically tried to get the generator back online. When it was ready, they flipped the switch for a second time, finally killing him.

This first attempt at electric execution was hailed as a colossal failure and an inhumane act by all the papers the next day. George Westinghouse, who campaigned for an AC distribution system, was quoted as saying it would have been less cruel to execute Kemmler with an axe.

Aug 2, 2011

Noble: Power in Rural Villages



I came across this article on USA Today early this month, and I felt it should be the first story to win the “Noble” title. The story is one I have heard repeatedly since I first started really paying attention to renewable energy implementations across the globe. Millions still do not have access to electricity despite electrical distribution systems being in place for well over a century. Rural villages in Africa and India are not considered high priority by the local utilities so they end up getting wired into the grid, but never getting switched on.

The article I found talks about the efforts of Selco Solar Light Pvt. Ltd. I have never heard of the company personally, but they have installed over 125,000 solar panels in the villages of Karnataka state (India). Before their efforts, the people were living by night using kerosene lamps, which is the same technique people were using before Edison introduced his electric bulb for mass production. Kerosene lamps carry the same problems now they did 100 years ago: noxious fumes, fires, poor light quality, and wind susceptibility. 
                                                                Figure 1. Sample Solar Installation in India, Courtesy of USA Today

India’s government has been aggressively trying to expand the country’s energy production to match its exploding population and infrastructure. Current estimates say that they must quintuple their electricity production over the next 25 years to keep up with the demand. As a result, more companies are looking to decentralized off-grid power stations as a solution. The Indian electric utilities are seeking a 4x increase in off-grid power (around 200 megawatts) over the next two years.

The entire reason I picked this story though is for the human element. Technological advancements have improved the lives of the human race dramatically. The story mentions how, with the addition of solar power, the residents of rural villages have voiced that they feel safer at night. One 14-year old said that the fumes from the kerosene lamps used to make his eyes water and he was unable to read his books at night. Consequently, he had fallen behind in his classes. With the new solar lamps, he is now back on track and keeping up with his classmates.

Too often I feel people get bogged down in what technology can do for them rather than what technology can do for the world. It has always been my goal to be involved in something that has the impact these micro-grid solar installations have had. Through a company headed up by one of my co-workers, I have been aiding in a solar light design for villages in India. Rather than using a central solar panel, the light makes use of smaller panels to charge an internal battery for a short period. The batteries run a portable torch light for moving around at night. It may be small right now, but someday I hope to do more.