mova
Published

Long Range Beam Break Sensor with Reflector Panel

A cheap beam break sensor utilising a reflector panel instead of a transmitter / receiver setup. Capable of handling long distances.

IntermediateFull instructions provided2 hours27,045
Long Range Beam Break Sensor with Reflector Panel

Things used in this project

Hardware components

Arduino Pro Mini 328 - 3.3V/8MHz
SparkFun Arduino Pro Mini 328 - 3.3V/8MHz
×1
Vishay TSSP4038 IR sensor
×1
Osram SFH 4545 IR LEDs
ams OSRAM Osram SFH 4545 IR LEDs
×2
Relay Module (Generic)
×1
d-sun voltage regulator
×1

Story

Read more

Schematics

ir_sensor_schem_4yP7GDenDe.png

Code

Coding

C/C++
int LED1 = 12;
int LED2 = 13;
int button = 8;
const byte IR_LED = 11;

boolean LED1State = false;
boolean LED2State = false;

long buttonTimer = 0;
long longPressTime = 2000;

boolean buttonActive = false;
boolean longPressActive = false;

void setup() {

  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(button, INPUT);
  pinMode (IR_LED, OUTPUT);

TCCR2A = _BV (COM2A0) | _BV(WGM21);
TCCR2B = _BV (CS20);
OCR2A =  209; // ~209 = ~38kHz | ~219 = ~36kHz

}

void loop() {

  if (digitalRead(button) == HIGH) {
    
digitalWrite(LED2, HIGH);

    if (buttonActive == false) {

      buttonActive = true;
      buttonTimer = millis();

    }

    if ((millis() - buttonTimer > longPressTime) && (longPressActive == false)) {

      longPressActive = true;
      
      digitalWrite(LED1, HIGH);

    }

  } else {
    digitalWrite(LED2, LOW);
    digitalWrite(LED1, LOW);

    if (buttonActive == true) {

      if (longPressActive == true) {

        longPressActive = false;

      } else {

        LED2State = !LED2State;
        digitalWrite(LED2, LED2State);

      }

      buttonActive = false;

    }

  }

}

Credits

mova

mova

1 project • 4 followers
Thanks to Nick Gammon.

Comments