Go Down

Topic: Arduino Nano and 2 of HALJIA E18-D80NK Infrared Obstacle Avoidance Sensor (Read 44 times) previous topic - next topic

n_paraskeva

Hello, Arduino community, i am a beginner in Arduino but i already fell in love with the community and the potentials.
I have some background in VBA programming but that's it.
I hope i can find some support and pass it in the future to the next beginners.

I am currently working in a project which uses 2 of HALJIA E18-D80NK Infrared Obstacle Avoidance Sensor and a small Arduino nano with a buzzer,
I want to make a small code module which when the first Ir sensor is triggered if i don't get the second one trigger in a specific period of time, then i would like to activate the buzzer if the second sensor is triggered then the whole thing is reset.
In the future, i want to connect a monitor which counts the times that the 2 sensors are triggered.
(the first and then the second sensor is considered 1 trigger).

=>currently i have some issues with the triggering of the alarm,
i try to use mills due to the fact that i want to monitor the second sensor for a period of time.

Any advice will be welcome, apologise for my mistakes and ignorance in advance.


Until now i have this:

int ledPin = 8;                // choose the pin for the LED
int inputPin2 = 2;               // choose the input pin (for PIR sensor)
int inputPin3 = 3;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val2 = 0;                    // variable for reading the pin status
int val3 = 0;                    // variable for reading the pin status
 
void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin2, INPUT);     // declare sensor as input
  pinMode(inputPin3, INPUT);     // declare sensor as input 
 
  Serial.begin(9600);
}
void loop(){
  val2 = digitalRead(inputPin2);  // read input value
  val3 = digitalRead(inputPin3);  // read input value
  if (val2 == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("pin 2 Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  }
  else if (val3 == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("pin 3 Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } 
  else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}

Go Up