Tag Archives: arduino

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()
  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

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()
  if(waitForButton() == 3)

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

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);
    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.

Processing – interface on steroids

Everyone who become interested, will, rather sooner than later, stumble on the name Processing. Processing is the software on which Arduino IDE is based. But, it isn’t the only common thing.

At first – what is the Processing?

It’s a programming language (under an open source license) with IDE environment created for the people involved in electronic arts and visual design communities (by the Wikipedia).
More clearly? Just look over, for example Vimeo for tag processing.org. Or processing group on YouTube. Data visualization, multimedia experiments, etc. We are able to see, for example, train traffic in Melbourne:

Ebb and Flow of Melbourne Trains by Flink Labs from Flink Labs on Vimeo.

Exactly, and from where the data comes? Well, it might be from Arduino, whose sensors can provide quite a lot of various data to visualize

Now I will give a simple recipe how to use the Arduino and Processing to build … an oscilloscope :) . Oscilloscope is too much said – visualization of the voltage on a single analog input is better description.

Continue reading

SelFly – from the space by glider

SelFly is an interesting (IMO) project of an autonomic (with autopilot) glider which will, elevated to a high altitude (about 30 km) with a weather balloon return home on its own. Good base for further experiments.

All the more I was glad it’s Polish, domestic production :) . I hope the entire project will succeed. Maybe this success would encourage more people to implement their own (sometimes a little crazy, but by that fantastic) ideas.

And this information is here because what will control the glider? Of course – you have guessed – Arduino.

Self-made Arduino shield – making a PCB

Sooner or later, everyone bitten by Arduino bug would want to make his own extension. At the beginning Proto Shield may be sufficient.

When we have a working prototype, we might want to convert it into a series model, so PCB board will be needed.


Time for self-made PCB CC by http://www.flickr.com/photos/odinhg/

On Arduino Forum there is a link to a very nice tutorial, how to make our own PCB board, especially for Arduino shields.

Aaron Eiche, author of the article is a member of DorkbotPDX group, which makes orders for PCBs and everyone can order with them the price is quite attractive – $5 for square inch of a double sided board + $15 for shipment (worldwide). It must be ordered in multiples of 3.