Slotted LM393 Beam Infrared Light Counter Photoelectric Sensor Module
Specifications
- Dimension: 23mm x 20mm x 20mm
- Chip: LM393, Infrared head
- Working voltage: DC 5 V
Features
- It has a signal output instructions.
- Single-channel output.
- Output valid signal is low.
- Sensitivity is not adjustable.
- It can be used for work piece count, the motor speed encoder.
- Can be place between Wheel Encoder Disc to detect speed.
**Might not fit all types of chassis, may need some modification.
Sample Code
int encoder_pin = 2; // The pin the encoder is connected unsigned int rpm; // rpm reading volatile byte pulses; // number of pulses unsigned long timeold; // The number of pulses per revolution // depends on your index disc!! unsigned int pulsesperturn = 20; void counter() { //Update count pulses++; } void setup() { Serial.begin(9600); //Use statusPin to flash along with interrupts pinMode(encoder_pin, INPUT); //Interrupt 0 is digital pin 2, so that is where the IR detector is connected //Triggers on FALLING (change from HIGH to LOW) attachInterrupt(0, counter, FALLING); // Initialize pulses = 0; rpm = 0; timeold = 0; } void loop() { if (millis() - timeold >= 1000){ /*Uptade every one second, this will be equal to reading frecuency (Hz).*/ //Don't process interrupts during calculations detachInterrupt(0); //Note that this would be 60*1000/(millis() - timeold)*pulses if the interrupt //happened once per revolution rpm = (60 * 1000 / pulsesperturn )/ (millis() - timeold)* pulses; timeold = millis(); pulses = 0; //Write it out to serial port Serial.print("RPM = "); Serial.println(rpm,DEC); //Restart the interrupt processing attachInterrupt(0, counter, FALLING); } }