Blinking Monkey

My project involved a monkey doll and detecting how close someone is. The biggest problem I had was getting the infrared proximity to get correct readings (which I couldn’t get working in time), and opted out to using a potentiameter as a replacement. Please assume I used a proximity sensor when reading the description below.

The monkey had a set of LED’s, three rows where each row had different color, in the front.

If someone is very far away, the LEDs would fade in and out. Once someone is closer, each row of LEDs would blink alternatively but at a faster rate as someone gets closer. Once someone is very close, all the LEDs would all blink together (at a faster rate as someone gets closer).

Video demo

http://www.vimeo.com/1810723

Code

/*
* AnalogInput
* by DojoDave <http://www.0j0.org&gt;
*
* Turns on and off a light emitting diode(LED) connected to digital
* pin 13. The amount of time the LED will be on and off depends on
* the value obtained by analogRead(). In the easiest case we connect
* a potentiometer to analog pin 2.
*
* http://www.arduino.cc/en/Tutorial/AnalogInput
*/

int potPin = 2;    // select the input pin for the potentiometer
int ledPin = 9;   // select the pin for the LED
int ledPin2 = 10;   // select the pin for the LED
int ledPin3 = 11;   // select the pin for the LED

int val = 0;       // variable to store the value coming from the sensor
int value = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
pinMode(ledPin2, OUTPUT);  // declare the ledPin as an OUTPUT
pinMode(ledPin3, OUTPUT);  // declare the ledPin as an OUTPUT
}

void loop() {
val = analogRead(potPin);    // read the value from the sensor
Serial.print(val);
Serial.print(“\n”);

if (val > 500) {
for(value = 0 ; value <= 100; value+=5) // fade in (from min to max)
{
analogWrite(ledPin, value);           // sets the value (range from 0 to 255)
analogWrite(ledPin2, value);           // sets the value (range from 0 to 255)
analogWrite(ledPin3, value);           // sets the value (range from 0 to 255)
delay(50);                            // waits for 30 milli seconds to see the dimming effect
}
for(value = 100; value >=0; value-=5)   // fade out (from max to min)
{
analogWrite(ledPin, value);
analogWrite(ledPin2, value);
analogWrite(ledPin3, value);
delay(50);
}
}

else if (val < 200) {
digitalWrite(ledPin, HIGH);  // turn the ledPin on
digitalWrite(ledPin2, HIGH);  // turn the ledPin on
digitalWrite(ledPin3, HIGH);  // turn the ledPin on
delay(val);                  // stop the program for some time

digitalWrite(ledPin3, LOW);   // turn the ledPin off
digitalWrite(ledPin2, LOW);   // turn the ledPin off
digitalWrite(ledPin, LOW);   // turn the ledPin off
delay(val);                  // stop the program for some time

}
else {
digitalWrite(ledPin, HIGH);  // turn the ledPin on
delay(val);                  // stop the program for some time
digitalWrite(ledPin2, HIGH);  // turn the ledPin on
delay(val);                  // stop the program for some time
digitalWrite(ledPin3, HIGH);  // turn the ledPin on
delay(val);                  // stop the program for some time

digitalWrite(ledPin3, LOW);   // turn the ledPin off
delay(val);                  // stop the program for some time
digitalWrite(ledPin2, LOW);   // turn the ledPin off
delay(val);                  // stop the program for some time
digitalWrite(ledPin, LOW);   // turn the ledPin off
delay(val);                  // stop the program for some time
}
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s