Archive for the ‘Electronics’ Category

iobridge to measure the temperature of Comcast DVR

May 16, 2009

Using IOBRIDGE to connect sensors the Internet

Using IOBRIDGE to connect sensors the Internet

This morning I received a wonderful electronic device called iobridge. This device  allows you to easily connect sensors to the Internet. In addition to the basic module I also ordered their temperature sensor. I’m glad I did that since it allowed me to quickly see how easy it is use this system. Click on the thumbnail to see the inside temperature of my entertainment cabinet (or more specifically the area just above the Comcast Motorola DVR unit).

IOBRIDGE is a great product for the electronic hobbyist. I wish the UI would allow embedding the “log”  view in some other page. The system provides a simple API so one could build a simple back-end that will store the historic data and plot it. But they clearly have already done that part, so why not make it available for embedding?

How to debug with Arduino

March 17, 2009

If you need to use the hardware UART of Arduino to control some other module, e.g., the Telit GM862, you may wonder how you can use the hardware UART and use Serial print for your debugging. Well you cannot. Your options are to use Software Serial. But then you should not use software serial for communicating with GM862. There are too many issues, especially if you plan to read from GM862. The default SoftwareSerial is not interrupt based and hence you may lose input. The NewSoftSerial does not support 8MHz systems, so that means you wont be able to use it with Arduino Mini Pro 8MHz. In the past I had used hardware serial for debugging and software serial for communicating with GM862. But given the issues that I just mentioned this was not a satisfactory solution.

Matthew Elias, suggested that I use a second USB TTL for debugging. This is a brilliant solution. It allows me to use hardware UART for communication with GM862 and the out of the box SoftwareSerial for debugging. Here is what you need to do:

  1. You need two USB to TTL adapters
  2. On Arduino, use two digital pins (e.g., pins 10 for RX and 11 for TX for software serial).
  3. Connect the 1st adapter to Arduino and use that to Upload your program to the board. You’ll need to add a switch to the TX line of the USB adapter. The switch must be on when you want to upload a program to Arduino, and you must turn it off when you want to run/debug the program. If you don’t add a switch then the USB voltage will interfere with the device that you’re managing, e.g., GM862.
  4. Connect the 2nd adapter with three wires to the Arduino: (a) connect adapter’s TX pin to Arduino pin 10 (software serial RX) ; (b) connect  adapter’s RX pin to Arduino pin 11 (software serial TX); (c) connect adapter’s GND pin to Arduino’s GND pin.
  5. Open the Terminal application on the Mac (or Hyper-Terminal on PC) and connect to the second USB port (due to the second adapter). 

Now you can use the Terminal application for IO with SoftwareSerial. Here is a simple program to test this setup (note that on the Mac, you need to use 2400 baud rate for the SoftwareSerial and for when you connect to the USB port via Terminal).

#include <SoftwareSerial.h>

int rxPin = 10;
int txPin = 11;

// set up a new serial port
SoftwareSerial debug = SoftwareSerial(rxPin, txPin);

void setup() {
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);



  Serial.println("hardware UART");

