Web Based Water Metering with ioBridge

After the real-time power meter project I did back in January, the next logical step seemed to be an ioBridge based water meter. Lets face it, power conservation isn’t going to save the planet on it’s own. There are plenty of resources besides electrical power that each of us use on a daily basis. All these resources have a measurable impact on the environment and our bank accounts. Reducing consumption benefits us all.

I grew up in the country where our water was supplied by a well. Conservation was easy back then: if we used too much water, the well ran dry. These days my water comes from city. The water doesn’t run out if I shower too long, but I still want to save water (and save money) when I can.

This project was a little easier than the power meter in terms of technical skills but it did require some basic plumbing know-how. The concept is simple enough: I installed a water meter on my home’s incoming water line which flips a switch for each gallon of water traveling thought it. The switch creates electrical pulses that are are counted by an ioBridge module. The data is tracked by ioBridge.com using their free web based data logging service.

My plan was to do this over a weekend, but it only really took about an hour or two. I think I spent more time at the hardware store picking out the proper fittings and adapters than actually installing the stuff.

Parts needed:

DLJSJ75C Water Meter
IO-204 ioBridge Module
teflon plumbing tape
assorted plumbing fittings
2-conduction wire, about 20 ft.
PVC primer and cement
hacksaw (for cutting the pipe)
soldering Iron


Step 1: Figuring out where to put the water meter

My house is in a flood plain (more specifically, it’s in a Florida swamp). Therefore, my house is built on stilts. This made it incredible easy to access the water main. It was fastened to one of the cinder-block posts supporting the house. All I needed was a straight section after the main water shut-off valve to install the new meter. After removing a bit of insulation, I had my straight section to work with.

Step 2: Figuring out what fittings to use

The water meter came with two coupling adapters to make installation easier. However, I still needed to get from 3/4″ NPT threaded end to PVC pipe. Not that this is difficult. There are just soooo many plumbing fittings to choose from in a big box hardware store. It took a little while to figure out exactly what I needed. I also wanted to include a hose connection. Not a big deal, just another couple of fittings to figure out and I was ready to go.


Step 3: Assembling the water meter section

Because I didn’t want to shut off the water and then get stuck half way through the project, I did as much as I could without actually cutting the main water line. This meant assembling the different fittings and connection pipes ahead of time. All of this was very simple. It required a little teflon tape for the threaded connections and some PVC cement for the pipe fittings. Now I had a solid section that could be installed quickly.

Step 4: Marking the water line

Since the water meter section was already assembled, I knew exactly how much pipe to remove from the main water pipe. I just held the assembly up to the pipe where I wanted to install it, then made a mark .75 inches from the end on each side. The .75 inch extra is needed because the main water pipe fits into the water meter assembly ends by that much.

Step 5: Cutting the water main

After I turned off the main water shut-off valve, I cut the water pipe where I had marked earlier. A gallon or so of water came out of the pipe from what was trapped in the plumbing above. I mopped up the water with a towel and dried the area the best I could.

Step 6: Water meter installation

I unscrewed the threaded couplers from both ends of the water meter and glued them onto the cut ends of the pipe. After the PVC cement was set, I just reconnected the meter to the couplers and tightened them down. All very, very easy.

Step 7: Check for leaks

I slowly turned the main valve back on and checked for leaks. Fortunately, I didn’t have any.

Step 8: Running the signal wire

Nothing special for this part. The water meter comes with a 6 ft section of cable. My ioBridge module was in my house above. I drilled a tiny hole in the floor and ran a long section on 2-conductor wire from my ioBridge module, through the hole in the floor, to the water meter. I just soldered the wires, covered them with heat-shrink tubing and tucked the wires behind the water line to keep them from getting exposed to the elements.

Step 9: Connection to ioBridge

This is super simple as well. Using a screw terminal board, I just connected one wire to ground and the other to a digital input. The water meter contains a reed relay contact switch. As the meter reads each gallon of water, it connects and disconnects the switch. All ioBridge needs to do is read the numbers of times the switch closes to get the number of gallons used. The latest revision ioBridge modules have built in pull-up resistors, so I didn’t even need to add them myself (as done here with the Twittering Toaster)

