EasyManua.ls Logo

Arduino uno

Arduino uno
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Figure 15PING))) basic circuit
digitalWrite(PING_SENSOR_IO_PIN, LOW);
15
-
pinMode(PING_SENSOR_IO_PIN, INPUT);
-
const unsigned long duration = pulseIn(PING_SENSOR_IO_PIN, HIGH);
-
if (duration == 0) {
-
Serial.println("Warning: We did not get a pulse from sensor.");
20
} else {
-
Serial.print("Distance to nearest object: ");
-
Serial.print(microseconds_to_cm(duration));
-
Serial.println(" cm");
-
}
25
-
delay(100);
-
}
-
-
unsigned long microseconds_to_cm(const unsigned long microseconds) {
30
return microseconds / 29 / 2;
-
}
-
First we define a constant for the IO pin the PING))) sensor is connected to.
If you want to connect your sensor to another digital IO pin, you have to
change the programs first line. In the
setup
method, we set the serial ports
baud rate to 9600, because wed like to see some sensor data on the serial
monitor.
Chapter 5. Sensing the World Around Us 80
report erratum discuss
www.it-ebooks.info

Table of Contents

Other manuals for Arduino uno

Related product manuals