void loop() {
  int c;
  char cmd;
   if ((c = != -1) {
     Serial.println("I'm here");
     cmd = char(c);
     if (cmd == 'a') {
     } else if (cmd == 'b') {

From the Terminal you can type ‘a’ and the main loop will print ‘A’ back at the Terminal. All IO from hardware UART will be directed to GM862 (or whatever module that you need to communicate with).

Thank you Matt for providing this solution.

USB Adapter for 3.3V & 5V circuits

February 20, 2009

USB BUB for 3.3V & 5V Circuits

USB BUB for 3.3V & 5V Circuits

I recently purchased a Sanguino kit and a USB Serial Programming Adapter. Both of these are designed for 5V circuits. I wanted to use the USB Serial adapter for a Arduino Mini Pro which requires 3.3V, but was not clear how to do this. I contacted the folks at where I had purchased the Sanguino board from and within a few minutes they provided me with detailed instructions. Here are the instructions in case someone else also wants to use the USB adapter for both 3.3V and 5V circuits.

You need a six pin connector and 5 small pieces of wires.

Use the two horizontal rows above the four vertical rows in the picture (click on the thumbnail). Put your connector into the 6 holes in the top row.

In the row below, starting with the left hand most hole (pin 6) and using the leftmost column of vertical holes (the column next to the labels)

  1. short wire from vertical column Pin 6 (labeled DTR) to horizontal row Pin 6 (red wire)
  2. short wire from vertical column Pin 5 (labeled RX) to horizontal row Pin 5 (orange wire)
  3. short wire from vertical column Pin 4 (labeled TX) to horizontal row Pin 4 (yellow wire)
  4. short wire from vertical column Pin 2 (labeled 3.3v) to horizontal row Pin 3 (blue wire)
  5. short wire from vertical column Pin 6 (labeled GND) to horizontal row Pin 1 (both are square pads) (purple wire)

You will be wiring across other wires, use insulated wires, The wires ought to be long enough to keep them from touching. With such short wires when soldering the insulation often melts. To reduce the chance of melting the insulation,  solder the wires at the back of the board.

I’ve used very short wires (as you can see from the photo), which is not recommended. But I was very careful as I was soldering from the back of the board. After doing this, the adapter works well with both my 3.3V and 5V systems.

Kudos to Brian Riley and Paul Badger for providing such wonderful service at I was very pleased to get the above detailed instructions on how to do this so quickly.

Hall-effect Sensor

December 31, 2008

Hall Effect Sensor Pin Values

Hall-effect Sensor Pin Values

Today I got my first unipolar Hall-effect Sensor and was eager to find out how I could test it. But first there was the issue of how can you determine which pin is the input voltage and which pin the sensor out. The documentation, as with most electronics part documentation, is very terse and assumes that you already know everything. Click on the thumbnail to the left to see the value of the pins.

The Hall-effect Sensor incorporates a magnet. This magnet is on the center of the sensor. The side with no label is north and the side with the label (the branded side)  is south. If you hook up this sensor to a LED (with a pull-up resistor, pick a value that you normally use with your LEDs), when you move the north polarity of a magnet close to the sensor (the side with no label), the LED with light up. If you move the south pole of the magnet close to the side with the label, the LED will also light up.  I connected the sensor to 4 AA batteries (6 volts).

Hall-effect with LED test circuit

Hall-effect with LED test circuit

If you now hook up the sensor output to the red wire and the ground to the black wire of a oscilloscope, and start moving the north pole of a magnet back and forth within the range of this sensor you’ll see a square wave. 

This sensor is not particularly effective for weaker magnetic fields. In my test, a fridge sized magnet had to be millimeters away from this sensor for it to be detected. So depending on your application, you will need to pay careful attention on the Bop and Brp specs of this sensor and the requirements of your own application. Here is the sensitivity of this particular sensor:

Magnetic Properties of this Sensor

Magnetic Properties of this Sensor

Here is a good article on Hall-effect sensors that includes a useful trouble-shooting guide. For my application, I had to give up on this sensor and go with a magnetic sensor with 0.5 Gauss sensitivity, i.e., a magnet that can detect earth’s magnetic field.

Most linear Hall-effect sensors are ratio-metric, where the quiescent output voltage (typically half of the supply voltage) and sensitivity are proportional to the supply voltage. For example, with a supply voltage of 5 volts and no magnetic field present, the sensor’s quiescent output will typically be 2.5 volts and will change at the rate of 5 mv/g (milli-volts per gauss). The output of the sensor will depend on the regularity of the input. If the input magnetic field is defined by a rotating magnetic circle, then you may get a sine-wave type output. If you need a pulse output, then you must convert this sine-wave output to a square wave. Linear sensors act as input for analog-to-digital converters. A comparator cable needs to be added to the circuit to provide a set point or trip point and thereby convert the linear sensor into an adjustable digital switch.

unipolar Hall-effect sensor act as switches require a single polarity magnetic field for operation. When the magnetic flux density increases above the operate point (Bop), the unipolar sensor will switch on (output changing from high to low). When the flux density drops below the release point (Brp) the sensor will switch off (output changes from low to high). Typically, a unipolar sensor require a positive magnetic field (a south pole) directed toward the branded face of the sensor.

An omnipolar sensor will activate with either a north or a south pole.

latching sensor are digital output Hall-effect switches. They switch on (output from high to low) with a positive magnetic field and switch off (output from low to high) with a negative magnetic field. Both magnetic polarity are required for operation.

Circuit Gear, Arduino and Counting Pulses

December 28, 2008


Square Wave Generated by Circuit Gear

Square Wave Generated by Circuit Gear

Arduino has a convenient function called pulseIn that you can use to count the HIGH or the LOW of a pulse. To test this, I created a square wave using the excellent Circuit Gear Waveform Generator.

I uploaded this program and connected the output of the waveform generator to the board (connect the Red wire to the Arduino pin 3, and the black to the Arduino digital ground). The program started printing the count of the HIGH pulses. As I adjusted the frequency of the square ware, the print out was getting faster or slower depending on the frequency of the wave. But as I started changing the amplitude of the square wave, I noticed than when the voltage difference between the LOW and HIGH of the square wave was less than 4 volts, the pulseIn function could no longer read the HIGHs. The documentation for the HIGH confirmed that the difference between the LOW and HIGH must be at least greater than 3 volts. In my case, anything less than 4 volts just didn’t work.

To show a waveform on the Circuit Gear, connect the output of the generator (leftmost connector) to one of the oscilloscope inputs (the two on the right). You’ll need something that can connect to BNC connectors, either alligator clip leads or adaptors or scope probes.

In other words, there is no internal connection between the output of the generator and the input of the oscilloscope, you have to add that.

(If you had another oscilloscope, you could also connect the output of the generator to that oscilloscope and view the waveform.)

Here is the pulse counter program for the Arduino:

int pulsePin = 3;
unsigned long counter = 0;
unsigned long duration = 0;
unsigned long timeout = 1000000; // in microseconds

void setup() {
  pinMode(pulsePin, INPUT);
  // enable the 20K pull-up resistor to steer
  // the input pin to a HIGH reading.
  digitalWrite(pulsePin, HIGH);
  Serial.println("Here we go again");

void loop() {
  duration = pulseIn(pulsePin, HIGH, timeout);
  if (duration == 0) {
    Serial.print("Pulse started before the timeout.");
  } else {
    Serial.print(", ");

How to control GM862 from Arduino

December 20, 2008

Arduino to GM862 pin connection

Arduino to GM862 pin connection

It took some effort to figure out how to connect the GM862 GSM module to a UART (in my case the Arduino USB evaluation board, so I decided to document the steps here.

I also have the GM862 USB Evaluation board, if you plan to use this board and control the GM862 from Arduino, e.g., to programmatically send an SMS message, then you need to be careful how you power the GM862 USB board. If you power it via a battery or external power source (but not USB), then you’re fine. Otherwise, you must remove the jumper that disconnects the TX and RX pins from the GM862 USB FT232. To remove this jumper, you must remove the solder that is on the pins marked TX-I and RX-O. This board is not designed to accept a two pin header and a plastic jumper to allow you to easily switch between USB control and external control. So to get going, don’t use the GM862 USB to power the GM862, whilst it is being externally controlled through your Arduino board.

For a minimum implementation, only the TXD and RXD lines needs to be connected, the other signals of the GM862 modem serial port (DCD/pin 36, DTR/pin 43, DSR/pin 33, RTS/pin 45, CTS/pin 29, and RI/pin 30) can be left open provided a software flow control is implemented (which is what we are trying to do).

You’ll need to disconnect the RX pin 0 on the Arduino board each time you upload your program. If you don’t, upload will fail with the “avrdude: stk500_recv(): programmer is not responding” error message. After you’ve uploaded the program you can reconnect pin 0. Pin 1 can remain connected at all times, so there is no need to disconnect pin 1.

It helps to have a LED attached to the status indicator LED (pin 39 of GM862), but this is optional and not required for you to control the GM862 from Arduino. Pin 39 is an Open Collector output where we can directly connect a LED to show network and call status information (fast blink means net search, not registered or turning off, slow blink means registered full service, always on means a call is active). I connected a LED with a pull-up resistor.

After connecting the Arduino RX pin (pin 0) to GM862 RX-O pin (pin 37), Arduino TX pin (pin 1) to GM862 TX-I pin (pin 20), and Arduino Ground to GM862 Ground, you are ready to take control of GM862 right from Arduino (click on the thumbnail for detailed schematics). To test this set up, send a SMS message. Here is the code to do just that:

#include <SoftwareSerial.h>

int rxPin = 0;
int txPin = 1;

// set up a new serial port
SoftwareSerial serial=SoftwareSerial(rxPin,txPin);

void setup()  {
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

  // set the data rate for the SoftwareSerial port

  // Set SMS to text mode. Note it is critical 
  // to use \r\n to end each line
  // The delays are also critical, without them, 
  // you may lose some of the
  // characters of your message

  // Replace with a valid phone number
  serial.print("Hello from Arduino.");

  // End the SMS with a control-z

void loop() {

Here is a function that takes a char array and use that as the content of the SMS. Not sure if a delay after each print statement is really needed or not.

#define PHONE_NUMBER  "+14081234567\r\n" 
#define PRINTDELAY 500

void sendSms(char msg[]) {
  // End the SMS with a control-z


Serial LCD goes blank when you update the code

October 31, 2008

I just ordered a Serial LCD (a 2 line LCD) from, and connected it to my Ardunio board. The LCD works perfectly fine with one exception. If you update the code whist the LCD is connected, then you may end up with a black screen. I just spend an hour fiddling the board trying to figure out why the LCD all of sudden stopped working, until I figured out that you need to disconnect the LCD (take both the ground and power wires off), upload the new code and then connect the LCD.

Color Coded Resistor Calculator

October 10, 2008

Here is a simple HTML resistor calculator that displays the value of the resistor based on the standard 4 color coded bands.