Tinkerlog header image 2

Tinkerlog

Alex’ blog

Arduino powered Braitenberg vehicle

April 18th, 2009 · 9 Comments · Arduino, sensor

Jonathan asked me, if I would like to do a project with him on Braitenberg vehicles. After some research and reading the first couple of chapters in Vehicles: Experiments in Synthetic Psychology, I was hooked in. Here is the first version of a Braitenberg vehicle, powered with two RC-Servos and an Arduino as its brain.

Best of all, it needs no soldering, drilling or hot glue. And if you’ve played already with Arduinos, there is a good chance, that you have already most of the needed parts at home..

Braitenberg vehicles

Valentino Braitenberg developed a model of simple vehicles with sensors and actuators (motors) and interconnections between them. While the vehicles are extremely simple, the emerging behaviour is not. It is often interpreted as love, aggression or caution.

The easiest one is a light seeking vehicle. That’s like “hello world” in robotics. The sensors are affecting directly the motors. The right sensor affects the left motor and the left sensor affects the right motor. That means, if light shines on the right sensor, the left wheel turns. And if the light shines brighter on the right sensor, the left motor will turn faster than the left one and so the vehicle will turn towards the light source.

These kind of simple robots can be build with analog techniques alone, they don’t need a microcontroller. Think of two sensors feeding into two amplifiers that control the motors. The big advantage a controller brings in, is the possibility to rewire the connections between inputs and outputs in software. Even more complex functions for the interconnections can be reprogrammed easily.

Needed parts

  • Arduino board
  • small breadboard or prototyping Arduino shield
  • 2 RC-servos, can be cheap
  • 2 wheels, Solarbotics
  • 2 light sensors, LDR (Light Dependent Resistor), e.g. CdS from Solarbotics, and 2 resistors
  • 2 3-pin headers
  • battery holder and 4 rechargeable batteries
  • some rubber bands
  • some wires
  • paper clip

I am using a Boarduino here, that snaps nicely into the small breadboard. The two wheels are used for convenience. You could use any other type of wheels and attach them to the servos.

The two resistors have to match the LDRs to form a good voltage divider. Otherwise you get only a small range of values out of your sensors. Mine work great with a 10 k resistor.

The servos are hacked. Hacking servos means modifying them for continuous motion. A standard servo moves its tiny arm around from -90 to +90 degrees. But we want them to act as simple motors. There are quite a number of resources out there on how to hack a servo. One of the latest and very good documented one is from Tod. Check out his post about “Tiny Servos as Continuous Rotation Gearmotors”.

Tools

Nothing. Ha, no soldering iron, no drilling and no hot glue! Ok, you need a PC and an USB-cable.

Assembling

Attach the two servos to the breadboard by using 3-pin headers. Connect the red cable to VCC and the brown one to GND. The orange cable is used to send the control pulses to the servo motor. It is connected to Arduino pin 10 (left) and 9 (right).

The LDR and the resistor are forming a voltage divider. Connect the LDR to VCC and to a free socket on the breadboard. Now connect the resistor to GND and a free socket of the same row as the LDR. Next connect a wire from this row to the analog input pins of the Arduino (left to analog 0 and right to analog 1).

Now take the two servos, put them together and wrap a rubber band around them and the breadboard. Then attach the battery holder to the breadboard and fix it with another rubber band.

Use the paperclip or some other kind of wire to form a small hook. The hook should snap into place and holding the breadboard and the battery holder together. And it has a little notch that is used instead of a third wheel.

Now this tiny guy is complete.

Arduino Code

/*
 * Simple braitenberg vehicle
 * http://tinkerlog.com
 */

#include "Servo.h"

Servo leftServo;
Servo rightServo;
int leftValue = 0;
int rightValue = 0;

void setup() {
  leftServo.attach(10);
  rightServo.attach(9);
} 

void loop() {
  // sensor values between 50..900
  leftValue = (analogRead(0) - 50) / 50;
  rightValue = (analogRead(1) - 50) / 50;
  leftServo.write(89 + rightValue);
  rightServo.write(89 - leftValue);
  delay(10);
}

