Arduino Infrared Optical Gate

by tkhareendran in Circuits > Electronics

71 Views, 1 Favorites, 0 Comments

Arduino Infrared Optical Gate

0--Optical Gate Lead.jpg

Optical gates are widely used for counting objects. An optical gate is basically an infrared emitter and receiver facing each other. If the infrared beam is not interrupted then the optical gate is open. Else it is closed. A closed optical gate means something is blocking the path between the infrared emitter and receiver.

This post is going to demonstrate how you can build an Arduino Infrared Optical Gate!

Supplies


  1. Arduino Uno x1
  2. FC-33 Infrared Slot Sensor (Photo Interrupter/Speed Sensor) Module x1
  3. 3mm/5mm LED x1
  4. 1KΩ ¼ W Resistor x
  5. 1uF/16V Electrolytic Capacitor x1

Wiring Diagram

1--Uno Optical Gate Sch_v0.png

This is the proposed wiring diagram of the Arduino Uno Infrared Optical Gate.

Arduino Sketch (Code)

[code]

#define SIGNAL_PIN 7 //LED-OUTPUT PIN

#define SENSOR_PIN 2 //SENSOR INPUT PIN

volatile byte signalState = LOW;

void setup() {

pinMode(SIGNAL_PIN, OUTPUT);

pinMode(SENSOR_PIN, INPUT_PULLUP);

attachInterrupt(digitalPinToInterrupt(SENSOR_PIN), blink, CHANGE);

}

void loop() {

}

void blink() {

signalState = !signalState;

digitalWrite(SIGNAL_PIN, signalState);

}

[/code]

Hardware & Software

2--FC-33 Module.png

The FC-33 module (at least in my case) uses the H2010 thru-beam infrared sensor (http://www.qtbright.com/static/upload/file/h2010.pdf).

This compact slot/fork sensor has an infrared light emitting diode and phototransistor which are arranged face-to-face on the optical axis within a leaded package so that external light can be blocked.

The LM393 comparator IC in the module is wired to provide a logic-high (H) output signal when an object blocks the invisible light path between the infrared light-emitting diode and the phototransistor.


Normally, the FC-33 module provides a logic-low (L) output, which is indicated by a red indicator embedded in the module.

Breadboard Prototype

3--Uno Optical Gate Bread 1.jpg

According to the current circuit configuration, Arduino Uno gives a logic-high (H) output on its D7 pin when there is an interruption in the optical gate. The LED wired to that pin also lights up with it.

Now a few lines about the interrupt based code used here…

Since we are waiting for the optical gate to send an output signal during an interruption, we can either monitor the sensor at a high frequency, or use interrupts. With interrupts, we are sure that we will not miss an event.

The monitoring for Arduino Interrupts is done by hardware. As soon as the optical gate raises a signal, the logic-high (H) hardware signal on Pin D2 triggers a function inside the Arduino code (this halts the mains execution of the program, if any, and the main execution resumes after the triggered function is done). Note the CHANGE Interrupt will be triggered when the signal changes. In Arduino Interrupts Pins are using digital pins, and only D2 and D3 pins have the interrupt functionality enabled in Arduino Uno.

For more information on Interrupts, see https://gammon.com.au/interrupts.

By physically blocking the light path of the optical gate, you can quickly simulate an interruption that the optical sensor can detect. This interruption is then translated into an electronic signal that the Arduino can interpret and act upon in your code.

The included Arduino Sketch responds to the interruptions detected by the optical gate sensor using the Arduino’s interrupt capability. Adapt and elaborate upon this experimental code to incorporate the interruptions into more luxuriant projects such as rotational speed measurement.

Conclusion

4--Uno Optical Gate Bread (1).jpg

Hopefully you all found this post interesting and useful. Try it out and have fun!