Category Archives: howto

Pin header soldering

During meetings with readers I found out that many of them like the Arduino project, but the greatest barrier is soldering.
Some are literally scared of this – their hands are trembling. In this article I would like to make soldering more familiar.

Some of electronic parts available as printed circuit boards with ready-to-use devices (modules) has already terminals in form of holes on the board. It only lacks of connectors or wires. For use with Arduino, the best idea is to solder pin header into these holes.

Pin header is a kind of connector with pins aranged in a line. In most cases the raster (gap between two pins) is the same – 2.54 mm (0.1 inch).
Pin header fit very well to a breadboard.
In this article we’ll be talking about soldering pin headers to Ultrasonic distance meter.


To solder we need:

Soldering iron

If you are amateur electronic-hobbyist, you don’t have to buy advanced and expensive tools. I myself am using simple and cheap 40W soldering iron from long time ago. It’s available in electronics shops for a few dollars. Of course, I reccomend a “pencil” type, not transformer. The second type is better for wires soldering than for small elements, so excluding them, you will avoid many problems.
The most important thing in using a soldering iron is to know, which end gets hot. Grabbing the unproper may end badly.
The iron heats approximately for 2 minutes. It’s ready when solder melts on the soldering iron’s tip.


Solder is a kind of wire made from tin and lead with specific chemicals added. Solder is usually available in a form of spool with wire in a sort of diameters.
I reccomend diameter up to 1mm. We should realize that the smaller is the diameter of solder, the smaller parts can be soldered. However, when diameter is too small, a considerable length of solder will be needed for soldering bigger parts, what could be uncomfortable.
I use 1 mm solder and in the lfollowing example it will be a bit too thick.

Pin headers

Pin headers are available in a sort of configurations (from one to a few rows). We will settle for one row. Usually they are sold in 50 pins pieces.
If a device requires less pins, the remaining are broken up.


Holes and soldering pads should be degreased with a cloth soaked with alcohol, solvent or water. Most of the manufacturers reccomend the last option, but you must be careful, because water can easily short the circuit an slowly vapors from thin gaps like places under ICs.

We are breaking up desired number of pins,

and trying on, whether they fit to the board.

Further preparation

In fact, you could begin soldering right now, but yet one thing would be helpful – a “third hand”. There is quite difficult to hold a part in place, when we have soldering iron in one hand and solder in the second. Pin headers can’t be soldered straigthly (at 90° angle) when the module leans against it.
Fortunately, many ways to solve this problem exist. The most popular is magnifying glasses with “crocodile” grips tightened to a table.
Though, I used…

…a small vise.

The board shouldn’t be tightened by the vise directly. This could corrupt it, otherwise it wouldn’t be held stabily. So, I suggest to cover jaws of the vise with something like foam used to isolate pipes.

What to do with pin headers falling out from the board?
I suggest to glue the plastic ends to the board with “Super Glue”, for example.

Soldering process

The soldering consists in putting hot soldering iron tip to the junction point. Next, solder is applied there. It must melt and flow down, filling the junction.

You have to remember not to heat one point too long (the soldered parts could be damaged). Manufacturers reccomend max 2-3 s.
If the solder will accidently flow over two pins, melt it and divide quickly, using something like a toothpick or match.

Properly soldered junction is cone-shaped.

The most common mistake in soldering is applying too less (the soldering pad isn’t well covered) or too much (there is a bead instead of a cone) solder to the junction.

My soldering

To finally dispel the fear of soldering, I decided to record in on a video
As you can see, dear reader, this isn’t so difficult.

Temperature and LCD

In Nettigo recently appeared LCD kit for Arduino – it is 2×16 alphanumeric LCD with soldered connector fitting to a breadboard and 10 kΩ linear potentiometer for contrast regulation.

LCD kit in action

LCD kit in action

The LCD module has HD44780-compatible controler, what means LiquidCrystal library will be able to handle it. How to connect it?

Let’s begin from the code:

#include <LiquidCrystal.h>

float temp;
LiquidCrystal lcd (12,11,10,9,8,7);

