Monday, January 23, 2012

Understanding Servo Motors

"Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. The signal pin is typically yellow, orange or white and should be connected to a digital pin on the Arduino board. Note servos draw considerable power, so if you need to drive more than one or two, you'll probably need to power them from a separate supply (i.e. not the +5V pin on your Arduino). Be sure to connect the grounds of the Arduino and external power supply together."

I bought my Servo motors from InMotion who imported them from SparkFun.

It's easy to control a Servo with Arduino using the libraries distributed with the Arduino IDE, but with only three wires, how is that controlled?

A servo motor expects a PWM signal with a very specific period and duty time.
Usually a 20ms period and a 1ms to 2ms as duty time.

On a regular servo the minimal duty cycle means a 0º position, the maximum corresponds to 180º and half way equals 90º.
On a full rotation servo, each period to motor rotates acording to the duty cycle.
Under 1,5ms rotates counter-clockwise and above 1,5ms rotates clockwise.

Controlling a servo from Arduino:

To test the theoretical knowledge I tried to run this simple sketch:

void setup() {
  // put your setup code here, to run once:
  pinMode(9, OUTPUT);

void loop() {
  // put your main code here, to run repeatedly: 
  digitalWrite(9, HIGH);
  digitalWrite(9, LOW);

Worked fine!

But for the best control, why not use a tested and proven library?

So I used Arduino's IDE Sweep example that rotates the Servo from side to side (0 to 180 degrees and back) using a class designed for that purpose.
The Sweep example seems simple and self-explanatory for me to give more detail about it.

In my full rotation servo I noticed that it rotated more going counter-clockwise than when moving clockwise.

I don't know why does it happen...

Thursday, January 19, 2012

Nokia 5110 LCD

I bought a SparkFun Nokia 5110 LCD through InMotion. Both sites have the datasheet and example documentation for how to use it.
Adafruit also sells this and documents its use with another excellent Ladyada tutorial.

Here it is with connectors already soldered:

The soldering is pretty bad. Maybe I should buy a new tip for my soldering iron...

This screen supports direct connection to an Arduino (5V), but in doing so we push it to the datasheet defined limits, so to it is best to reduce all signals to a confortable 3.3V.

My Arduino Duomilanove only outputs 5V signals, so in order to translate those signals to 3.3V, the simplest way is to use a Voltage Divider.
I used this site to calculate the best resistor values to use for this case (10kOhm and ~5kOhm).
Adafruit offers a free level shifter with the LCD that can be used as a more efficient Voltage Divider.

Also to light up the 4 leds used as backlight I used a 22Ohm resistor, so that I could connect to a 5V signal on the Arduino in order to control them with PWM.

And here it is using the Arduino example code 2:

Wednesday, January 18, 2012

Electronics Stores

Here are my favorite electronics stores:


Aquario (Porto) - Nice collection of generic electric components, ICs and tools, but not for hobbyist electronics, like sensors, motors or other robotics components;

InMotion (On-line) - Nice catalog with products from SparkFun and Pololu, etc. Usually they offer the shipping costs at Christmas. It is possible to order SparkFun items by mail that aren't on their catalog.

PTRobotics (On-line) - Like InMotion, they have a very good catalog of products.

Found a link on a forum with their own list: LusoRobotica


Sparkfun (US) - Best generic store, but the shipping costs can be very high for a direct order. The most common items can be found in distributors around the world.

Adafruit (US) - Main competitor for SparkFun. Can't tell wich is best.

Pololu (US) - Best store for motors and related products, shipping costs have the same problem as SparkFun;

eBay stores (mostly China) - Sometimes we can find great deals with free shipping from high trust rated sellers.

Friday, January 13, 2012

Electronics Components

Here I'll be updating some links about electronics components, as a wiki with the best information I can find.

- Zener Diodes