As you may know, when a new board is announced, I try to find a good project for it. I have to tell you that this goal is keeping me pretty busy. This one I had to finish at the request of the Channel 9 team for PDC – that is a breathalyzer on the new Secret Labs Netduino Mini (http://www.netduino.com/netduinomini). (Note: At this posting, the Netduino Mini is not yet available in distribution but will be in a few days – it can be preordered at:http://forums.netduino.com/index.php?/topic/551-pre-order-your-netduino-mini/.)
The mini is a 24 pin standard DIP configuration. This means that there are not shields that you can plug into it but a number of places that you can plug it into. For example, any breadboard (as we will see) and any device that currently takes a Parallax Basic Stamp. I like this package for that flexibility and I like is because it is just so tiny (34 mm x 17 mm). Don’t let this bare bones package deceive you though. You have SPI, I2C, 4 ADCs, 4 PWMs, serial UART, and 16 GPIOs. Compare that with anything else this size and then add Visual Studio and C# productivity!!
This is not a design for a breathalyzer that is going to let you know if you are just under the legal limits in your state and safe to drive – calibration is really hard for these devices. You need to be able to control the exact alcohol exposure to know how to calibrate and then it varies with temperature and humidity. But for the purposes of a fun project and to give to my daughter whose friends are just starting to drive, it is sufficient. The breathalyzer end result looks like the picture below and works as shown in the video
With this form factor (ie no USB connector), how do you connect to Visual Studio and how do you power the device? First, you need to connect to the serial port instead of the USB Port. To do this on the breadboard, you need to hack a serial cable. You can see the serial pin numbering below.
What you need are:
Serial pin #2 to connect to Mini pin #1 - TX (Debug/Com2)
Serial pin #3 to connect of Mini pin #2 - RX RX (Debug/Com2)
Serial pin #5 to connect to Mini pin #4 - GND
You can see these in the picture below. Then I have a regulated 5V power source running on 2 AA batteries (Bodhilabs VPack 5.0V). I put a simple toggle switch to turn the power on and off. This is connected to the side rails of the breadboard and jumpered into Mini pin #21 (regulated 5V input) and Mini pin #23 (GND). Finally, I put in an LED to let me know when the power is on (so that I don't waste batteries). That is all you need to set up the Mini to be run and ready to be programmed. In fact, it is a good time to ping the device using MFDeploy to make sure that it responds with ‘TinyCLR’ to double check your connections. Now you can treat the serial port in VS just like you did the USB port in other devices. Remember to set the NETMF tab accordingly.
The sensor is an MQ-3 that I bought at Pololu.com because I liked their carrier board. It takes the six pins of the sensor and reduces that to three that fit into a right angle header. This sensor costs less than $5.00. I used a 100K variable resistor for calibration. The sensor outputs 0-5V which is too much for the Mini to handle so I added a voltage divider to step it down by a third to 3.3V. The analog input port theoretically returns a value between 0 and 1024 but the actual baseline measurement is dependant on a number of variables (calibration setting, temperature, and humidity). So, I let the device stabilize before starting the measures (see The Code below).
As you can see, there is one clear LED and three each green, yellow, and red LEDs that I can light up to reflect the reading we get from the MQ-3. I put three values of resistors in each color group (870, 390, and 100 Ohms) so the the first LED of each color is dimmer than the last. These are not the optimal values to use. I calculated them with the 5V power source in my head but these are driven off of GPIOs from the Mini which are 3.3V so that whole thing is a little dimmer than it might be. After I built this project, I ran across something that you might want to use instead. This is the Elabguy LED-Rainbow. In this LED array, the LEDs are not driven by the processor but by the 5V power supply and there is a simple transistor switch that the processor interfaces with. The resistors are internal to the array as well – much easier for the next project.
It is telling that I spend so much more time talking about the hardware than the software. I found for my setup that adjusting the baseline (using the variable resistor) so that it is around 200 gives me a full range of values. I blink the clear LED for 15 seconds to let the sensor heat up and stabilize. Then I take a current baseline measurement and calculate the steps for each LED. The rest is really simple.
public class Program
public static void Main()
Cpu.Pin pinMap = new Cpu.Pin
OutputPort leds = new OutputPort;
AnalogInput br = new AnalogInput((Cpu.Pin)GPIO_PIN_5);
int baseline = 0;
for (int idx = 0; idx < leds.Length; ++idx)
leds[idx] = new OutputPort((Cpu.Pin)pinMap[idx], false);
// let the unit adjust
for (int i = 0; i < 30; i++)
value = br.Read();
// set baseline and steps
baseline = br.Read() + 20 ;
step = (1024 - baseline) / 8;
value = br.Read();
if (value > 0)
if (value > baseline)
if (value > (baseline + step))
if (value > (baseline + (2*step)))
if (value > (baseline + (3*step)))
if (value > (baseline + (4*step)))
if (value > (baseline + (5*step)))
if (value > (baseline + (6*step)))
if (value > (baseline + (7*step)))
if (value > (baseline + (8*step)))
This project is not going to get you a breathalyzer that will stand up in court but it will give you a way to verify that someone has been drinking and whether a lot or a little. This was done as a demo for PDC. There was also a Tweeting Breathalyzer demo done on the Netduino Plus which you can see at:
This form factor may not be for everyone – it does not come with all the current Arduino shield options that the original Netduino can draw on. Maybe it just takes me back to my old bread boarding and wire wrapping days but I like this little guy. Maybe it’s just that I like to see people’s reaction when I hold up this tiny thing and say - ‘This has .NET running on it!’.