void setup() {

void loop () {
  temp = analogRead(0)*3.3/1024.0;

  temp = temp - 0.5;
  temp = temp / 0.01;
  lcd.print("Temp: ");
  lcd.print("        ");

Basic LCD handling boils down to connecting (I’ll tell about it later) and initializing it:

LiquidCrystal lcd (12,11,10,9,8,7);

The code above defines lcd variable, which will be used for communicating with the module. We will assume the simplest form here, so we are wiring it up:

  • RS pin of the module
  • ENABLE pin of the module
  • Data pins of the module: D4, D5, D6, D7

In this example 12 – RS, 11 – ENABLE, 10-7 D4-D7. Apart from this we need to connect R/W signal to ground (we won’t write anything to it) and power. Even if we’ve connected it all, the display shows 32 little black squares. We need also to set the contrast, providing voltage in range 0 – 5V to Vo pin of the LCD. To be able to adjust it, we will use a potentiometer included in the kit. Everything illustrated in Fritzing (the transistor works as MCP9700, because there isn’t such a part in Fritzing, package is the same – TO-92):

LCD connection schematic

LCD connection schematic

After that, in loop we are reading temperature form MCP-9700 (described in this post). Having the temperature already, we are showing Temp: text and the reading, and going back to the beginning.

How to improve the temperature measurement?

Temperature reading (in form of voltage measured by analog input 0) is given by MCP9700 with accuracy dependent on voltage converter in Arduino. It’s 10-bit and measures voltage from 0 to 5V by default. 10 bits mean that we have 1024 steps in voltage reading. Thus, the voltage is measured with 4.88 mV (5/1024) resolution.

MCP9700 sensor has 10 mV / degree resolution, so it virtually means that we have 0.5 degree accuracy (it’s not about sensor’s quality, it’s about how Arduino measures the voltage).

Arduino’s A/D converter is able to be provided with external reference voltage (AREF – the peripheral pin in the digital outputs row), which replaces 5V. This voltage can be higher or lower than 5V EDIT: Unfortunately, I made a mistake here – converter’s datasheet tell that maximum reference value is the supply voltage – for Arduino it means 5V. If someone needs to measure higher voltage, then voltage divider always could be used…

Potential risk.
According to the reference of
analogReference function, the default setting (when analogReference isn’t invoked at all or invoked with DEFAULT value) could damage the microcontroller on Arduino board when using external AREF!

MCP9700 datasheet shows that maximum output voltage is 500 mV+ 125*10mV = 1.75V. It would be best to force the converter to measure voltage in range 0-1.75V, but it requires to add a voltage divider. This is not difficult, but in order not to complicate, we will use a simple measurement quality improving method, without any additional elements. We will exploit the fact that Arduino provides a 3.3V voltage, apart form 5V and we can improve measurement resolution without any problems.

Because of this in setup the analogReference(EXTERNAL) (it’s not enough to supply a voltage to AREF) function is invoked and in loop the tempreature calculating formula is changed. After changing the reference voltage we have 3.2 mV step, which means the temperature is measured with 0.3°C accuracy and not 0.5°C, like before.

NOTE – the improvement affects only the reading, not the measurement itself. The sensor still has +-2°C accuracy :) . This thick will improve only our mood, because the reading doesn’t jump so much :)

Of course, change of AREF affects all of the analog inputs…

Arduino’s eye, or about a photoresistor, not Tolkien’s mythology

Arduino’s eye – sounds like a quote from J.R.R. Tolkien, while it’s about connecting photoresistor to Arduino. With this article I would to begin short course dealing with basics of electronics.

Photoresistor is a element whose resistance is dependent of amount of light falling on it. What only remains is to measure this resistance. In which way?

For a playful use we will ignore accuracy, assuming simplified model.

How it looks?

Simple circuit built on breadboard

Simple circuit built on breadboard (click on the picture to see notes on Flickr)

Circuit diagram looks like the following:

Circuit diagram

Circuit diagram

What is depicted here is so called voltage divider. You can read on Wikipedia, how it works.

Briefly speaking, voltage on the junction point between two resistors will be varying according to resistance of the photoresistor. And this is what we will be measuring with our program.

This is its code:

// pin, from which we read the voltage
int photoPin = 0;
//the reading
int val = 0;

//initial configuration
void setup()
  pinMode(photoPin, INPUT); // setting the pin as input

