Arduino and infrared reflective sensor

Testing a infrared reflective sensor module.

I set it up with an arduino board, running the following sketch:

int sensorPin = 10;
int value = 0;
int prevval =0;
int count=0;
void setup() {
  pinMode(sensorPin,INPUT);
  Serial.begin(9600);
}
void loop() {
 value = digitalRead(sensorPin);
 if(value==0 && prevval==1){ // something is dected
   count++;
 }
 prevval=value;
 Serial.print(count);
 Serial.print("   ");
 Serial.println(value, DEC);
 delay(50);
}

To run this, connect dout on the sensor to digital pin 10 on the arduino, connect + on the sensor to 5V and – to ground.
When the infrared light is reflected back to the detector, the output goes low. The sensitivity can be adjusted using the trim pot, turning it counter-clockwise lowers the sensitivity, i.e. what passes in front must come closer or be more reflective. In addition to watching the serial monitor for changes, there is a led that lights up when something is detected.

To lower the sensitivity, turn ccw, turn cw to increase the sensitivity

Adjustments of the sensor

The sensor module is marked “auto-ctrl.com” and “LOGO-sensor Var1.5”.

This entry was posted in arduino. Bookmark the permalink.