Drawing Robot

Today I finished teaching electronics arts course, which was also intro to arduino. In that course we built simple drawing robot. I’ll post here instructions on how to do it and some code examples. Robot is very cheap, if you have arduino and breadboard the parts will only cost you around 10€. With arduino (and breadboard) it’s still just around 40€. Of course the robot is nothing fancy and can for sure be improved upon. But it’s fun intro to Arduino ad programming. Also with some more programing you can have the robot draw lots of nice things :)

_ _ _ _ _ _ _ _ _ _ _ _ _ _

First, heres the parts list:

  • Arduino
  • Half-Breadboard
  • Electrolytic Capacitor
  • L293D -Hbridge. (L293ne will work just as fine)
  • 2 * DC Motor  Basic Photo-Resistor (Photocell)
  • 10k Resistor
  • some jump wire
  • 2* 9volts batteries (Or better is some rechargeable 6-9 volts batteries, but we used normal 9-volt batteries, problem is that they dont last very long)
  • Tires
  • some board to build the robot upon.

Some info on parts:

Electrolytic capacitor  is used to save protect the circuits and give even flow of electricity. We used these 3-6volt gear motors, but any gear motor running 3-6volts will do. The 10K resistor and photo resistor is there because in one sketch we did photo resistor controls different functions depending on amount of light. (Cheap, nice intro to sensors.) But if you don’t want to do that then you don’t need those parts.


The robot is based upon using h-bride (the l293d chip) and controlling motors with arduino through h-bridge. Theres nice tutorials on h-bridge at ITP’s site, and on lucky larrys ardunio site and also on Umass Amherts M5:s site. So I wont explain the basics of h-bridge here. From the scheme you can see how everything is connected. Heres the schemes: And here how to doit on breadboard:
Here a pictures of the finished robot. You can build it anyway you like and improve it.We also did version where the tires where in the center and on both sides we had pens to draw, that was fun also! Or you can just give wheels and make it ordinary robot.


And heres sketch we did for the robot. Shown here is the one with the photoresistor, so it has 3 modes: if its very light it draws randomly varying the speeds of both motors. If it’s normal light it draws spirals and finall if its dark it draws circles and blinks led.  The course was quite short so the code is also kept very simple. But it’s something to get you started. I also did 2 more variations of the theme, one which doesn’t need photo resistor and randomly selects different ways to go, forward or backward. That also made quite interesting drawings. You can download all the sketches as a zip file here.
/* " DRAWING ROBOT" 2010 Tomi Dufva Uses l293ne IC-chip (H-bridge, for info look:http://www.ecs.umass.edu/ece/m5/tutorials/H-Bridge_tutorial.html and http://luckylarry.co.uk/arduino-projects/control-a-dc-motor-with-arduino-and-l293d-chip/) for driving 2 simple dc-motors on random directions. */ int moottori1a = 3; //pin 2 on l293 int moottori1b = 4; //pin 7 on l293: int moottori2a = 5; //pin 10 on l293 int moottori2b = 6;//pin 15 on l293: int enablepin1 = 9;//pin 1 onl293 int enablepin2 = 10; //pin 9 on l293 int moottori1nopeus = 125; //speed of the motor 1 int moottori2nopeus = 125;//speed of the motor 2 int valoisuus = 0; // Variable to store the amount of light the photo resistor gives int led = 13; void setup() { Serial.begin(9600); pinMode(moottori1a, OUTPUT);// Setting all the motor pins as output pinMode(moottori1b, OUTPUT); pinMode(moottori2a, OUTPUT); pinMode(moottori2b, OUTPUT); pinMode(led, OUTPUT); digitalWrite(enablepin1, LOW); //enabling the motor control, but butting them off for starters. digitalWrite(enablepin2, LOW); } void loop() { valoisuus = analogRead(0);//reading the photo resistor Serial.println(valoisuus); if (valoisuus >950){ digitalWrite (moottori1a, LOW); digitalWrite(moottori1b, HIGH); //Putting the first motor to run forward analogWrite (enablepin1,random(0,250)); //randomises the speed of the motor digitalWrite(moottori2a, LOW); digitalWrite(moottori2b, HIGH); //Putting the second motor to run forward analogWrite(enablepin2, random(0,250)); //randomises the speed of the motor delay(random(50,500)); // Below code turns the robot a little, depenfin how long delay you have, so it wont run of the paper! digitalWrite (moottori1a, LOW); digitalWrite(moottori1b, HIGH); analogWrite (enablepin1,125); digitalWrite(moottori2a, LOW); digitalWrite(moottori2b, LOW); analogWrite(enablepin2, 0); delay(1000); // Putting the motors off to wait for the next instructions digitalWrite(enablepin1, LOW); digitalWrite(enablepin2, LOW); } // This makes spirals else if (valoisuus <950 && valoisuus >400){ digitalWrite (moottori1a,LOW); digitalWrite (moottori1b,HIGH); analogWrite(enablepin1, 10); digitalWrite(moottori2a,LOW); digitalWrite(moottori2b, HIGH); analogWrite(enablepin2, moottori1nopeus+250); delay (5000); digitalWrite(moottori2a, LOW); digitalWrite(moottori2b, LOW); analogWrite(enablepin2, 0); delay(1000); digitalWrite(enablepin1, LOW); digitalWrite(enablepin2, LOW); } //This makes circles and blinks a led else { digitalWrite(led,HIGH); delay(500); digitalWrite(led,LOW); delay(500); digitalWrite (moottori1a,LOW); digitalWrite (moottori1b,HIGH); analogWrite(enablepin1, 40); digitalWrite(moottori2a,LOW); digitalWrite(moottori2b, HIGH); analogWrite(enablepin2, 80); delay (2000); digitalWrite(moottori2a, LOW); digitalWrite(moottori2b, LOW); //Määrittää moottori 2 kulkusuunnan analogWrite(enablepin2, 0); //Määrittää moottori 2 nopeuden delay(1000); } } Finally heres some photos of what the robots did… I guess we can’t say it’s art, but at least it was fun to do it. And with little more programming it’s easy to turn the robot to be more expressive and maybe artistic?

UPDATE 19.12.2010

Just updated the breadboard and scheme photos to bit clearer ones.

Comments are closed.