A documentary movie about Arduino

Here’s a really interesting documentary devoted to Arduino project. It explains how the idea began and why its creators decided to spread it out freely. There are also demonstrations of some smart devices based on Arduino.

You can watch it on the Arduino Documentary page in english (except for some spanish snippets, english subbed) or spanish verion.

Puff – The Magic Firefighter

This is Puff, Magic Fire Fighting Dragon

Puff consists of:

  • Arduino
  • chassis and two motors
  • servo moving its head
  • motor with a fan
  • two photoresistors as fire detectors

The result? Autonomic robot (this means, controlled only by software from Arduino) detecting fire (this means, a bright light) and trying to put it out. It recognizes edges (to not fall down) and obstacles (to avoid it).

Here we have an example of panic mode, when it didn’t succeeded to quench the fire:

Puff is a developmental project, you can monitor the progress on Let’s Make Robots.

Arduino SMS and not only

GSM module for Arduino lets you convert it into a cell phone :) Well, somewhere about a cell phone.

Arduino with GSM module (a makeshift power supply in the background)

Arduino with GSM module (a makeshift power supply in the background)

Let’s start from the beginning. First, we need the the module and a valid SIM card. The first issue – power. The GSM module is quite demanding in this regard. Not every USB port provides enough power to feed an Arduino with GSM module. As a result, the communication breaks up immediately afer entering PIN code. In this case you will need an additional power supply. How to – more on that later.

Testing the module

GSM module can work in two serial comunication modes. It “talks” with Arduino or a computer connected to Arduino’s USB port. The first is used during normal operating, the second can be used for testing. To choose the second mode you should follow these steps:

  1. remove the ATMega from Arduino (Arduino will be used only as power supply, we will be utilizing also the USB/Serial converter)
  2. set operating mode jumpers to USB gateway
  3. insert SIM card
  4. connect Arduino to computer
  5. press ON/OFF button on module and hold it for two seconds
  6. start the terminal software (gtkterm), choose serial port (parameters: 115200 8,N,1, line ending – CR (not CR+LF)) and write AT commands in UPPERCASE
    • AT – the answer expected is “OK” – this means the connection has been estabilished
    • AT+CPIN=”ABCD” – where ABCD is the PIN code of SIM card inserted – we should get “OK” if it’s correct or “+CME ERROR 16” if not
    • the module starts to search for GSM network – if it will be returning “OK” for “AT” command in the next few seconds, means the USB port succeeded to power the device. In case of a failure, begin to prepare additional power supply
    • if it’s working we can try some commands:
      • AT+COPS? – returns the name of GSM provider
      • AT+CPBR=# – returns an entry from address book (# is a number)
      • AT*PSCPOF – turns the module off
      • ATD##########; – call the number # (of course, a conversation is impossible, for now)
      • ATH – ends the call
    • sending a SMS – follow these steps:
      • AT+CSCA? – download the SMS center number
      • AT+CMGF=1 – SMS sending mode – 1 is tezt
      • AT+CMGS=”#######” – target number
      • after AT+CMGS begin to enter the message content in a single line and end with character 0x1A (hex code)
      • wait for the SMS ;)

Full AT command list for Sagem HiLO modem is here.

GSM module has a microphone input and speaker output, so it’s able to act as regular cell phone :)

Power feeding

There is a jumper specifying power source. When set in “5V” position, Arduino is used for powering the module. By choosing “ext” we are able to power it from external power supply. The manufacturer reccomends a 12V, 2A supply. When using a supply with current efficiency lower than 2A, a 220 μF capacitor should be added. I tested whole device feeding Arduino from USB port and GSM module from 12/0.5A power supply with 200 μF capacitor and 5V voltage regulator (L7805).

1 - power socket and power source jumper, 2 - communication mode jumper

1 - power socket and power source jumper, 2 - communication mode jumper

Controlling it from Arduino

When serial mode communication jumper is set to Arduino, the module can be connected to Arduino serial port and controlled by commands sent from Arduino (using Serial.println). An example code:

int led = 13;
int onModulePin = 2;        // the pin to switch on the module (without press on button)
int timesToSend = 1;        // Numbers of SMS to send
int count = 0;

void switchModule(){

  digitalWrite(onModulePin,HIGH);
  delay(2000);
  digitalWrite(onModulePin,LOW);

}

