In this experiment, we will learn how to use the tracking module and avoidance module.Infrared obstacle avoidance sensor is designed for the design of a wheeled robot obstacle avoidance sensor distance adjustable. This ambient light sensor Adaptable, high precision, having a pair of infrared transmitter and receiver, transmitter tubes emit a certain frequency ofinfrared, When detecting the direction of an obstacle (reflector), the infrared receiver tube receiver is reflected back, when the indicator is lit, Through the circuit, the signal output interface output digital signal that can be detected by means of potentiometer knob to adjust the distance, the effective distance From 2 ~ 40cm, working voltage of 3.3V-5V, operating voltage range as broad, relatively large fluctuations in the power supply voltage of the situation Stable condition and still work for a variety of microcontrollers, Arduino controller, BS2 controller, attached to the robot that can sense changes in the irsurroundings.
IR light reflection switch, useful for obstacle avoidance or line following on models that move around the floor. An obstacle in front of the sender/receiver diodes will cause the ‘out’ pin to be pulled low(active low). A pot allows adjustment of the circuit’s sensitivity. The detection distance can be up to approximately 1 cm.
You can click the blue text link to download the program file to your local device, and double-click the file to open it after the download is complete. Please note: Before opening the file, ensure that you have installed the Arduino IDE development environment and completed the installation of relevant components such as the board support package and driver corresponding to the board.
int Led=5; //define LED port
int buttonpin=18; //define switch port
int val;//define digital variable val
void setup()
{
pinMode(Led,OUTPUT); //define LED as a output port
pinMode(buttonpin,INPUT);//define switch as a output port
Serial.begin(9600);
}
void loop(){ val=digitalRead(buttonpin);//read the value of the digital interface 3 assigned to val
if(val==HIGH)//when the switch sensor have signal, LED blink
{
digitalWrite(Led,HIGH);
Serial.println("HIGH!");
}
else
{
digitalWrite(Led,LOW);
Serial.println("LOW!");
}
}
This is a universal piece of code compatible with various main control boards. You only need to modify the corresponding pin definitions according to different hardware models. Note that the sensor outputs a high level by default, and switches to a low level once its probe is blocked and triggered.