Step 10: ioBridge configuration

ioBridge recently added a free data-logging service to their long list of features. The cool thing about data-logging is that I don’t need to have a web page up to record the data. The ioBridge module sends the meter pulse counts to the ioBridge server and they keep track of all the data for me. This means I’m not running a computer 24/7 just to log the data. To configure my setup for logging the number of pulses, I signed into my ioBridge account and set the I/O channel to send data when there was a digital input state change. This way data only gets sent when the contact switch in the water meter is tripped. I then went to the “modules” tab and clicked “add log”. On the next screen, I was presented with a few options for data logging. I chose “Digital Input Counting”, then I went on to select the module and channel number. For the “States to Count”, I picked “On State” and I used 15 minutes for the frequency. The frequency basically sets up how the plot will look. Choosing 15 minutes means the plot will be divided into 15 minute chunks. Finally, I clicked create log and that was it. It took about 15 minutes for my first data point to show up, but I’ve been collecting data since!

That’s it, only 10 steps! Now when I log into my ioBridge account, I can view the past day, week or month of water usage down to the gallon in 15 minute windows. The plots are interactive and allow zooming, panning, etc. ioBridge also gives the option of downloading the data in a CSV file. This feature will come in handy when I need to import the data into Excel and do a little analysis.

And before someone asks… I don’t plan on connecting my water meter to twitter. Although I’m sure there is already a Tweet-a-Liter in the works out there somewhere.

Posted in Uncategorized | Tagged , , | 10 Comments

Real-time Web Based Power Charting

Do-It-Yourself Smart Grid Monitor

Brief project description

This post details a real-time web based household power usage chart. The end result is a live chart in a web page that updates every 10 seconds with the instantaneous power usage for my entire house. The electrical current is measured on the main lines entering my home with AC clamps. The signal is then conditioned with a simple circuit and monitored by an ioBridge module. The ioBridge module takes care of feeding the data to the internet without the need for me to host a power hungry home web server. By using ioBridge widgets with a few JavaScript API calls on my web page, I am able to chart the data with Google Charts as it is measured and make kilowatt-hour calculations in real-time.

(This chart will begin plotting in 10 seconds)

Not so brief project description

Ever since I started paying for my own utility bill, I’ve been interested in my household power usage. Years before the Kill-A-Watt was introduced, I was measuring the power consumption of individual appliances in an attempt to figure out exactly where my money was going. Of course, back then I used a very low-tech way of doing it. I turned off and unplugged everything in the house, then went outside and timed how long it took my power meter’s “wheel” to make one revolution. Then I turned on appliances, one at a time, and re-timed a power meter wheel revolution. With a little simple math, I was able to convert the time differences into watts and get a pretty good idea of power usage of every appliance.

These days, EVERYONE is interested in lowering their household electrical consumption. One way to help do that is by tracking and understanding power usage real-time (not a month later when you get the electric bill). The following will describe the details involved in making a real-time web based household power usage chart.

There are a few ways to measure electrical power. The way I chose might not be the most accurate but it achieves two of the main criteria for this project. It had to be cheap and I didn’t want to screw with my home electrical wiring to make it work. I did not want make an electrical connection with main power wires. The idea of interfacing directly to 220v makes me nervous. I could have used a Kill-A-Watt but it is only good for one outlet. Plus there is no way to get at the actual data, just look at it. I’ve also seen commercial power meters for this kind of thing. Since those meters can cost over $1000, I didn’t want to go that route either.

For this project, I used an AC clamp. With an AC clamp, it is possible to measure the current traveling through a wire without physically touching it. Basically it is a simple transformer where the wire of interest acts as the primary coil and the AC clamp is the secondary coil. Most AC clamps are integrated into a multi-meter. I used a stand-alone type for my project. It outputs 10mV per ampere and is intended to be connected to a multi-meter. All you do is multiply the voltage reading by 100 to get the current in the wire. These can be found for $20 or less on Ebay. Mine were made by Steren, model MUL-285. The great thing about using an AC clamp is that I was able to do all of my prototyping without ever turning the power off.