void setup(){

  pinMode(led, OUTPUT);
  pinMode(onModulePin, OUTPUT);
  Serial.begin(115200);               // the GPRS baud rate
  switchModule();                    // swith the module ON

  for (int i=0;i<5;i++){
    delay(5000);
  }
   Serial.println("AT+CMGF=1");         // set the SMS mode to text
}

void loop(){

  while (count < timesToSend){
    delay(1500);

    Serial.print("AT+CMGS=");               // send the SMS the number
    Serial.print(34,BYTE);                  // send the " char
    Serial.print("*********");              // send the number change ********* by the actual number
    Serial.println(34,BYTE);                // send the " char
    delay(1500);
    Serial.print("Arduino SMS...");     // the SMS body
    delay(500);
    Serial.println(0x1A,BYTE);                // end of message command 1A (hex)
    delay(5000);
    count++;
  }

  if (count == timesToSend){
    Serial.println("AT*PSCPOF");             // switch the module off
    count++;
  }

}

Finally – as you can see, this module has a weird shape. Well, it fits perfectly to another shield – GPS :)

Arduino with GSM and GPS shields

Arduino with GSM and GPS shields

But about it later.

Programming the Arduino Pro Mini with USB Mini

Everyone, who has been making a project based on Arduino probably wanted the board to be smaller than the basic unit.

A variety of smaller, but compatible with Arduino, boards have been developed. One of them is SparkFun’s Arduino Pro Mini. Currently, it has ATmega328 onboard and its dimensions are 33 mm x 18 mm. It’s available in two versions. The first runs on lowered (3,3V) supply voltage, sacrificing clock frequency (up to 8 MHz). The latter version is a copy of an ordinary Arduino – works with 5V supply and the maximum frequency is 16 MHz.

If the board is so small, then what’s lacking? So, there is no USB/Serial converter (however, it lowers the price also). Because of that we need an additional device for programming it – USB/Serial TTL converter.

One of USB/Serial converters in Nettigo’s offer is Arduino Mini USB. Wiring it up and programming could cause some problems, so, here is a small HOWTO:

Manual programming

After resetting the device, Arduino bootloader is active for about a second. It waits for data on Serial and, if some binary data is present – transmission will be stored in Flash memory and started. Therefore, the simplest way is to connect Arduino Mini USB and Pro Mini like the following:

  • Connect USB Mini and Pro Mini grounds (GND z GND)
  • Supply voltage from USB Mini (+5V) to Vcc on Pro Mini
  • RX from USB Mini to RX1 on Pro Mini
  • TX from USB Mini to TX0 on Pro Mini

The outputs on USB Mini are unlabelled, so here is a pinout schematic (USB socket is at the left of this picture):

USB Mini pinout

USB Mini pinout

In practice, it looks like this:

Manual reset circuit

Manual reset circuit

A sketch needs to be compiled at first (the icon with a triangle) and compiled after that. In order to do it, press the reset button on Arduino Pro Mini and the upload button in Arduino IDE simultaneously (before that, choose the proper board in Tools/Board menu). TX i RX on USB Mini will start blinking and the sketch should be on Pro Mini after a while.

Automatic Reset or Software Reset

Since a long time ago, a regular Arduino can be easily programmed by clicking Upload in the IDE with no need for resetting it manually. In the case of Mini boards, often placed in difficult spots, this method is much better.

To accomplish it, we only have to connect USB Mini’s RTS output to any of RST inputs on Pro Mini:

Automatic (program) Arduino Pro Mini reset

Automatic (program) Arduino Pro Mini reset

I’ve used Bus Pirate probes here, because I hadn’t any pin headers soldered. From now on the programming only requires clicking Upload in Arduino IDE.

Remember the colours – a game

The following article is based on this entry on Newton’s blog (in Polish). All the pictures, program code and the video clip came from there.

This project’s goal was to use as many parts from the Arduino Starter Kit, as possible. So, what is this project exactly? As the title itself suggests, it’s a game, whose object is to remember a colour sequence and recreate it. At the very beginning the sequence consists of 3 colours only, hovever, the difficulty level increases – an extra colour is added each time. Every colour has a different tone assigned. This tone is emitted from a buzzer when the corresponding colour is displayed, so the game involves two senses, both sight and hearing. User interface consists of: RGB LED diode displaying the colours, 8 red LED diodes arranged in a row to display which colour in turn we are setting and two microswitch type buttons. By pushing both in the same time we are starting the game, the left button chooses the colour, the right – accepts. There are two more LED diodes, indicating whether we have recreated the sequence properly (left LED), or not (right LED).

