Go Down

Topic: Infrared proximity sensor - IR 3 pin HCSR501 or HC-SR501 (Read 2537 times) previous topic - next topic


For some reason I was not able to find enough information and sketch that works with this device.
So I decided to put together some short test sketch that worked for me and hopefully it might help those who were looking for similar thing. Notice that no IR Remote or IR Library is required.
Values output are 0 for no activity or 1 for active.
After a few adjustments on the potentiometers with the ideal conditions on my device I noticed a slight delay and not always an immediate response to movement. Moving the sensor itself also promote activity.

//Sketch START
//Simple test sketch for IR Proximity sensor 3 pin HCSR501
//VSS, OUT, GND => 5VC, Digital pin 2, GND
//value output 0 or 1

int PIN_DETECT = 2; // digital pin
int sensorValue = 0;
void setup()
  Serial.begin(9600); //setting up serial interface

void loop() {
  sensorValue = digitalRead(PIN_DETECT); //getting values from IR sensor
  Serial.println(sensorValue);//output value to serial display
//Sketch END

Go Up