Skip to content
Snippets Groups Projects
Commit 5fcdfc0d authored by Stefan Gehr's avatar Stefan Gehr
Browse files

ultrasonic sensor for distance

parent 540a2d90
Branches
No related tags found
No related merge requests found
const byte ECHO = 6;
const byte TRIGGER = 5;
void setup() {
Serial.begin(9600);
pinMode(ECHO, INPUT);
pinMode(TRIGGER, OUTPUT);
}
void loop() {
digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER, LOW);
unsigned long rawdata = pulseIn(ECHO, HIGH);
Serial.print(0.017 * rawdata);
Serial.println(" cm");
delay(100);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment