After exploring servo motor with potentiometer, I created lego car which moves by servo. I used two tires to make the car mobile and put stick with rubber to the servo motor.
Components:
Arduino
3wires
Servo motor
wooden stick and rubber
Lego blocks
Code: I used reference in Arduino website.(http://arduino.cc/en/Tutorial/Sweep)
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(7); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1+1/2); // waits 1.5ms for the servo to reach the position
//by doing this I could make the rotation less than 180 degree
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1+1/2); // waits 1.5ms for the servo to reach the position
}
}
- Login to post comments