The only issue with an AC clamp is that the mV output is also AC. This isn’t a problem for a multi-meter since it can be set for measuring AC voltages. However, the ioBridge module is expecting a DC voltage on its analog input pin. Therefore a little signal conditioning is required to convert the AC RMS value into a DC equivalent. The circuit I used was my own design and used components I had on hand, so I’m almost certain that it’s less than ideal. After I was done soldering it up, I found a simpler circuit here. You may want to try it instead.


The main component in the circuit is an Analog Devices AD8220 instrumentation op-amp. This part only comes in surface mount style packaging. I needed to use a tiny SMT-to-DIP adapter board for my circuit. Don’t feel like you need to use the exact same part. Any rail-to-rail instrumentation op-amp will work just fine. For example, the AD627 (Analog Devices) will work too and it comes in a breadboard friendly DIP package. In my circuit, I used a 16k resistor to achieve a gain of 4. Feel free to use a different resistor to get to a particular gain you need. However, any change in gain must be compensated for in the JavaScript of the webpage.

The other part of the circuit is a “leaky” peak detector made with a diode, resistor and capacitor. Its purpose is to translate the AC wave peaks into a DC voltage level. The 47k resistor causes the leakiness. Since the voltage level updates 60 times per second, adding that resistor increases the system’s response time.

The potentiometer is used for offset calibration. I used a 15-turn pot for the best accuracy. To calibrate, power the circuit, make sure the AC clamp is not on any wire and measure the circuit’s voltage output. Adjust the potentiometer until 1.000v is reached.

Caution:
Don’t touch ANYTHING inside the breaker box! The beauty of using an AC clamp is that it’s designed for this sort of thing. Just clip it on a line you’re interesting in measuring and put the cover back on immediately. Touching the wrong thing in there will kill you. I don’t assume any responsibility if someone injures themselves trying to recreate this.

To access my particular breaker box, I just removed the front panel by unscrewing the four screws in the corners.

I used two converter circuits in my setup. In most US homes, the electricity comes in as 220v on 3 main lines. Some appliances, like ovens and clothes dryers, are connected to these 220v lines directly. However, by using just one of the lines, the power is reduced to 110v for all the wall outlets. Usually, a home’s electrical wiring is divided into two sections. One line (known as a leg) powers one section of the home and the other line powers the other side. To get the total power usage in my house, I put an AC clamp on both legs and added the measurements together.

If you are interested in monitoring a single breaker or maybe a single appliance, this method will still work. Just put the clamp on the wire coming out of the breaker. I measured single appliances by splitting an extension cord and clipping the clamp around the wire. (It is necessary for the clamp to be places around a single wire only. Clamping all the wires of an AC electrical cord simultaneously won’t give you a reading.)

To fine tune the scaling factor for converting measured DC voltage to AC current I used a Kill-A-Watt and a portable space heater. I first measured the current draw with the Kill-A-Watt. I then did the same thing my setup, using the clamp on a modified extension cord. Assuming the Kill-A-Watt was accurate, I saw that my readings were about 7% off and adjusted accordingly.

Getting the data to the web was probably the easiest part of this entire project. I just connected the outputs of my converter circuits to the I/O ports of an ioBridge module. The module was connected to my home network using a LinkSys wireless gaming bridge. That saved me from running another Ethernet cable to the electrical panel.

I then went to ioBridge.com and made two analog input monitor widgets, one for each leg of power to be monitored. I embedded these two widgets in my webpage to track the readings. My ioBridge module also monitors the inside and outside temperate.

To convert the voltage reading to current, use the following formula:

I = (VoltageReading – 1) x 100 / Gain


To convert this to Watts, the math gets a little fuzzy. A number called the “Power Factor” is needed. The power factor is different for different appliances. Some appliances use voltage and current in phase with each other. This is the case with a heater for example. An electric heater would have a high power factor, maybe 90%. Other things, like computers, use power differently and their voltage/current demands are not in phase. In these situations, the power factor is lower, maybe 35% to 50%. Your entire home is a combination of all these devices with differing power factors. In order to calculate power usage in watts from voltage and current, you’ll need to make a guess at the power factor. Most people use 60% as a good estimate for a home’s average power factor. I used 75% in my calculations. To get power use the following:

