Thursday, December 27, 2012

Arduino & Android Integration

I'm working on a project for a friend of mine, which requires a Arduino to be connected to an Android device. The Android is the display and control interface for the Arduino, displaying data from the Arduino, pin status, and sending control messages to turn items on and off, dim with PWM, etc.

2 items we recommend are the Arduino MEGA ADK R3 for Android and Beginning Android ADK with Arduino. Add a Android phone or tablet, and you are on your way to creating some very cool apps, limited only by your imagination.

I just finished reading this book, and I highly recommend it. It makes it easy to create apps and communication between the Arduino and the Android!

Monday, December 24, 2012

Breadboard and Protoboard Combo Pack

A prototyper's dream combination, I can't recommend this inexpensive ($7) package enough. After working out the bugs in your design on the solderless breadboard, transfer it to the permanent PCB for posterity. Perfect for embedded DIY Arduino designs where shield compatibility is not a concern.

Breadboard 400

Standard solderless breadboard with 2 power strips and 400 contact points.

ProtoBoard 400

High quality,double-sided prototype board designed for quick and quality prototyping. These are production quality boards with solder mask and silk screen. The board has 464 plated through holes. The board is laid out to match a 400-point breadboard with the same row and column markings. This allows you to build a circuit on a breadboard then transfer the design to the protoboard exactly as it is on the breadboard. An additional double column of holes runs through the middle of the board for additional power connections.

These boards are durable and easy to work with. You won't have to worry about pads coming loose with this board!

Wednesday, December 12, 2012

Arduino PID Control

PID you say. What's that?

According to Wikipedia: A proportional–integral–derivative controller (PID controller) is a generic control loop feedback mechanism (controller) widely used in industrial control systems – a PID is the most commonly used feedback controller. A PID controller calculates an "error" value as the difference between a measured process variable and a desired setpoint. The controller attempts to minimize the error by adjusting the process control inputs.

Here's the issue: Let's say you want to heat a tank of water to 150 degrees. you check the temp sensor, and it says 100 degrees, so you turn on the heat full bore. You check again, and it says 160 degrees, so you turn off the heat. But now the water has cooled to 140. Now with a micro-controller like the Arduino, keeping a 10 degree spread (+/- 5 degrees) isn't too hard, but for finer and more intelligent control, it's time for PID! 

The Arduino Playground puts it this way: So, you tell the PID what to measure (the "Input",) Where you want that measurement to be (the "Setpoint",) and the variable to adjust that can make that happen (the "Output".) The PID then adjusts the output trying to make the input equal the setpoint.

There is an awesome library for the Arduino that makes this process almost easy.


PID Controllers: Theory, Design, and Tuning

Saturday, December 1, 2012

Arduino & Model Railroading: Io:duino


The Io:duino is designed for DIY model railroading, combining the power of NMRAnet and open-source tools. Fully Arduino-compatible, Io:duino makes it easy to design your own digital controls, for layout automation, lighting effects, even controlling your trains via DC or DCC.*
Even better, Io:duino’s built-in Controller Area Network (CAN) support makes it a great tool for hacking your automobile, or for home automation.**
Io:duino is built around the Atmel AT90CAN128 processor, whose 128KB of program space, 4KB of SRAM, and 4KB of EEPROM are just the icing on the cake. This processor has built-in hardware support for the CAN and NMRAnet networking protocols, without sacrificing any of the digital I/O pins.
Arduino compatibility means you have immediate access to hundreds of add-ons called shields, empowering you start building without any additional tools. And it’s easy to write and upload your own custom software over USB.
Like all Railstars products, Io:duino includes a No-Questions-Asked 3-Year Warranty!
Retail Price $90. Available from an Railstars Authorized Dealer or the Railstars Web Store.
*Requires additional hardware, such as a digital power station like RAILbooster, or a motor shield like Ardumotor, not included.
**Requires cable adapter and additional software libraries, not included.

Further Reading:

The DCC Guide: How to Select and Use Your Command Control System

Saturday, November 24, 2012