Whole device mounted on a breadboard looks like the following:

Device mounted on a breadboard

You can see (and hear) how it works on this video clip. Hereunder is the circuit schematic made in Fritzing:

Circuit schematic

Circuit schematic

All the resistors used are 220Ω and the IC in the centre of the breadboard is 74HC595 shift register, which allows to drive eight LEDs using only three Arduino digital pins. This was described in “Shifted LEDs” article.

When everything is connected, we should take care of the code. At the beginning we must declare where we have connected what (to which input/output). The following code is responsible of it:

int latchPin = 8, clockPin = 12, dataPin = 3; //shift register
byte data = 0; //register data

int led8 = 7, led9 = 6; //additional LEDs
int ledR = 11, ledG = 10, ledB = 9; //LED RGB
int buttonLeft = 5, buttonRight = 4; //buttons
int speakerPin = 13; //buzzer

Here comes the initialization part – setting pin as input/output, turning internal pull-up resistors on and so on:

void setup()
{
  Serial.begin(57600);
  for(int i=3;i<=13;i++) // setting all the pins
    pinMode(i, OUTPUT); // from 3 to 13 as outputs
  pinMode(buttonLeft, INPUT); // setting the button pins
  pinMode(buttonRight, INPUT); // as inputs

  digitalWrite(buttonLeft, HIGH); // turning internal pull-up
  digitalWrite(buttonRight, HIGH); // resistors on
  randomSeed(analogRead(0)); // initializing the pseudorandom number generator
  // with the value read from analog input no. 0 
  // - each time it's different
  clearLeds();
}

If you are wondering what stands for such a strange notation:

 a ? b : c

here is the explanation.

The main loop of our program looks like the following:

void loop()
{
  effect();
  clearLeds();
  if(waitForButton() == 3)
    return;

  for(int j=3;j<=8;j++)
    if(!playLevel(7, j))
      return;
}

Consecutively: at the beginning, effect() function turns on visual and light effects, clearLeds turns all the LEDs off. After that, unless the user pushes both buttons at the same time, what will cause a reset, playLevel function starts successive levels of the game, increasing the second parameter (number of the lights to remember) by 1. The first parameter denotes the total number of colours (from 0 to 7). Of course, we can lower it, but then the game will become too easy. It’s better to add another colours using setColor function (changing parameters in setRGB) and upgrade it. Then, we can put the total number of colours (remember – the numeration starts from 0!) as the first parameter of playLevel function to make the game more difficult and hence – more addicting ;).

The whole program code with comments is available here. I think it’s clear enough and doesn’t require any additional explanations.

How to connect switches

Switches (buttons, pushbuttons, tact switches) are commonly used with Arduino. But, for beginners, it’s sometimes irritating when it comes to wire them up correctly. Some of their terminals are shorted with each other. Such a switch doesn’t work if putted in reversely. Because of that, here’s some words of explanation.

For instance, we have a button like this:

Just an ordinary button.

As you can see, it has four terminals organised in two pairs. These pairs are shorted when we are pushing the button. Which of them are which? Maybe this picture will be helpful:

Internal connections of the button

And here is a photo with a switch symbol shown:

Button with schematic

Now it’s clear that proper orientation is the crucial thing. Turning the switch by 90 degrees causes permanent short – the button will act as a jumper, not as switch.

For even cleaner explanation, example of a working circuit:

Circuit with a button

And this is how it looks with schematic:

Circuit with its schematic

This switch shorts the resistor to ground. How to detect whether the button is pressed or not? Read more in the article about Family Feud.

Arduino UNO as a joystick

It was pretty predictable. One of the new Ardiuno UNO features is a re-programmable USB communication chip.

Wirtualny joystick CC by http://www.flickr.com/photos/jon_knox/4711705430/

On the Arduino forum appeared a solution for loading custom firmware on this chip with the joystick as an example. So, after loading this firmware and connecting to PC, Arduino will be detected as joystick, not as serial port.

I want more digital outputs!

Arduino offers quite a few digital outputs, but sometimes you want even more… When a keypad and LCD are connected, it doesn’t remain much free outputs.

