Parallax Ping))) and rgb led

Hi all, i have made a small alarm from rgb led. When you approach it turns red light on! otherwise it slightly blue)

i have used this sensor

here you can check how it works

and here is the code:

const int pingPin = 7;
unsigned int duration, inches;
int Sensor = 0;
int value = 0;
int red = 6;

void setup() {

void loop() {
pinMode(pingPin, OUTPUT); // Set pin to OUTPUT
digitalWrite(pingPin, LOW); // Ensure pin is low
digitalWrite(pingPin, HIGH); // Start ranging
delayMicroseconds(5); // with 5 microsecond burst
digitalWrite(pingPin, LOW); // End ranging
pinMode(pingPin, INPUT); // Set pin to INPUT
duration = pulseIn(pingPin, HIGH); // Read echo pulse
inches = duration / 74 / 2; // Convert to inches
Serial.println(inches); // Display result
delay(200); // Short delay

value = analogRead(pingPin); //read value from the sensor
delay (20);





Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s