greeitings, I am trying to control the brightness of some incandescent lights using Arduino and the Parallax PING ultra sonic sensor. the idea is that the closer an object gets to the sensor, the brighter the lights will get. Im fairly new to arduino, at the moment I have gotten the PING to light up some LEDs the closer I get to the sensor... i will post my code and a quick video shortly. SO any ideas?
Any help with hardware or code advice is welcome
I had thought about using LEDs, but im worried they wont get bright enough (i want this thing BRIGHT), but if LEDs are really the way to go, please let me know point me in the right direction.
Thank you!
EDIT: i was not able to get the video up... but here is my code for 4 LEDS..
#define led1 2
#define led2 3
#define led3 4
#define led4 5
const int pingPin = 7;
int duration;
void setup(){
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
Serial.print(duration);
Serial.println();
delay(100);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
//these values may need to be changed for your setup
if (duration < 11000){
digitalWrite(led4, HIGH);
}
if (duration < 8000){
digitalWrite(led3, HIGH);
}
if (duration < 5000){
digitalWrite(led2, HIGH);
}
if (duration < 1000){
digitalWrite(led1, HIGH);
}
delay(50);
}