More Ethernet - Read Analog, & Set Digital Pins

As a followup to our previous Ethernet web server example, I offer a enhanced version. Again, it displays what is coming in on the analog pins, but also allows you to control digital pins 0-7.

Get the CODE HERE!

You'll need:
Arduino UNO
Ethernet Shield

Plug shield into your home router with an ethernet cable. Change IP information to match your network, and MAC address to match your shield.

The html isn't pretty, but it's functional! I'm sure some of you can pretty it up, and even show the current status of the digital pins, like the status of the analog pins are displayed. Thanks to the What I did Was blog for inspiration!

Friday, November 23, 2012

Using a Keypad for Input

Keypads are handy for a variety of projects, from security access to telephone dialing. In this tutorial, we use a Adafruit membrane keypad, and output the button presses to the serial monitor. Nothing fancy, just a platform for future development. Expand the Library in your sketchbook/libraries/ folder. The next step will be to multiplex the lines so we don't use up 7 inputs with a SN74LS151 (reduces Arduino pins to 3, expands inputs up to 16).

You'll need:
Arduino Uno
Breadboard Kit
Membrane Keypad

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){

EtherShield SD Card Access

Since I was playing with my EtherShield SD, I figured I'd load up the example sketch "CardInfo" in the SD folder. I popped in the microSD card from my digital camera, and it started listing the files on my card (but did not recognize the full 16GB partition).

Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3038248960
Volume size (Kbytes): 2967040
Volume size (Mbytes): 2897

Files found on the card (name, date and size in bytes):
DCIM/         2011-06-20 14:58:52
  100_PANA/     2011-06-20 19:07:48
    P1000812.JPG  2011-09-08 09:19:54 4158647
    P1000781.JPG  2011-08-20 21:02:02 4309863
    P1000813.JPG  2011-09-08 09:20:00 4258311
    P1000814.JPG  2011-09-08 09:20:06 4145655
    P1000954.JPG  2011-10-05 19:11:52 3605223

  SD card test
 This example shows how use the utility libraries on which the'
 SD library is based in order to get info about your SD card.
 Very useful for testing a card when you're not sure whether its working or not.
 The circuit:
  * SD card attached to SPI bus as follows:
 ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** CS - depends on your SD card shield or module.
  Pin 4 used here for consistency with other Arduino examples

 created  28 Mar 2011
 by Limor Fried
 modified 9 Apr 2012
 by Tom Igoe
 // include the SD library:
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;  

void setup()
 // Open serial communications and wait for port to open:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  Serial.print("\nInitializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);     // change this to 53 on a mega

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
  } else {
   Serial.println("Wiring is correct and a card is present.");

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
    case SD_CARD_TYPE_SD2:

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  // list all files in the card with date and size | LS_DATE | LS_SIZE);

void loop(void) {

Simple Ethernet

This is the first in a series of Ethernet projects. This first project will display the values coming from the analog ports in a web browser on a remote machine. Additional posts will cover controlling the Arduino from a web browser, and reading and writing to the SD card for logging purposes. Stay tuned!

I popped a Arduino EtherShield SD on to an older Duemilanove (328), and loaded the following sketch. I changed the MAC address to the one printed on the bottom of my EtherShield, and put in a applicable IP address from my network. When I pointed my browser to the new IP address, I got the following output:

analog input 0 is 1023
analog input 1 is 0
analog input 2 is 1023
analog input 3 is 771
analog input 4 is 551
analog input 5 is 437

This makes sense, because I have A0 and A2 connected to 5v, A1 connected to Gnd, and A3-A5 are left floating, and the values change every second or so.

Sketch from examples folder (Ethernet, Web Server)

  Web Server

 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield.

 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe


#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x00, 0x23, 0x36 };
IPAddress ip(192,168,254, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
 // Open serial communications and wait for port to open:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  Serial.print("server is at ");

void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c =;
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connnection: close");
                    // add a meta refresh tag, so the browser pulls again every 5 seconds:
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(" is ");
");          break;
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data
    // close the connection:
    Serial.println("client disonnected");

Thursday, November 22, 2012

Producing DTMF Tones

I wanted to teach my Arduino to talk telephone, so I added a HT9000A DTMF chip to produce the familiar "touch tones" (upcoming projects will act upon "heard" DTMF tones, but with a different chip).

The output is really low volume, so you may want to plug in amplified speakers or use an input on your stereo. You could build an amplifier circuit with a LM386 as well.

I used an Ham Radio program that listens for touch tones and displays the number it hears to verify operation.

The code I used (and modified) was built by Brohogan.(don't forget the include file)

/* HT9200A DTMF Generator Test                             BroHogan 7/17/09
 * SETUP FOR SERIAL MODE - Requires 3 pins - Data and Clock (100KHz) and CE
 * Wire per data sheet - 3.57MHz xtal (4.0MHz won't dial) S/P to GND = serial
 * modified by Steve Spence -

#include <HT9200.h>                     // defines for HT9200 DTMF chip
#define DATA_PIN   2                    // Data (serial)
#define CLOCK_PIN  3                    // Clock (serial)
#define CE_PIN     4                    // Chip Enable pin (must control)

#define PHONE_NMBR "2642262"         // phone # to dial
char PhoneNum[] = PHONE_NMBR;           // load phone # for dialer

void setup() {
  pinMode(DATA_PIN, OUTPUT);
  pinMode(CE_PIN, OUTPUT);
  Init_HT9200();                        // init the chip

void loop() {
  Dialer();                             // dials phone

void Init_HT9200 (){
  digitalWrite(CE_PIN, HIGH);           // start with chip disabled (else you go nuts)
  digitalWrite(CLOCK_PIN, HIGH);        // start with clock pin high
  digitalWrite(CE_PIN, LOW);            // now enable the chip
  delay(10);                            // delay 10ms to ramp up the ocillator
  DTMF_Out (DTMF_OFF,1,0);              // turn off any tone from previous run

void DTMF_Out (byte digit, long duration, long pause){  // FOR SERIAL COMM
  if (digit == 0) digit = 10;           // take care of 0 here
  for (byte i=0; i<5 br="br" i="i">    digitalWrite(CLOCK_PIN, HIGH);      // clock high while setting data
    digitalWrite(DATA_PIN, bitRead(digit,i)); // set data LSB->MSB
    delayMicroseconds(5);               // 1/2 of 100K Clock speed
    digitalWrite(CLOCK_PIN, LOW);       // clock low to latch data
    delayMicroseconds(5);               // 1/2 of 100K Clock speed
  delay(duration);                      // how long tone will play
  if (pause != 0){                      // tone sounds continuously if zero
    for (byte i=0; i<5 above="above" as="as" br="br" i="i" nbsp="nbsp" same="same">      digitalWrite(CLOCK_PIN, HIGH);
      digitalWrite(DATA_PIN, bitRead(DTMF_OFF,i));
      digitalWrite(CLOCK_PIN, LOW);
    delay(pause);                       // how long pause between tones

void Dialer(){  // dials tones from number
  for (byte i=0; i<7 i="i" nbsp="nbsp" p="p"> //i<7 11="11" 7="7" br="br" digit="digit" for="for" i="i" number="number">    DTMF_Out(PhoneNum[i]-'0',500,100);  // 1/2 sec tone with 1/10 pause

Tuesday, November 20, 2012

Using pull up / pull down resistors

Pull up and pull down resistors are used to eliminate floating inputs. Normally a input is either connected to a high (on), or a low (off). But if the input is not connected to anything, it's "floating" and can read either, or cycle back and forth due to stray currents, so it's not a reliable state. A resistor is used to pull an input to the opposite of what you are trying to read (ground if you are trying to read a high, +5V if you are trying to read a low). This resistor prevents a short circuit (you can't connect +5v to gnd), and makes sure the input is in a stable state when not connected, but is ignored when your input is connected to a high or a low.

Monday, November 19, 2012

Transistor and Resistor Sizing

When using a transistor to turn on a device, it's important to chose the right transistor, and to trigger it properly. NPN transistors get triggered with a high, PNP transistors get triggered with a low, and get connected differently in a circuit. You need to know how to size the base resistor properly, to make sure you drive the transistor hard enough, but not draw too much power from the Arduino. The typical hookup in the Arduino world is that a Arduino digital pin is driving the base of the transistor, through the resistor he talks about in the video, and that the voltage is typically (but not always) 5v. This video will make it very clear:

We are reading:

Electrical Engineering 101: Everything You Should Have Learned in School...but Probably Didn't (w/ CD)

Sunday, November 11, 2012

4 Pin DIN Security Camera

I needed to know the pin designations on a small home security camera that was given to me. This post actually has little to do with the Arduino directly. I'm building a Arduino based security system, and this camera was given to me, so I decided to include it.

It has no name, only the model number (080800-24t) and uses the OV5116 camera chipset. I searched the net, but could not find an full explanation. I did find pieces of info from several sources, so I thought I'd put it all together in one place in case someone else was also looking.

It turns out it's from a "Homeland Security” brand camera and monitor set that was being sold at Walmart around 2001. It has a small 4 pin DIN type plug, and the wires are red/white/yellow/black. The camera has 6 IR (night vision) LEDs and a mic...

1. White (Audio)
2. Yellow (Video)
3. Black (Common Ground)
4. Red (+12vdc)

It's a Black and White Model. Reportedly the "Night Vision" portion barely works on these and the picture isn't very clear even during the day...  

Sunday, November 4, 2012

Arduino Simulators

Want to get started playing with Arduino's, but don't have the hardware? Download a free (or nearly free) simulator from This is a good way to get a feel for the platform, it's abilities, and the code, before making investments in hardware and accessories.

Other Arduino Simulators include:

Saturday, November 3, 2012

Arduino IR Receiver - Part 2

I have been successful in programming my Arduino to identify sets of digits transmitted from my Samsung remote. I used the excellent library at as a starting point. I stripped out everything that wasn't a raw number, and started logging what numbers came across the serial monitor as I pressed buttons.

I then created a Switch/Case statement that turns on (and off) particular LED's when the appropriate button on the remote is pressed.

Not sure what sensor was in my VCR, but a TSOP4838 should work as well.

This can now be easily used to control motors, lights and other equipment (optically isolated SSR). I've uploaded a video to youtube showing how it all works.

Code and schematics are available at

As always comments here and detailed discussion at is encouraged.

We are reading:
Arduino Robotics, by John-David Warren, Josh Adams, & Harald Molle

 * IRremote: IRrecvDump - dump details of IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
 * Heavily modified by Steve Spence,

#include <IRremote.h>

int RECV_PIN = 19;

int reversePin = 4;                 // LED connected to digital pin 13
int forwardPin = 5;                 // LED connected to digital pin 13
int playPin = 6;                 // LED connected to digital pin 13
int pausePin = 7;                 // LED connected to digital pin 13

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
  irrecv.enableIRIn(); // Start the receiver
  pinMode(reversePin, OUTPUT);      // sets the digital pin as output
  pinMode(forwardPin, OUTPUT);      // sets the digital pin as output
  pinMode(playPin, OUTPUT);      // sets the digital pin as output
  pinMode(pausePin, OUTPUT);      // sets the digital pin as output

void loop() {
  if (irrecv.decode(&results)) {
    long int decCode = results.value;
    switch (results.value) {
      case 1431986946:
        digitalWrite(forwardPin, HIGH);   // sets the LED on
      case -11780576:
        digitalWrite(reversePin, HIGH);   // sets the LED on
      case -873913272:
        digitalWrite(playPin, HIGH);   // sets the LED on
      case -1025287420:
        digitalWrite(pausePin, HIGH);   // sets the LED on
      case 1791365666:
        digitalWrite(forwardPin, LOW);   // sets the LED off
        digitalWrite(reversePin, LOW);   // sets the LED off
        digitalWrite(playPin, LOW);   // sets the LED off
        digitalWrite(pausePin, LOW);   // sets the LED off
        Serial.println("Waiting ...");

    irrecv.resume(); // Receive the next value

Wednesday, October 31, 2012

Arduino IR Receiver

I recycled a InfraRed receiver module from an old VCR tonight. I connected it to my Arduino 2560, and I'm displaying raw data in the serial monitor whenever I press a key on the remote. I'm attempting to do something useful with this data, like turn lights on and off, or adjust my thermostat. Will post more as the project develops.

int IRsignal[] = {
// ON, OFF (in 10's of microseconds)
    34, 1896,
    444, 440,
    52, 164,
    56, 164,
    54, 164,
    54, 54,
    56, 54,
    56, 54,
    54, 56,
    54, 54,
    56, 166,
    52, 164,
    54, 164,
    56, 54,
    54, 56,
    54, 58,
    52, 54,
    56, 56,
    52, 58,
    52, 58,
    52, 164,
    54, 54,
    56, 54,
    56, 56,
    52, 54,
    56, 54,
    56, 166,
    52, 164,
    54, 56,
    54, 164,
    54, 164,
    56, 162,
    56, 164,
    54, 164,
    54, 4526,
    442, 434,
    56, 164,
    54, 164,
    54, 164,
    56, 54,
    54, 56,
    54, 54,
    56, 54,
    56, 54,
    54, 164,
    54, 164,
    56, 164,
    54, 54,
    56, 54,
    56, 54,
    54, 56,
    54, 58,
    52, 54,
    54, 56,
    52, 166,
    54, 60,
    50, 54,
    56, 56,
    54, 56,
    54, 56,
    52, 166,
    52, 164,
    56, 54,
    54, 166,
    54, 162,
    56, 164,
    54, 164,
    54, 164,
    56, 4524,
    444, 434,
    54, 162,
    56, 162,
    58, 162,
    56, 52,
    58, 52,
    58, 54,
    54, 56,
    54, 54,
    56, 164,
    54, 164,
    54, 162,
    56, 164,
    54, 162,
    56, 0};

Sunday, October 28, 2012

Morse "Paddle" Keyer

Building on our previous "simple" piezo beep sketch, I now introduce a Morse "Paddle" Keyer. It contains two buttons, one timed for a 60ms dot, the other for a 180ms dash. It uses the tone() command to activate the Piezo, which is a pwm output.


This example shows a morse "paddle" keyer.
One button is timed for a dot, the other
for a dash (3 * dot). I'm using a 60ms
duration for a dot, so a dash = 180ms.


int outPin = 9;
unsigned int frequency = 700;
unsigned long dotDuration = 60;
unsigned long dashDuration = dotDuration * 3;
int dotPin = 7;   // pushbutton connected to digital pin 7
int dashPin = 8;   // pushbutton connected to digital pin 8

void setup()  {
pinMode(dotPin, INPUT);      // sets the digital pin 7 as input
pinMode(dashPin, INPUT);      // sets the digital pin 8 as input

void loop()  {
  int dotVal=LOW;
  int dashVal=LOW;

  dotVal = digitalRead(dotPin);
  dashVal = digitalRead(dashPin);
  if (dotVal==HIGH)
  tone(outPin, frequency, dotDuration);
  if (dashVal==HIGH)
  tone(outPin, frequency, dashDuration);

What we are reading this week:

Fun with Piezo's

I've created a simple beeping alarm with a Piezo transducer. Connect the Piezo + to pin 9, and the Piezo - to Gnd. Run the following sketch. Next version will be using the tone() command to build a Morse Code trainer.

 This example shows how to run a Piezo Buzzer on pin 9
 using the analogWrite() function.
 It beeps 3 times fast at startup, waits a second then beeps continuously
 at a slower pace

void setup()  { 
  // declare pin 9 to be an output:
  pinMode(9, OUTPUT);

void loop()  { 

void beep(unsigned char delayms){
  analogWrite(9, 20);      // Almost any value can be used except 0 and 255
                           // experiment to get the best tone
  delay(delayms);          // wait for a delayms ms
  analogWrite(9, 0);       // 0 turns it off
  delay(delayms);          // wait for a delayms ms   

Sunday, October 21, 2012

New 32-bit, 84MHz Arduino Due

Hot off the presses, this is a big jump in speed and power for the Arduino community. No longer an 8bit Atmel at heart, there is a powerful ATSAM3X8E processor beating at the core of this Arduino. Compatible with 3.3v shields, and still programmed with the Arduino IDE, the user experience is the same as with the lessor models of the Arduino. A new addition to the Arduino feature set is a digital-to-analog converter. Not just one, but two! For more info on what this new board brings to the hacker community, see

Sunday, October 14, 2012

Stepper Motor Controller - Part 2

Continuing our saga from Part 1, We finished soldering up the controller shield with all the components. We have downloaded the library, and have connected the stepper motor. The motor has 4 wires, which we have attached to the M1/M2 connector. The wires connect top to bottom:

1. Orange
2. Yellow
3. N/C
4. Green
5. Brown

A 12v power supply connects to the motor external power connector. Make sure you do not enable the Arduino power jumper just to the right of the motor external power connector.

Video can be seen at

Discuss this project at


#include <AFMotor.h>

AF_Stepper motor(48, 1);

void setup() {

  motor.setSpeed(10);  // 10 rpm   

  motor.step(100, FORWARD, SINGLE); 

void loop() {
  motor.step(100, FORWARD, SINGLE); 
  motor.step(100, BACKWARD, SINGLE); 

  motor.step(100, FORWARD, DOUBLE); 
  motor.step(100, BACKWARD, DOUBLE);

  motor.step(100, FORWARD, INTERLEAVE); 
  motor.step(100, BACKWARD, INTERLEAVE); 

  motor.step(100, FORWARD, MICROSTEP); 
  motor.step(100, BACKWARD, MICROSTEP); 
Learn more by reading: 
Arduino Internals, by Dale Wheat 


Stepper Motor Controller

You don't need a fancy shield to control motors, but sometimes they are handy. This unit works with steppers, servos, and even regular dc motors.

This is stage one in our Stepper Motor Controller project. We are assembling the Motor Shield that Hacktronics sent us, then we will write the sketch to control it. This project would make a good starting point for a robot or even a cnc machine. Stay in touch for additional steps in the project.

Discuss this project at

What are we reading this week? 

Practical Arduino Engineering, by Harold Timmis.

Wednesday, August 29, 2012

Light Sensors

A Light Sensor generates an output signal indicating the intensity of light by measuring the radiant energy that exists in a very narrow range of frequencies basically called "light", and which ranges in frequency from "Infrared" to "Visible" up to "Ultraviolet" light spectrum. The light sensor is a device that converts this "light energy" whether visible or in the infrared parts of the spectrum into an electrical signal output. Light sensors are more commonly known as "Photoelectric Devices" or "Photo Sensors" because they convert light energy (photons) into electricity (electrons).
Photoelectric devices can be grouped into two main categories, those which generate electricity when illuminated, such as Photo-voltaics or Photo-emissives etc, and those which change their electrical properties in some way such as Photo-resistors or Photo-conductors. This leads to the following classification of devices.


Saturday, August 25, 2012

The Arduino Wifi Shield is finally here!

Finally, a TCP/IP WIFI "co-processor". Takes all the load off the arduino, and can run independently.


We’ve been working for a while on this new wifi shield for Arduino that is quite different from what you can find already on the market.

Instead of just getting the usual pre-made module we decided to build a product that would encourage hacking and modifications so we decided to use an AVR32 processor running an open source version of TCP/IP and the WIFI software stack. The Arduino communicates over SPI with the AVR32 and this in turn controls the WIFI module, an HDG104 from H&D Wireless. Following the Arduino tradition the full software stack running on the AVR32 is released as open source as well as the Arduino library that controls the shield.

Having the full source for the software stack allows adding more complex protocols directly on the AVR32 without using the limited code space of the atmega328 on the Arduino. On top of this, skilled C developers can re-program the shield to operate as a standalone device without the need of an Arduino connected to it.  Since we expect that there will be amazing new features created by the community we made updating its firmware very easy, just connect a usb cable to the shield. We believe this opens up to a lot of hacking potential.

Thursday, August 23, 2012

Sensors & Detectors

Detectors in science

In order to study anything in science, you must first be able to detect it. The most interesting things, of course, are those that we can detect with our own senses. We then use devices to amplify what we can sense, in order to study those energy forms more thoroughly.
We also use detectors to study energy forms that we are not able to sense, such as magnetic fields. Detectors and sensors make up the starting point for most scientific studies.

Man-made detectors

Scientists have invented various types of sensors to detect energy forms. For example, a smoke detector in you home will set off an alarm when the energy from smoke or heat reaches its detection device. The microphone on you tape recorder detects the energy from sound waves and creates an electric signal that records the sound.
  • Solar cells and photographic film detect light.
  • Microphones detect sound.
  • Thermometers sense the change in heat or temperature.
  • Pressure gauges detect touch.
  • Scales detect and measure the effect of gravity.
  • There are many devices that detect various chemicals and even odors.
  • A magnetometer detects magnetic fields.
  • An electric meter detects electricity.
  • A Geiger counter detects atomic radiation.

Changing signals

The signals received by a detector may often be manipulated to gather desired information. Often the signal received is weak, so it must be amplified. Sometimes the signal is too strong, so it must be filtered. Extraneous signals and noise also must sometimes be filtered out, so that only the desired signal comes through.


Besides detecting energy forms, many devices amplify or enlarge the signal. Some are mechanical, but most amplifiers are now electronic. Examples of amplifiers include:
  • A telescope makes distant objects appear closer.
  • Electronic amplifiers can increase the level of sound
  • Very faint chemical signals (odors or tastes) can be amplified electronically to give their details.


If you would try to study the Sun, the light would be too bright to view or photograph. A filter could be used to lower the light level. It could also filter out all colors except those that you want to measure.
Sometimes electrical signals on the radio or television include static and other forms of noise. Electronic filters eliminate the noise and allow you to get a good, clear signal.

More at

Tuesday, August 21, 2012

Digispark, the tiny "Arduino"


We set out to build a little brother to the wonderful Arduino line of development boards - we were tired of leaving our valuable Arduino's behind in projects, or worse, ripping apart old projects to build new ones! We also felt the Arduino was too big and powerful for many projects where we only needed a few pins, or an SPI or I2C bus. And so the Digispark was born! To us, the best things about the Arduino is the community, the easy of use, and the IDE - by making the Digispark an Arduino compatible development board all of those remain common. Plug it in, power your project with USB or external sources, program it with the Arduino IDE, and easily use existing Arduino code! But with its small size and low cost you can feel free to leave it in your project, give one to a friend, and use them everywhere!

Sunday, August 12, 2012

The Marriage between the Arduino and the Android

Normally smartphone events are tightly coupled to your phone device itself. When your cell phone is ringing, your phone speaker plays a ringtone. When you get a new text message, your phone displays it on its screen. Wouldn't it be thrilling to make those phone events visible somewhere else, on your wearable, in your living room, on your robot, in your office or where ever you want it to occur? Or would you like to use your smartphone sensors, like the accelerometer, light sensor, compass or your touchscreen to control other devices? Amarino is a toolkit, basically consisting of an Android application and an Arduino library which will help you to interface with your phone in a new dimension. You can build your own interfaces almost without any programming experience.

The Arduino ADK is a microcontroller board based on the ATmega2560 (datasheet). It has a USB host interface to connect with Android based phones, based on the MAX3421e IC. It has 54 digital input/output pins (of which 14 can be used as PWM outputs), 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button.

Saturday, July 21, 2012

Wearing your Arduino

One of the more interesting aspects of Arduino's is taking them with you. Now I don't mean putting a bunch of parts in a small box and sticking it in your pocket, but actually integrating the circuits, conductive thread, and I/O into a garment, using buttons, zippers, LED's, and even solar cells and rechargeable batteries for power. Light yourself up, make sound, build a gps bracelet, and much more. Only your imagination is the limit. There are special sewable, wearable arduino boards (Lilypad & Flora), or you can make your own. A fantastic reference that will start you down this path is Arduino Wearables, a hefty tome (300+ pages and I couldn't put it down once I started reading it) that describes the ins and outs of integrating intelligence into clothing, and spends as much time on sewing topics (make a electronic beatbox hoodie) as it does coding and circuits. I'll be interviewing Tony Olsson, and posting the interview shortly.

Sunday, July 1, 2012

Building the Heating / Air Conditioning Thermostat - Part 3

We continue with the project by building the temperature sensor module. We are using our favorite, the Dallas DS18B20 digital sensor. It uses one pin to communicate with the Arduino, along with +5vdc and Gnd. We add a 4.7k resistor between pins 2 & 3. Because we are using a single sensor, we do not need to know the address of the DS18B20 ahead of time. If you want to add a second sensor, to display outdoor temperature see our other tutorial. We are using the DS18B20 code from and the LCD code from

Don't forget the updated One Wire and Dallas Libraries from

Pin 1 on the left is Gnd, Pin 2 in the middle is +5vdc, and pin 3 on the right is data, according to the GVS standard we follow.

Building the Heating / Air Conditioning Thermostat - Part 2

After looking at the documentation on our White Rogers thermostat, it looks like we can simplify the operation as such:

Now this would be fine, if we were just interested in manual control, but we actually want this to be automatic, like the original, based on temperature, so we need to give the Arduino the ability to "switch" these circuits, which are nothing more than 24vac relay coils in the furnace and air conditioner. I'm not sure what the current is that those coils pull, but I believe that these SSR's will handle it.

The next step is the DS18B20 Temperature chip, as described previously in this blog, and at

Saturday, June 30, 2012

Building the Heating / Air Conditioning Thermostat

Our existing thermostat is a White Rogers that currently controls our Air Conditioner and Electric Furnace. We will be replacing this with our Arduino and LCD display. Attached are the photo's, schematic, and documentation of the existing control. We will post the code and schematics of the new system as it develops. More details on how Thermostats work and are wired can be found at

Monday, June 25, 2012

LCD / Keypad Shield

We are building a thermostat to control our furnace and A/C. We are using a DFRobot LCD / Keypad shield we received from to display the temperature, and to set the temperature ranges for both the heating and cooling modes. The following is a sketch that shows how the lcd and the buttons are utilized. Only one analog input is needed for the 6 buttons, as they are connected to resistors, and the resistance is measured to determine which button is being pushed. We will be customizing this with a Dallas DS18B20 temperature sensor, and MOSFET / SSR control over the Furnace and A/C. A video of how this works has been uploaded to YouTube.

//Sample using LiquidCrystal library
#include "LiquidCrystal.h"
This program will test the LCD panel and the buttons
Mark Bramwell, July 2010
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
// read the buttons
int read_LCD_buttons()
 adc_key_in = analogRead(0);      // read the value from the sensor
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 if (adc_key_in < 50)   return btnRIGHT; 
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT;  
 return btnNONE;  // when all others fail, return this...
void setup()
 analogWrite(10, 50); // set brightness on pin 10 to 0-255
 lcd.begin(16, 2);              // start the library
 lcd.print("Push the buttons"); // print a simple message
void loop()
 lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over
 lcd.print(millis()/1000);      // display seconds elapsed since power-up
 lcd.setCursor(0,1);            // move to the begining of the second line
 lcd_key = read_LCD_buttons();  // read the buttons
 switch (lcd_key)               // depending on which button was pushed, we perform an action
   case btnRIGHT:
     lcd.print("RIGHT ");
   case btnLEFT:
     lcd.print("LEFT   ");
   case btnUP:
     lcd.print("UP    ");
   case btnDOWN:
     lcd.print("DOWN  ");
   case btnSELECT:
     case btnNONE:
     lcd.print("NONE  ");