Hello guys. I designed a system for my room lamp with relay module.
There's a LDR and PIR sensor for automatic mode. I've a IR remote control and it will be the main control unit. I'm controlling the system with this remote control.
There's 3 command. "ON" "OFF" and "AUTOMATIC MOD".
My problem is this : When I change the mods I want to create a buzzer beep in my program to give information for me. But in if statements, it's beeping forever. I just want to make a beep sound once, without stopping the main loop. "ON" "OFF" or "AUTOMATIC MODE" should continue after beeping. How can I do this ? Thank you.
Here is my all code :
#include "IRremote.h"
int LDR = A0;
byte sensor = 11;
byte bulb = 12;
int val = 0;
int val2 = 0;
int RCV_PIN = 10;
IRrecv irrecv(RCV_PIN);
decode_results results;
void setup()
{
pinMode(sensor,INPUT);
pinMode(bulb,OUTPUT);
digitalWrite(bulb, HIGH); //rölenin başlangıç durumu
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
val=analogRead(LDR);
val = map(val,0,1024,0,100);
if (irrecv.decode(&results)) { // have we received an IR signal?
irrecv.resume(); // receive the next value
delay (500);
}
if (results.value == 0xFFE21D) {
digitalWrite(bulb,LOW);
Serial.println("ANA KUMANDA: sistem acik");
}
if (results.value == 0xFFA25D){
digitalWrite(bulb,HIGH);
Serial.println("ANA KUMANDA: sistem kapali");
}
if (results.value == 0xFF629D) {
Serial.println("ANA KUMANDA: sistem otomatik modda");
if (results.value !=0xFF629D){
if (digitalRead(sensor) == HIGH && val<=50 ) {
Serial.println("Hareket belirlendi !");
digitalWrite(bulb,LOW);
delay(1000);
}
else if (digitalRead(sensor) == LOW || val>50 ){
digitalWrite(bulb,HIGH);
}
}
else
if (digitalRead(sensor) == HIGH && val<=50 ) {
Serial.println("Hareket belirlendi !");
digitalWrite(bulb,LOW);
delay(1000);
}
else if (digitalRead(sensor) == LOW || val>50 ){
digitalWrite(bulb,HIGH);
}
}
}
versiyon4.ino (1.37 KB)