Arduino Mega 2560

Optical gates are basicly an infra LED and photo sensor facing eachother. If infrawave is sensed then the optical gate is open. It is closed otherwise. If everything functions normally a closed optical gate means something is blocking the space between the infra LED and photo sensor. They are widely used for counting objects.

arduino mega modul with optical gate
Figure 1 - Arduino Mega modul with optical gate

Required hardware

  • Arduino Mega 2560
  • Optical gate
  • Resistors: 100Ω, 100kΩ

Source code to install on controller


Before you upload this code to your Arduino, please format the EEPROM...
#include <OzOpticalGateController.h>
#include <OzIDManager.h>

// global pointers
OzIDManager* manager;
OzOpticalGateController* opticalGate;

uint8_t _ledPin = 3;
uint8_t _photoPin = 2;


void setup()
{
  Serial.begin(115200);

  manager = new OzIDManager;
  manager->_sendACK = true;
  manager->_checksum = true;
  
  OzCommunication::setIDManager(manager);

  opticalGate = new OzOpticalGateController(_ledPin, _photoPin);

  int x=1;
  manager->sendLinkSetup();
  manager->PrintWelcomeLine(opticalGate, x++, "MyOpticalGate");
}

void loop()
{
    OzCommunication::communicate();
    opticalGate->ownLoop();
}