Need some help with my project.


Not sure if I am approach this right. Here is my problem:

I have 2 sensors that detects objects in front of it. If both sensors detect something turn on LED.
LED have to be on as long as sensors 1 detect an object. And LED can turn off if sensor 1 senses no object for x seconds. I hope some of you have the time to help me out. My arduino skills is at lvl 1 so be nice :stuck_out_tongue:

// IR Obstacle Detection 

#include <Servo.h>
Servo myservo;  // create servo object to control a servo
int pos = 0;    // variable to store the servo position
long previousMillis = 0;  
unsigned long currentMillis = 0;
const int greenLedpin = 13;

int greenLedState =  HIGH; //ledstate for green LED
int isObstaclePin1 = 7;  // This is input pin1
int isObstaclePin2 = 6;  // This is input pin2
int isObstacle1 = HIGH;  // HIGH MEANS NO OBSTACLE
int isObstacle2 = HIGH;  // HIGH MEANS NO OBSTACLE
long previousMillisGreen = 0; // last tim egreen LED was updated
long greenLedInterval = 5000; //interval timer

void setup() {
  pinMode(greenLedpin, OUTPUT);
  pinMode(isObstaclePin1, INPUT);
  pinMode(isObstaclePin2, INPUT);

void loop() {
   //captuer the current time
    currentMillis = millis();
  isObstacle1 = digitalRead(isObstaclePin1);
  isObstacle2 = digitalRead(isObstaclePin2);
   if (isObstacle1 == LOW && isObstacle2 == LOW){
        Serial.println("OBSTACLE!!, OBSTACLE!!");
    digitalWrite(greenLedpin, HIGH);
  else if(isObstacle1 == HIGH  &&currentMillis - previousMillisGreen > greenLedInterval){
    previousMillisGreen = currentMillis;
    digitalWrite(greenLedpin, LOW);

I haven’t verified the code. Do you face any issue with the code? If then explain the issue.