Summary:
A small toy car that moves. The car is attached by embroidery floss to a DC motor that will reel the car in when the string is pulled taut by the motion of the motor. Motion is turned on and off by input to a photocell: the motor is activated when the photocell registers lower light values or is covered by a hand. The photocell can be kept separate from the car for use as a controller, or taped to the back of the car to make a "shy car" that moves away from the hand that is reaching for it.
Materials:
Embroidery Floss
1 Toy Car
Tape
1 photocell
1 solderless breadboard
1 Tip120 transistor
1 diode
1k ohm resistor
220k ohm resistor
1 Battery Case (2 AA Batteries)
1 DC Motor
Jumperwires
1 Arduino Uno
Code:
/*
Photocell input is used to turn the motor on and off.
If a hand is placed over the photocell, the car will move forward.
*/
int photocellPin = 0; // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(photocellPin); // read the value from the sensor, between 0 - 1024
Serial.println(val);
if (val <= 0){ //photocell is covered
analogWrite(motorPin, 100);
}
else{
analogWrite(motorPin, 0);
}
}
- Login to post comments