EasyManuals Logo

Arduino Pro Mini User Manual

Arduino Pro Mini
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
Page #98 background imageLoading...
Page #98 background image
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

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino Pro Mini and is the answer not in the manual?

Arduino Pro Mini Specifications

General IconGeneral
BrandArduino
ModelPro Mini
CategoryMotherboard
LanguageEnglish

Related product manuals