Hardware Reference
In-Depth Information
Accessing the IR sensor from the Arduino
IDE
Now, bring up the Arduino IDE. Here is a simple sketch that provides access to the sensor
and returns the distance to the object via the serial link:
The sketch is quite simple. The three global variables at the top set the input pin to A3 and
provide a storage location for the input value and distance. The setup() function simply
sets the serial port baud rate to 9600 and prints out a single line to the serial port.
In the loop() function, you first get the value from the A3 input port. The next step is to
convert it to a distance based on the voltage. To do this, you need to use the voltage to dis-
tance chart for the device; in this case, it is similar to the following diagram:
Search WWH ::




Custom Search