An Obstacle Avoidance Sensor (as shown below) uses infrared reflection principle to detect obstacles. When there is no object in front, infrared-receiver cannot receive signals; when there is an object in front, it will block and reflect infrared light, then infrared-receiver can receive signals.
– 1 * SunFounder Uno board
– 1 * USB data cable
– 1 * Obstacle Avoidance Sensor module
– Several jumper wires
An obstacle avoidance sensor mainly consists of an infrared-transmitter, an infrared-receiver and a potentiometer. According to the reflecting character of an object, if there is no obstacle, emitted infrared ray will weaken with the propagation distance and finally disappear. If there is an obstacle, when infrared ray encounters an obstacle, it will be reflected back to the infrared-receiver. Then the infrared-receiver detects this signal and confirms an obstacle exists in front.
In this experiment, we will use an obstacle avoidance sensor module and an LED attached to pin 13 of the SunFounder board to build a simple circuit. With the LED attached to pin 13, connect pin OUT to D8 of the SunFounder board. When the obstacle avoidance sensor detects an obstacle, the LED will be on. Otherwise, it will be off.
Note: The obstacle avoidance distance of infrared sensor is adjustable; you can adjust the obstacle avoidance distance by adjusting the potentiometer.
Step 1: Build the circuit
Obstacle Avoidance Sensor module SunFounder Uno
out ————————————– D8
– —————————————- GND
+ —————————————- 5V
Step 3: Compile
Step 4: Upload the sketch to SunFounder Uno
Now, put an obstacle in front of the Obstacle Avoidance Sensor and the LED attached to pin 13 on the SunFounder Uno board will light up.
|#define ledPin 13|
#define avoidPin 8void setup()
int avoidVal = digitalRead(avoidPin);
if(avoidVal == LOW)