Assuming V = 110v (US homes)

P = V x I x Power Factor


As for the plotting and the use of Google Charts… I’m actually a JavaScript newbie myself. I’d rather not try to explain my patchwork of code. The source code is available for my power charting page and the embedded comments should help explain a little of how it works. Code involving the ioBridge widgets was taken from the Temperature Chart example available on their website. More information about the Google Chart API can be found here. I attempted to write the code in a way so that others could reuse it by just changing a few variables. But if you use a different circuit, you’ll need to make changes to compensate for different offset, gain and scaling.

There are a few features of the chart that I’d like to point out. First, it automatically updates every 10 seconds. It will continue to add more points for an hour. After an hour, data older than an hour will be scrolled off the chart to make room for new data. This limitation is because of the way Google Charts works. A Google Chart is created through the use of a URL. Since a URL is limited to 2048 characters, there is a limit on the amount of data that can be plotted at once. The other thing I want to mention about the chart is that it will automatically scale the Y-axis.

In this effort to track and minimize power usage, you may be wondering about the electricity consumed by the ioBridge module the LinkSys wireless bridge. Together they use a mere 5 watts! That is considerably less that running a home web server to publish this data.

After using this setup for a few days, I’m amazed at how much power our hot water heater uses (as you can see in the picture below).

Special thanks to Steve for suggesting this as a potential application of ioBridge hardware/software.

And yes… I do know “The Energy Detective” exists. I don’t believe the T.E.D. will publish data directly to your web page without a server running in your home. Besides… it wouldn’t be a very good DIY project if I didn’t actually do it myself.

PS: If you add a comment that includes a link, I probably won’t publish it. Most times, the links are thinly-veiled attempts to plug other products or services.

Posted in Uncategorized | 32 Comments

The Picodore 64 – a Commodore 64 PDA

This post is my first attempt to document the design and construction of my Picodore 64. It’s a Commodore 64 based PDA / Palmtop. Really, all the hard stuff was already done before I joined the DTV hacking scene, I just stuck it all together in a nice small package.

Here are the specs:

Mainboard: Hummer DTV
Construction: Hobby plywood covered in faux stainless steel contact paper
Size: 6.5″ x 6″ x 1.5″ (closed)
Power: 7.5v wall adapter or 6 rechargable AA NiMH batteries
Screen: 5″ LCD Keyboard: 69-key QWERTY Sound: Ampilfied 1.5″ 0.4W internal speaker

Connections: power, userport/joystick, serial disk drive, audio/video output, headphone jack, external PS/2 keyboard, SD card slot.

Addition peripherals: 1.75″ x 1.5″ mini Atari joystick.

Features: on screen display for volume and brightness control, auto sensing of external keyboard connection, programmable funtion keys, video selector switch.

Although I plan on posting a more length write-up, for now, I’ll give you just the important details:

The LCD screen is from a PSOne. I’m also using on LCD’s board audio amp to drive the speaker.
The LCD is what ultimately drove my power requirements. Almost the entire circuit for the LCD uses 5v except for one IC which needs between 7v and 8v to generate H-Sync.

The keyboard was a bitch to figure out and will be the subject of a post of it’s own. It’s from a Jornada foldaway keyboard made by Micro Innovations. In terms of construction, I had cut away a lot of extra plastic and superglue the two halves together making a single solid keyboard. The keyboard normally interfaces with a HP Jornada via a RS-232 link and special driver. I was able to capture all the output codes and program a 16F88 PIC microcontroller to re-map and output with the appropriate PS/2 protocol. On power up, the PIC checks if there is an extrenal keyboard attached. If so, it ignores data from the onboard keyboard.

If you more in depth details of the RS-232 to PS/2 keyboard hack check on this post.
Some other general construction details can be found here.

I have set up a DTV Hacking Wiki here. Also, here is a forum specifically geared toward answering basic questions about hardware hacking.



This is what I started out with. I got it from Radio Shack on clearance for $17.99.

After all the sawing, sanding and filing, I think I would have been better off just carving it out of a log.


All the major components can be seen here.

This is the backside of the keyboard panel. You can also see the speaker hot-glued into position.

