Description
Based on the toy of 2 boxers, the system responds to the proximity of the user, and increases the speed at which the 2 boxers move their arms. A system of 2 pulleys was created to move the arms of both boxers. If their movement is fast, a red LED turns on, otherwise its green.
Materials:
-DC Motor
-Photocell
-Red LED
-Green LED
-Rubber Bands
-Cardboard
-Sticks
CODE:
/*
* The photocell controls the speed of the DC Motor. It also controls the Red and Green LEDs
*/
int photoCell = 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
int ledPin1 = 11;
int ledPin2 = 10;
void setup() {
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop() {
val = analogRead(photoCell); // read the value from the sensor, between 0 - 1024
analogWrite(motorPin, val/4); // analogWrite can be between 0-255
if (val < 512)
{
digitalWrite(ledPin1, HIGH);
}
else
{
digitalWrite(ledPin1, LOW);
Serial.println(val);
}
if (val > 512)
{
digitalWrite(ledPin2, HIGH);
}
else
{
digitalWrite(ledPin2, LOW);
Serial.println(val);
}
}