void loop()
  //reading and standarizing to range 0-7
  val = analogRead(photoPin)/128;
  for (int i=0;i<=val;i++) {

Program (as hardly every on Arduino) consists of the section preparing the device to work (setup) and main loop (loop) evoked as long as the power is available…

In main loop the voltage is measured, then the reading is converted in range 0-7 (because Arduino reads voltage as a number from 0 to 1023, so dividing it by 128 and rounding down gives digit from 0 to 7) and appropiate number of diodes is lighted up. Short break, and loop again…

The result:

Arduino IDE during execution of our program

Arduino IDE during execution of our program

While the program is running, I’m covering the photoresistor with my hand, changing its resistance, and thus the voltage being read by Arduino from pin 0. The number of dots is proportional to the reading.

Part list:

Coming soon – how to physically show varying reading.

LED diodes – how to flash and light

Recently there was silence on Starter Kit, because before holidays I was preparing to Bootstrap 9.4, what took most of my free time. Now, taking advantage of free day I’m making up for it.

Previously, we were dealing with reading from external sensor (photoresistor). Now we will try to show this reading.

We will use 7 LED diodes arranged in a line making a kind of indicator – the more light falls on the photoresistor, the more diodes will light. Beginning from the end – how it looks in action:

Arduino’s Eye from Starter Kit on Vimeo.

Forgive poor quality, but mobile phone camera is the only tool I can use to perpetuate my experiments with Arduino.

But despite of that the effect is visible. Behind the frame I zoom in and out the photoresistor to a lamp as the diodes are lighting up and fading out.
Continue reading

Arduino – play!

A long silence on the blog is just broken! During the last few months I was strongly engaged in projects not connected with Arduino, whole time was absorbed by keeping the Arduino shields shop, servicing customers, searching for new suppliers, etc.

Now I have a bit time which I can spend by documenting experiments with Arduino, thus I hope to add some examples with Starter Kit soon.

Silence, go away!

As we have to break the silence, so więc let’s begin from controlling so called buzzer a tiny speaker able to produce not very loud sounds, with the Arduino. Let’s start from final product:

Arduino buzzer from Starter Kit on Vimeo.

Buzzer is controlled by Arduino, playing simple melody. Playing speed depend on reading from photoresistor (the more light, the slower it plays).

How it’s made?

I wrote, how to read values from photoresistor in one of previous posts. Buzzer is stimulated to play by properly applied high and low voltage. For (Arduino output port) safety a 220 Ohm resistor is added to lower the current passing through (from PDF with documentation appears that it’s not obligatory – at least 14 Ohm resistance should not generate current higher than 36 mA – lower than the limit value for Arduino I/O port – 40 mA).
Thankfully Arduino is open source and there are many ready to use elements. So, playing melody (note) issue is described in Melody tutorial. We will take advantage of it and add only part reading value from photoresistor and converting it to adequate delay.

The only modification of Melody tutorial (except from setup) is a line in loop:


It divides the voltage reading by 3 and adds 100. This way we will obtain value in range from 100 to 1023/3+100=441. Original tempo was delay 300. Only the schematic remains:

The device schematic

The device schematic

For beginners – a detailed description, how to connect the wires:

Physical connections

Physical connections

Detailed part list (Fritzing has only piezo buzzer in basic library, so it is used on the schematics):

Fritzing Bill of Materials

Sketch: 	buzzer.fz
Date: 	Tue Sep 29 01:11:59 2009

Arduino1      Arduino Diecimila
Breadboard1   Tiny Breadboard
J1            Piezo Speaker
R1            220 Ω Resistor
R2            10k Ω Resistor
R3            Basic Photo-Resistor (Photocell)

Shopping List

Quantity	Part

1		10k Ω Resistor
1		220 Ω Resistor
1		Arduino Diecimila
1		Basic Photo-Resistor (Photocell)
1		Piezo Speaker
1		Tiny Bre

And finally – the code used in example:

How do you like the diagrams and pictures designed in Frizting? For me, it’s perfect software for documenting experiments with Arduino. I reccommend – check it.

How to measure temperature with Arduino and MCP9700

One of the sensors included in Arduino Starter Kit is a temperature sensor. It’s analog device which doesn’t need any additional elements to work (it’s exactly MCP9700-E/TO). So, briefly speaking, after connecting ground and power supply we are already able to measure temperature. On the sensor’s page in Nettigo shop there is PDF datasheet in Files bookmark. So, let’s begin from terminals:

MCP9700 pinout

MCP9700 pinout

Important – the terminals are showed from the bottom of the sensor. To the first we connect supply voltage (both 3.3V and 5V from Arduino would be OK), ground (GND) goes to the third and the second terminal should be connected to Arduino Analog0 pin. As we can read from the datasheet (first page), sensitivity equals 10 mV/ºC. On the second page we have Output Voltage, 500 mV for 0°C. That’s all we should know to write a simple program:

float temp;

void setup() {

void loop () {
  temp = analogRead(0)*5/1024.0;
  temp = temp - 0.5;
  temp = temp / 0.01;

The program measures temperature and sends the reading to Serial, from which we can read it using serial port monitor in Arduino IDE. How the temperature is calculated? I divded the whole process in three steps to make it easier to understand:

  1. temp = analogRead(0)*5/1024.0; Reading value from analog input and converting it to voltage. Maximal voltage Arduino is able to measure equals 5V and the A/D converter’s resolution is 10 bits, which means 1024 values, thus voltage value on Analog0 input is the value returned by analogRead multiplied by the voltage equaling one step of A/D converter. You have to remember, that dividing 5 by 1024 would be interpreted by compiler as integer operation and the result in this case will equal 0. Because of this in the code appears 1024.0 and thanks to this entry, the compiler will treat the dividing as floating point operation.
  2. temp = temp - 0.5; Calibrating to 0°C – the difference between voltage read from the sensor and 500 mV is linearily dependent on temperature.
  3. temp = temp / 0.01; This difference is divided by 10mV/step and now we have temperature

As you can see, the MCP9700 sensor is very simple to use and beginners-friendly. Now everyone can measure temperature with Arduino.

Let’s play, daddy – Family Feud

I was inspired by a simple DIY game seen on the web (I can’t find the link now) and despite the fact that original version was based on greatly simpler PIC I decided to build it with Arduino Starter Kit.

The rules are simple – the one, who will press his button faster after a diode lights up, gets a score. If the button will be pressed before the diode lights up, a point goes to opponent. The game continues, until someone gets five points. Let’s see it in action:

Simple game with Arduino from Starter Kit on Vimeo.

Beside the diode, which will be watched, we need also two diodes to indicate who gets the point and who has won the whole duel, buzzer to play simple melody at the end of the game and two buttons.

Continue reading

When it lacks of current

Sooner or later in experiments with Arduino we will want to drive some kind of device, which needs more than 40 mA to work (40 mA is limitary value, because it’s maximum current that Arduino digital output can supply) It may be a relay, lighting bulb or other current-greedy device.

What to do?

We can use a transistor as an amplifier. Analog techniques is very broad issue, which I don’t know very much (everyone who has studied with me know what I mean :) ), but here I will attempt to present a few informations about driving devices with higher current demand. This example is based on materials from Arduino Starter Kit available on

What you have to know about transistors.

Types – regarding of structure. Basic types are bipolar and field-effect (unipolar). We will focus on the bipolar. They have two groups: NPN and PNP. The difference in structure is other arrangement of semiconductor. Difference in using them is other way the current flows in the transistor, so there are two configurations of the supply voltage.

It seems easier to use NPN transistors with Arduino, because they need to be polarised with positive voltage that Arduino provides on digital output.

NPN type bipolar transistor symbol

NPN type bipolar transistor symbol

Bipolar transistors can work in many applications and each of them can be used in other way. We need to switch high current with low current from Arduino output. To precise, the application we will use is called transistor switch. In this application the transistor is switched between two states: saturation and cutoff.

  • cutoff: UBE is too low to bias the base-emiter junction. Thus, no current flows through the collector.
  • saturation: such a large current flows into the base, that the law IC=hFE*IB isn’t true anymore. In this case, UCE voltage hardly reach zero.

Virtually, the collector current is limited only by the load – what’s connected between the collector and the ground. Current efficiency of our power supply also is a limitation. You must also be careful to not exceed the maximum allowed collector current, which, for currently supplied with Starter Kit MPS2222A transistor equals 600mA.

How it looks in practice?

If we supply a 1 mA current to base, the maximal collector current will be 35 mA (1mA * 35). In case of 10 mA – IC will be max. 350 mA. If IB equals 20 mA, IC will be max…. 600 mA. 600, not 700, because 600 mA is maximum collector current of MPS2222A.

It is worst case, because hFE may vary for different copy of transistor, for one can equal 35, for another 40 – then maximum transistor current 600 mA will be achieved already for 15 mA IB.

Before sketching the circuit – rules of polarising NPN transistor to work as switch:

  • emitter connected to ground
  • positive voltage on base (switch is on) or 0 (switch is off)
  • collector connected to supply voltage through load


NPN transistor - using method

NPN transistor - using method

When we close S1 switch (it equals setting Arduino digital output in high state) UCB will be 0.6V, a current starts to flow into the base. It must be high enough to saturate the transistor, so UCE must fall below UCE(sat) (collector-emiter junction saturation voltage). According to the datasheet UCE(sat) value depends on IC and IB currents. We can estimate it as about 0.3V.
In Arduino Starter Kit there isn’t any part, which could receive current higher than 40 mA, but we can join parallelly some LEDs to demonstrate this issue in practice.

Example of using 4 diodes to exceed 40 mA load

Example of using 4 diodes to exceed 40 mA load

Let’s estimate current flowing through one diode – voltage drop between collector and emitter in saturation state is 0V, voltage drop on red diode – about 1.8V so on the resistor – 5-1.8 = 3.2. For resistors R2-R5 of value 280 Ohm the current flowing through them should be 3.2/280 = 11.42 mA. For 4 diodes it should give about 45 mA.

Before connecting the transistor we should know which terminal is which:

MPS2222A - pinout

MPS2222A - pinout

  1. emitter
  2. base
  3. collector

Physically connections illustrated in Fritzing (frankly admitting – this time it won’t be easy to read. The images probably will be better illustration):

Physically connected circuit

Physically connected circuit

And two photos (on the left of breadboard there is other circuit assembled, so everything what is visible under 25th row doesn’t matter):

Physical construction - take one

Physical construction - take one

Physical construction - take two

Physical construction - take two

Assembly warning – cutted off resistor terminals are perfectly suitable for making short jumpers on breadboard – they are clearly visible in the picture.

Bill of materials generated from Fritzing (all the required parts are included in Arduino Starter Kit from Nettigo):

Fritzing Bill of Materials

Sketch: 	tranzistor.fz
Date: 	Mon Dec 14 10:30:33 2009

Arduino       Arduino Diecimila
Breadboard1   Generic Breadboard
LED1          Red LED - 5mm
LED2          Red LED - 5mm
LED3          Red LED - 5mm
LED4          Red LED - 5mm
Q1            NPN-Transistor
R1            220Ω Resistor
R2            220Ω Resistor
R3            220Ω Resistor
R4            220Ω Resistor
R5            220Ω Resistor

Shopping List

Quantity	Part

5		220Ω Resistor
1		Arduino Diecimila
1		Generic Bajillion Hole Breadboard
1		NPN-Transistor
4		Red LED

Of course, 220Ω resistors are the ones supplied with Arduino Starter Kit for LED diodes and may have other values – from 200Ω to 280Ω. Regardless of the values, this circuit will work.

Sketch for Arduino is classical example of Blink:

 * Blink
 * The basic Arduino example.  Turns on an LED on for one second,
 * then off for one second, and so on...  We use pin 13 because,
 * depending on your Arduino board, it has either a built-in LED
 * or a built-in resistor so that you need only an LED.

int ledPin = 02;                // LED connected to digital pin 13

void setup()                    // run once, when the sketch starts
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output

void loop()                     // run over and over again
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(4000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(2000);                  // waits for a second

At the end, the values measured in real circuit, for 280Ω resistors:

  • supply voltage – 4.96 V
  • UCE voltage – 0.03 V
  • voltage drop on lighted LEDs – from 1.86 to 1.93 V
  • current flowing through LEDs (without incorporating real resistance R2-R5, each of them has 5% tolerance) – from 10.7 mA to 10.9 mA

As homework – it is possible to change pin used to drive transistor to any supporting PWM and control brightness of the diodes using analogWrite instead of digitalWrite. Movie illustrating such a modification:

Driving over 40mA of current – PWM version from Starter Kit on Vimeo.

Today I wrote slightly long article, but I had to include some theory here. I tried hard to avoid inaccuracies, but analog techniques aren’t my strong point :) If you notice any errors, please let me know, I will try to correct them.