Check out that sweet miniature Atari joystick! It’s fully functional by the way.
What project would be complete without an SD card slot.

The keyboard on the bottom is a normal sized PC keyboard. Initially, I was going to use the one in the middle since it was the smallest PS/2 keyboard I could find, but believe it or not, it wasn’t small enough!
Here is a close up of the to show some of those awesome decals. Note the “C64 inside” logo on the right.

Here’s the view when closed.

Posted in Uncategorized | 3 Comments

Simple e-Passport safeguard: Aluminum Foil

Today, CNN.com is featuring an article about the vulnerabilities of e-Passports. In case you don’t know, beginning in August, new U.S. passports will contain an RFID tag. An RFID tag is a little circuit and antenna that allows data to be read from it wirelessly. The plan is to speed up check-in by automating the process of getting the indentification information from the traveler’s passport. Unfortunately, anyone with an RFID tag reader can read the data without you even knowing it. Great… just what we need, identity theft on a global scale.
A simple and inexpensive way to defend against unwanted access to your e-Passport is to wrap it in aluminum foil. RFID tags are designed to be used at close range, so it doesn’t take much to interfere with them. One layer of aluminum foil will attenuate the radio signal enough to stop any unwanted access of your information. Though, you’ll probably need to remove it from the foil before you hand it over to the customs official.

Posted in Uncategorized | 1 Comment

How To Set Up a Webcam Server Behind a Proxy / Firewall / NAT/ Dymanic IP

My lastest addition to Jason’s Fishcam turned into quite a networking challenge. I needed to stream video from a server behind a proxy server and a firewall. Oh, and the webcam server had a dymanic IP.
My first attempt was to transfer still webcam images via FTP (passive mode, of course) to an outside server. To help speed things up, I saved the incoming images to a RAM Drive configured on the FTP server. Although this method worked it still wasn’t fast enough for my liking (about 1 frame every 2 seconds). My other cams are streaming video and I didn’t want this one to be anything less. My second attempt, using a “tunneling” proxy server, yielded a much better result at over five frames per second. If you’re interesting in setting up something like this for yourself, the following explainantion may help.
In order for this to work, you’re going to need a few things first. So besides your helpless server that is insolated from the rest of the internet, you’re going to need access to another server running on the outside and some tunneling software. In my situation, I already had a server on the outside streaming video from my other webcams. (And when I say server, I mean a crappy little PC running some webcam software… nothing special.) The tunneling application will connect the two servers in a “port forwarding” arrangement. Let me explain…
From behind a firewall, a computer can still transmit data to the outside world. The only catch is that it has to initiate the connection. Unfortunately, that doesn’t work very well when the computer behind the firewall is a server. The whole point of a server is to sit there and wait from connection requests. A server insolated from the internet by a firewall isn’t going to hear any requests. The tunneling proxy server approach overcomes this problem by having a little application (app) that runs on both the server behind the firewall and the server on the outside. The app on the outside server constantly listens for a connection originating from the app on the inside server. Once the two are connected, the server behind the firewall can accept outside requests. In practice, someone one wanting to connected to the inside server will actually type in the host name of the outside server. The request will transmitted from one server to the other via the tunneling app. Generally the entire process is transparent to the end user.
I’m sure there are better application to use for this but I’m going to talk about a little gem called Java Proxy. Go here to read what the developer has to say about it. He has a few diagrams that might make this easier to understand. You can download it there too, but good luck finding the well hidden link. Java Proxy is written in JAVA (big surprise) and you’ll need at least J2SE 1.4 installed to use it. You can use it as is by typing “java -jar jp3.jar” at the command line. Running it this way is great for setting it up, but unfortunately, it leaves a big ugly window in the middle of the screen that can’t be minimized. I’ve taken the liberty of making a custom wrapper that will allow Java Proxy to be run from a standard exe that can be hidden.
Java Proxy is quite a powerful little program and although it can do a lot of cool stuff, I’m only going to explain how to use it in one configuration: forwarding mode. This will allow a specific port on the outside server to pass along requests to the firewalled server.
First set up Java Proxy on the server behind the firewall… From this server, run Java Proxy and choose “Redirector client” from the first screen. Now under “Connection options” type in the location (Hostname or IP) of the outside server and choose a port. For this example lets say we’re going to use port 202. Now click Next and Start. Also, go to the File menu and pick “save config as…” Save the configuration as “settings.xml” (this is important if you want to use the hidden mode version). Now load up your webcam server software. Ok, that’s it for this server now it’s off to set up the outside server.
Load up Java Proxy on the outside server. This time choose “Connector server” and click next. On the next screen, type in the same server port we used on the other server, port 202 in our example. Now click the “Forwarding…” option. In the “Forwarding configuraion” window, check the use forwarding option. Type “localhost” in the remote host field. This basically tells the other Java Proxy that it is on the same machine as the webcam server we want to contact. Set the remote port to the port used by the webcam server software on the inside server. (hopefully something other than 202). For simplicity we’ll set the local port to the same number but it can be different if you want. Click Add and OK. Click Next and Start. Again save the configuration as “settings.xml”.
Now, hopefully within a minute or two, you’ll see the “connected” indicator turn yellow on the window that pops up. If not, check that Windows Firewall (or what firewall software you have) isn’t blocking the Java Proxy port. In our example that would be port 202.
At this point you should be able to see your webcam. To access it, use the address of the outside server with the local port number you used in the “Forwarding configuration” window. Something like… http://www.outsideserver.cat:8080
If you get it working and you’d like Java Proxy to run hidden in the background, then use the jp3_silent.exe from the ZIP package. It’s important to point out that you’ll need to have a “settings.xml” file in the same folder. By placing a shortcut to jp3_silent.exe in the Start Menu, under Startup it will run hidden at startup.
This write-up concentrates on webcam servers but really you could use Java Proxy for almost any kind of TCP/IP connection FTP, HTTP, VNC, etc.

