www.joy-it.net
Pascalstr. 8 47506 Neukirchen-Vluyn
2. Code example
This code reads the current status of the sensor and displays in the
console whether an obstacle is present or not. If the sensor detects an
obstacle, another LED (Sled) lights up.
int Sensor = 10; // Declaration of the sensor input pin
void setup (){
Serial.begin(9600); // Initialization serial output
pinMode (Sensor, INPUT) ; // Initialization of sensor pin
}
// The program reads the current status of the sensor pin and
// displays in the serial console whether an obstacle is currently detected
// or if there is no obstacle in front of the sensor
void loop (){
// The current signal at the sensor is read out
bool val = digitalRead (Sensor) ;
// If a signal could be detected, the LED is switched on.
if (val == HIGH){
Serial.println("No obstacle");
}
else {
Serial.println("Obstacle detected");
}
Serial.println("------------------------------------");
delay(500); // Pause between the measurement of 500ms
}
In this code example, the received data is issued on the serial
Monitor. Make sure that the baud rate is set correctly (9600).
Also make sure that you have set the right board and port in your Arduino
IDE before uploading.
You can also download the code example here.
The sensor has two potentiometers with which the sensitivity of the
receiver as well as the transmitter can be adjusted.
5. ENABLE - PIN
This sensor has an additional pin called Enable. This pin oers the
possibility to activate o to disable the sensor via a controller. By default
this is activated by means of a jumper. This means that the obstacle
detection is always performed. If you want to deactivate the permanent
detection, remove this jumper (EN) and connect the enable pin to a pin
with which a control signal can be sent.