Today I found out a simple solution for that – EZ Expander shield. The shield utilises two shift registers, 74HC595 to ‘multiply’ digital outputs. Of course, the additional outputs can be used only in output mode (there is no possibility to read from them).

EZ Expander CC by http://nootropicdesign.com/ez-expander/

So, this is the shield, but if you need more outputs (LED diodes?), then you can use only EZ Expander’s library and any shift registers (74HC595 of course will fit). Just wire up the registers and send values to them with simple digitalWrite – take a look at ‘Advanced API usage’ section in the documentation. But don’t fear the ‘advanced’ :)

There is a few other interesting things at nootropic, for example Arduino-based video game system. It uses TVout – library for generating composite video on AVR chip (so, Arduino too). If you want to know, how to generate video with Arduino, check the Sprae’s blog (Arduino as a graphics card – unfortunately, only in Polish).

Hall effect sensor

Hall effect sensor is a sensor utilizing the Hall effect to measure magnetic field. Briefly speaking, it’s about diference in voltage charges within a conductor placed in magnetic field.

CS3144E available in Nettigo store is a Hall effect sensor in TO-92UA package. It consists of voltage regulator, Hall voltage generator, differential amplifier and Schmitt trigger. The output is open-colector type.

Internal sensor’s structure:

Internal sensor's structure

And it looks like the following:
Sensor's pinout

Don’t bother about the markings – it’s totally different device, but the package is the same. I’m just not able to make a decent photo in macroscale ;) Of course, the terminal no. 1 is the first from the left, when looking at the package from the marked side.
The sensor gives two voltage values on its output: VOH, near to the supply voltage and VOL, near to zero. High value appears on the output when it’s no magnetic field. To be more accurate, when the field around our sensor is to weak to exceed the threshold value. When the field strength will increase enough, the output voltage will fall hardly to zero. It will return to the previos state only when the field strength will become lower, and the threshold value for

L->H change is lower than for H->L. To illustrate this – a graph:

Output voltage change

Such a output voltage levels are so called hysteresis. And why there’s no single threshold value? In this case, when the field strength is near threshold
value, output voltage switches rapidly between high and low states.

With two threshold values, there is no problem – when magnetic field reaches BOP value, output switches from high to low state. It changes in the opposite direction only when the field reaches BHP value, which is lower than BOP.

Thanks to this, there is no blinking effect, which would appear when the switching is performed independently from the direction.

Simplest aplication

Of course, the Hall effect sensor has many sophiscated applications, for example in a rpm meter, but I’ll show the simplest one – turning a LED diode on and off with a magnet.

The sensor gives two voltage levels on its output, so the best solution is to wire it up to one of Arduino’s digital pins. To do this we must, as usual, declare the pin as input in setup() function entering:

pinMode(hallPin, INPUT)

where hallPin means the digital pin number – I chose 8. Another thing to do is to pull it up using internal resistor. In other case, the input will remain unconnected and receive interferences, which will result with the diode blinking in a random way. So, immediately after the previous line, we are adding:

digitalWrite(hallPin, HIGH);

As a output we choose another digital pin. The best is 13th, because most Arduino models have internal LED diode connected there. The rest of the code rather doesn’t need any comments – the input is read in a loop and the output is set according to its value. The whole program code is here:

const int hallPin = 8;
const int ledPin = 13;

int hallState = 0;

void setup(){
  pinMode(hallPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(hallPin, HIGH);
}

void loop(){
  hallState = digitalRead(hallPin);

  if (hallState == HIGH){
    digitalWrite(ledPin, LOW);
  }
  else{
    digitalWrite(ledPin, HIGH);
  }
}

Connection diagram (just in case – there’s rather no vaguenesses):

Connection diagram

External LED diode is optional, unless our Arduino has a built-in one. In the other case it should be connected, as shown. A resistor limiting the current can be safely omitted.

This is how an assembled circuit looks:

Assembled circuit

And it works in this way.

As you can see, I tried two different magnets and the difference in range is clearly visible. Unfortunately, I hadn’t any neodymium magnet, but I suppose the sensor would react from farther distance.

Secret keylock – with Arduino

I’ve seen many electronic keylocks, but this project is probably unique :)

In a nutshell – Arduino listens to knocking on a door and, if you are knocking with a specific rhythm, then it unlocks the door. Along with this, a simple method of learning the new cipher and it’s finished :)

If someone is interested, the details can be found on ArduinoFun a blog – code, diagrams, etc.