Light activated by IR when car croses beam

const int inputPin3 = 3; //IR Sensor
const int relayPin5 = 5; //Relays
const int relayPin6 = 6; 
const int relayPin7 = 7;

void setup() {
  pinMode(inputPin3, INPUT_PULLUP);
  pinMode(relayPin5, OUTPUT); 
  pinMode(relayPin6, OUTPUT); 
  pinMode(relayPin7, OUTPUT); 
  pinMode(LED_BUILTIN, OUTPUT);}

void loop() {
  int inputState = digitalRead(inputPin3);
  if (inputState == HIGH) {
    digitalWrite(relayPin5, HIGH);
    digitalWrite(relayPin6, HIGH);
    digitalWrite(relayPin6, HIGH);
    digitalWrite(LED_BUILTIN, HIGH);
  }
  else {
    digitalWrite(relayPin5, LOW);
    digitalWrite(relayPin6, LOW);
    digitalWrite(relayPin7, LOW);
    digitalWrite(LED_BUILTIN, LOW);
  }
// Turn relays on and off at 1/2 second interval.
}

My problem is getting the lights blink, I've tried different loops, Millis...

Maybe read this

https://docs.arduino.cc/tutorials/uno-rev3/Blink/

to see a simple way to blink a light.

You should be able to fit that pattern into your sketch.

Did you say what the pushbutton should do?

a7

No pushbutton, just IR tx/rx device. Thanks for your advice.

I tried the Blink approach, but no help, AI gave me so code but it didn't help.

would this work for you

const int inputPin3 = 3; //IR Sensor
const int relayPin5 = 5; //Relays
const int relayPin6 = 6;
const int relayPin7 = 7;

byte  state;

void loop ()
{
    int inputState = digitalRead (inputPin3);

    if (inputState == HIGH)
        state = HIGH;
    else 
        state = ! state;

    setPins (state);
    delay (500);
}

void
setPins (
    byte state )
{
    digitalWrite (relayPin5,   state);
    digitalWrite (relayPin6,   state);
    digitalWrite (relayPin7,   state);
    digitalWrite (LED_BUILTIN, state);
}

void setup ()
{
    pinMode (inputPin3, INPUT_PULLUP);
    pinMode (relayPin5, OUTPUT);
    pinMode (relayPin6, OUTPUT);
    pinMode (relayPin7, OUTPUT);
    pinMode (LED_BUILTIN, OUTPUT);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.