Ultrasonic and LED Code
Ultrasonic and LED Code
Ultrasonic and LED Code
//
/*
Ping))) Sensor
The circuit:
http://www.arduino.cc/en/Tutorial/Ping
*/
int inches = 0;
int cm = 0;
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
void setup()
Serial.begin(9600);
pinMode(8, OUTPUT);
void loop()
Serial.println(cm);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.println("cm");
// Conditios
digitalWrite(8,HIGH);
else
digitalWrite(8,LOW);