Posted in Uncategorized | 1 Comment

How To Make a Windows XP RAM Disk Drive (for free)

Need to make Windows think part of your memory is a hard drive? Try making a RAMDrive (or RAM Disk some people call it). This will dedicate a section of your computer’s memory to the temporary storage of folders and files. Why would you want to do such a thing? Accessing time for files on a RAM Drive are about 1,000 times quicker than a conventional drive. Also, if you have a situation where you’re access the same files over and over again, a ram disk will help reduce wear and tear on your real hard drive. Of course the down side of all this is that files on a RAM Drive are gone when the computer is shut down (or crashes).
I use a RAM Drive on my “Jason’s Fishcam” system. One of my webcams is behind a proxy/firewall that I don’t control. I order to get images from that camera, I FTP the image files to a server sitting outside the firewall and restream them from there. Since I didn’t want my hard drive continuously writing and overwriting the same file, I save the image file onto the RAM Drive. Not only does this let my save the image over and over again without the hard drive, but it allows me to do it quite a bit faster as well.
There are some software packages out there that will configure a RAM Disk Drive automatically. If you need more bells and whistles, check those out. This method is free and allows a RAM Disk of up to 32MB.

1. Download ramdisk.inf and ramdisk.sys file and save them in the same folder (somewhere convenient).
2. Go to the Control Panel and click Add Hardware
3. Click Next and wait for the search to complete.
4. Choose “Yes, I have already connected the hardware” and click Next
5. Scroll to the very bottom and highlight “Add a new hardware device” and click Next
6. Choose “Install the hardware that I manually select from a list” and click Next
7. Wait for the search to complete and click Next
8. Highlight “Show All Devices” and click Next (warning: this part may take a few minutes)
9. Click Have Disk… (Important! Be sure not to click on anything else or scroll through the lists before you click Have Disk. Doing so will screw up this process.)
10. Click Browse and locate the folder you saved the ramdisk.inf file in, select ramdisk.inf and click Open
11. Click OK, then Next and Next again.
12. Click Continue Anyway if a warning pops up and then Finish
Now for the fun part!
13. Under the Start menu, click Run, type in regedit and click OK
14. Open the following: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Ramdisk\Parameters
To set the size of the Ram Disk Drive, right click on DiskSize and choose Modify. Type in the new size under Value data. The maximum is 3,200,000 (in hexadecimal) which equals 32MB
15. If you need to, modify the DriveLetter enrty too. (the default is “Z”)
16. Now navigate to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Fastfat
change the value of Start from 4 to 1
17. Exit the Registry Editor and Reboot

