Pages: [1]   Go Down
Author Topic: Infrared proximity sensor - IR 3 pin HCSR501 or HC-SR501  (Read 410 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Spank your monkey
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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()
{
  pinMode(PIN_DETECT, INPUT);
  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
  delay(25);
}
//Sketch END


* ir_sensor.jpg (5.44 KB, 232x218 - viewed 26 times.)
Logged

Pages: [1]   Go Up
Jump to: