Arduino and Reflective Sensor KTIR0711S
A short guide showing how to connect Arduino and the bounce sensor.
The following elements are used in the example:
Connecting the sensor from Arduino:
To operate the sensor with Arduino, connect the circuit as follows:
| Sensor | Pin Arduino |
|---|---|
| GND | GND |
| OUT | A1 |
| VCC | 5 V |
Wiring diagram of the sensor from Arduino Uno.
Program for Arduino
The following code was used in the example:
int sensor = A1; //pin analogue A1 connected to sensor signal
void setup(){
Serial.begin(9600); //initialisation of a serial monitor
Serial.println("Reflective sensor test");
}
void loop(){
int odl = analogueRead (sensor); //reading value from sensor
Serial.println(odl); // display it on the monitor
delay(200); // delay between readings
}
The values read on the serial monitor decrease as you approach an obstacle. The effects of the program can be observed on the screen below:
A screenshot of the serial monitor.