Posted in Uncategorized | 1 Comment

Controlling a Video Game with Brain Waves

This post describes two projects that involve controlling a video game (Quake II) via electrical signals generated by the body, otherwise known as a “Brian Machine Interface”. The first project is an EOG (electro-oculography) video game controller. In an EOG system, electrical signals generated by eye movements are detected by electrodes placed on the surface of the skin near the eyes. The second project demonstrates game control via EEG (electroencephalogram). With EEG, electrodes are placed on the scalp and neural activity of the brain itself is monitored.

EOG: Video Game Control by Eye Movements

The EOG game control is much easier to implement as compared to EEG. This is partly because of the slightly larger signals generated by EOG. But more importantly, the analysis of EOG signals is straight forward. During eye movements, a voltage potential is generated. By placing electrodes over the muscles responsible for specific eye movements, these movements can be detected and mapped to various inputs of a video game controller.

Here you can see me placing the electrodes on the subject (Il Park). The black cap and chin strap are completely unnecessary in this EOG experiment but we thought it looked cool and decided to use in anyway.

This is a block diagram of the system used to control Quake II. A multi-channel Tucker Davis data acquisition system was used to get the EOG signals and provide a little noise filtering. The buffered and filtered signals were then passed along to a PC running MatLab. This is where a crude pattern matching scheme was used to discriminate between the five different eye movements assigned to game control. When Matlab detected an intended motion, the corresponding command was sent to the running Quake II game. The commands had to be sent via TCP/IP since the game was running on a separate computer.

The results from this project were very good. There was little to no perceivable lag during game play and accuracy averaged 95%. Obviously you wouldn’t want to play the entire game this way. With only five eye movements to choose from (left, right, up, down and blink), control was limited. I was able to shoot and kill some enemies in the game, which you can see in the video. If you are interested in knowing more about how this system works, check out this paper.

This is a video of the system in action. The video shows the output of the Quake II game, the subject’s (which would be me) eye movements and the real time data analysis that is happening on a separate computer. It’s kind of eerie at the end of the video when the camera zooms out and you can see me controlling the game but I’m not moving my hands.

Download video: EOG_game_play.wmv

Download project details: EOG Video Game Control.pdf


EEG: Video Game Control by Thought (Brian Machine Interface)


Unlike EOG signal detection, a brain machine interface using EEG signals isn’t as straight forward. As mentioned earlier, EEG relies on an array of electrodes that contact the scalp. The electrodes are sewn into an elastic cap that is worn on the head (see the pictures) and a conductive gel is squirted around each electrode to get maximum conductivity between the data acquisition equipment and the subject. In contrast to an EOG interface which places an electrode over a specific muscle or nerve, an EEG interface involves a little guesswork to find a control scheme that will work. Not only are the signals captured during EEG fairly noisy, but getting the electrodes in the same place for every experiment is a challenge in itself.

Please excuse me while I vent for a second here…

Every few months various media outlets (CNN, MSNBC, etc) “re-discover” brain machine interfaces (BMI). Every time someone moves a cursor on a computer screen with their mind, the media covers it like the it’s the best thing since sliced bread. I’ve got news for everyone: brain machine interfaces have been around for a long time. Recently CNN had an article about some engineers at Honda who hooked up a robotic hand to an MRI machine. When the subject made a peace sign, the robotic hand made the same motion a few seconds later. Big deal. They could have made the robotic hand play the piano when the subject makes a peace sign, as well… though, that wouldn’t
have created the illusion that their system is actually decoding all the subtle neural signals required to make such a complex hand movement. The CNN reporter not only gave credit to Honda for invented brain machine interfacing (which has probably been around for 20 years now), but said that in the future this technology is going to replace keyboards and buttons on cellphones. Haha! Good one! There are some fundamental reasons this will never happen. If you attempt any kind of BMI experiment, they will become obvious to you. Maybe in a few months they’ll do an article on me playing a video game with my mind.
Back to the EEG video game control…