Yes, that’s all it needs. Only 25 lines of code. Including comments.

The analog values of the sensors are in a range between 50 and 900. So we take 50 as 0 and scale the value down.

The value you send to the servo is the degree it should turn to. From 0 to 180 degrees. At 90 degrees it is centered. For me, 89 is the value at which the left and the right servo stands still. If we add a value, the servo motors spins forward, if we subtract a value, it spins backward. The function for the right servo subtracts the values because it is attached on the opposite side.

You might have to write some simple sketches to evaluate the right values of the sensors and servo motors.

If you plug the USB cable into your PC, it may suck too much power because of the servo motors. You can power it with your external battery pack. Check your Arduino board, most have a jumper for external power supply. Or you unplug the servos for programming.

Play

Now switch him on and see if he finds some light sources. It works better, if the rest of the room is dark with only a single light source. I managed to tempt him with a flash light or a lighter. If he seems not to turn as much as he should, try to bend the light sensors more sideways.

This small bot is a bit shaky because of the rubber bands. But he is forgiving. And as he moves around underneath your table, you almost instantly think of him as something that has its own will. Even if you know, that it has only two sensors and two motors.

Links

Add this to:Del.icio.us Del.icio.us Digg! Digg

9 responses so far ↓

  • 1 Arduino powered Braitenberg vehicle - light seeking robot « adafruit industries blog // Apr 20, 2009 at 18:44

    [...] is a great solderless Arduino (Boarduino) based robotics project! Tinkerlog writes – Jonathan asked me, if I would like to do a project with him on Braitenberg vehicles. After some [...]

  • 2 Arduino powered Braitenberg vehicle - light seeking robot at ArduinoShow.com - The Arduino Project Access Point. // Apr 21, 2009 at 02:52

    [...] [link] | [via] [...]

  • 3 I dream of Robot… « Brain Dump // May 11, 2009 at 13:33

    [...] then, when I was trying to do some actual work, I stumbled across this description of how to build a Braitenberg vehicle. It’s based on Arduino, which is apparently an open-source electronics platform – just [...]

  • 4 Zementblog » Arduino-Neuigkeiten // May 19, 2009 at 20:44

    [...] vorhabe? Ich will in die Robotik einsteigen. Dazu beginne ich mit einer leichten Übung, dem Bau eines Braitenberg’schen Vehikels (eine Idee von einem zweirädrigen Roboter, der Licht sucht). Diese lässt sich mit solchen [...]

  • 5 XBee 101 « Deviation’s from Boredom // May 28, 2009 at 18:59

    [...] breadboard based robot – inspired from the Braitenberg vehicle that can be found on the blog Tinkerlog. The bot uses a Dorkboard as a brain (I prefer to use the Dorkboard over Adafruit’s DC [...]

  • 6 Zementblog » News (2. Juni ‘09) // Jun 2, 2009 at 12:44

    [...] bin, einen Roboter mit dem Arduino-Board als “Gehirn” auf Grundlage des Tutorials zum Bau eines “Braitenberg’schen Vehikels” von Alexander Weber zu konstruieren, sind die heutigen News etwas [...]

  • 7 Jan // Jun 7, 2009 at 17:25

    Hello,

    my own “Braitenberg vehicle” has been finished seconds ago. Your tutorial was really helpful. I’ve got a picture of my version here:

    http://freeduino.de/files/images/PICT0006.preview.JPG

    Greetings,

    Jan

  • 8 a well-documented project « Making Things Interact Fall 09 // Oct 15, 2009 at 10:48

    [...] well-documented project This Braitenberg vehicle project is very well documented (and interesting, [...]

  • 9 Mikrokontroler.info // Nov 3, 2009 at 22:14

    Pojazd Braitenberga na Arduino…

    Tematyka robotów zawsze mnie fascynowaÅ‚a. Niestety, do tej pory na fascynacji siÄ™ koÅ„czyÅ‚o. Zawsze chciaÅ‚em coÅ› zbudować, ale kwestia części mechanicznej skutecznie mnie zniechÄ™caÅ‚a. Jestem elektronikiem, a nie mechanikiem! No cóż, może …

Leave a Comment