A common misconception about brain machine interfacing is that you just stick an electrode over the part of the brain that controls a particular movement and ‘viola’ you can detect any time someone makes that movement. If it were only that easy. There are several reasons why this isn’t the case. First, the human brain has billions of neurons versus the limited number electrodes of that can be placed on the subject’s head (see the picture to the left for the electrode placement). Even if there was one neuron that was responsible for a certain hand movement, what are the chances an electrode (that is enormous in comparison) is going to be in exactly the right place to pick up that signal? Second, there is a lot of noise in a system like this. Trying to filter out all the other neural activity is a real challenge. Third, the truth is, we’re not even sure how the brain works yet. Granted, there are some generalities we know about how intended physical movement originates in the premotor cortex and shifts into the motor cortex, but there is a still much to be learned in the area of motor control.

The term “brain waves” refers to the different frequency bands of neural activity in the human brain. These frequency bands can be associated particular mental states. For example, delta waves occur between 0.5 and 4 Hz. Delta waves are seen during deep sleep. The brain wave band used for controlling the video game in the experiment is the mu-band (between 8 and 12 Hz). mu-rhythms occur at the sensorimotor cortex and are associated with movement preparation and motor imagery, but suppressed during any actual motor activity. Meaning you can detect these signals when the subject is relaxed but not while the subject is actually moving a body part or even thinking about moving a body part.


These plots show frequency power spectra during “no imagined movement” and “imagined movement. Notice the mu-rhythms at about 12 Hz.

To control the computer with my mind, mu-rhythms were analyzed in this experiment. Again it is nearly impossible to discriminate signals from different parts of the motor cortex through surface electrodes placed on the scalp. BUT, the left and right hemispheres of the brain can be analyzed separately. This scheme gives two channels for computer control. Basically, the mu-rhythms were measured for each hemisphere of the brain and when a certain threshold was reached that equated to an “on” state. Two hemispheres multiplied by two control states gives four possible outputs for the game control. This was used to make the character in Quake II go left, right, forward (and fire) or stop.

Controlling the computer with your mind requires a little training. Training was done with a visual feedback system that allowed you to see you’re brain waves in real time and try various things to modify them. The strategy that works the best involved small imagined movements. In practice this amounted to sitting in a chair perfectly relaxed and imagining moving a finger and therefore modifying the mu-rhythms for that hemisphere. So when I imagined moving my right finger, the video game character moved right. When I imagined moving my left finger, the computer moved the game to the left. The accuracy for this style of EEG computer control was about 60%. Clearly not as good as EOG.

If you need a more technical description of this system read this paper:

EEG Based Game Control.doc

Posted in Uncategorized | 1 Comment

Essential Tremor Suppression via Viscous Damping

This is a prototype of an essential tremor suppression device. I built it for a biomedical engineering design contest (which I won). Essential tremor is a neurological disease that causes uncontrollable shaking of the hands and arms. A surgical treatment does exist, but it involves implanting an electrode into the thalamus of the brain. Needless to say, not a surgery for everyone. For some, tremor is only temporary and they are not good candidates for the $25,000 operation.
This particular device uses dashpots to dampen out the high frequency tremor motion
(4 to 8 Hz) and allow the slower intended movements. Obviously this isn’t a complete solution since it only addresses tremor at the wrist. Check out the link to the presentation slides for more information.

Posted in Uncategorized | 1 Comment

$7 Air Purifier

I’ve been suffering from some allergy problems lately and while I was at Lowe’s, I took a look at their selection of air purifiers. Much to my surprise, the cheapest one they had was $70. I took the liberty of taking apart the display model while I was there. It seems that there isn’t much magic going on inside these things. It consisted of a squirrel cage fan and an air filter. Since I already had a box fan at home, I decided to walk down to aisle 20 and grab a furnace air filter to make my own. I picked the cheapest filter that could still filter pollen. I’m happy to report that with a little duct tape, I have constructed my very own air purifier at a fraction of the price. After using it for a week, I am amazed at how much dirt and pollen is in the air. It’s that time of year here in Florida. The pollen is absolutely horrid for a few weeks in the spring. I think the forecast is in inches.

Posted in Uncategorized | 1 Comment