hello i quite new to this i recently want to use a ir remote for an automated curtain rail and using a code i found online but the IR receiver didnt detect anything an error message came when compling it IRrecv: :decode(decode_results) i dont know what to do. can anyone explain to me what the problem is
#include <IRremote.h>
#include <DS3231.h>
#include <LiquidCrystal.h>
#include <Stepper.h>
#include <EEPROM.h>
const long int OpenCurtain = 0xFF02FD; //button for opening the curtain
const long int CloseCurtain = 0xFF22DD; //button for closing the curtain
const long int OpenAlarmScreen = 0xFF906F; //button for opening the alarm screen to be able to set the alarm
const long int EnterButton = 0xFFC23D; //button for confirming the value written in the alarm screen
const long int add1 = 0xFFA857; //button to add 1 to the number displayed in the alarm screen
const long int subtract1 = 0xFFE01F; //button to subtract 1 from the number displayed in the alarm screen
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
int curtainDistance = 1000; //IMPORTANT: whatever value you write here, will decide how far your curtains open, so be VERY careful not to put
//a very high value in, as the curtains might open too much and you DEFINITELY don't want that. Better start of with a small value.
//Uncomment the following lines (the curtainTogglestate ones) and then upload the code. Make sure that your curtains are closed.
//After you've uploaded the code,
//the arduino will save these values to its EEPROM and update them whenever you open or close the curtains. It's very important
//to comment these lines back after you've uploaded the code. You do this by adding // in front of your line like I've done on this line.
//int curtainTogglestate = 0; //the curtains are closed
//int curtainTogglestate2 = 1; //the curtains are closed
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 7, 8, 9, 11);
int stepCount = 0; // number of steps the motor has taken
byte alarm[8] = {
B00000,
B00100,
B01110,
B01110,
B01110,
B11111,
B00100,
B00000,
};
DS3231 rtc(SDA, SCL);
LiquidCrystal lcd(3, 4, 5, 6, 12, 13); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
const int RECV_PIN = 2;
bool AlarmClock = false;
// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;
Time t;
int OnHour = 9; //these are the values for your alarm, but don't worry, these are just default values. You'll set your alarm using the remote.
int OnMin = 00; //(24 HOUR FORMAT)
int Enter = 0;
int state = 0;
int address = 0;
int address2 = 1;
void setup(){
// Enable the IR Receiver
irrecv.enableIRIn();
rtc.begin(); // Initialize the rtc object
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }
lcd.createChar(7, alarm);
//The following lines can be uncommented to set the date and time. You have to do this once, upload and then comment them back again
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(22, 13, 00); // Set the time to 22:13:00 (24hr format)
//rtc.setDate(5, 8, 2020); // Set the date to August 5th, 2020
myStepper.setSpeed(300); //set the speed of the stepper motor to 300. You can change this value. For me, 300 was about the maximum value
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(11,LOW);
lcd.display();
Serial.begin(9600); //If your lcd is acting weird, comment this line because it might help. This line is only necessary for reading the IR transmitter codes
}
void loop(){
int curtainTogglestate = EEPROM.read(address); //read the curtainTogglestate from the EEPROM. It checks whether the curtains are closed or opened.
int curtainTogglestate2 = EEPROM.read(address2);
lcd.setCursor(0,0);
lcd.print("Time: ");
lcd.print(rtc.getTimeStr());
lcd.setCursor(0,1);
if(AlarmClock == true){
lcd.write(7);
}
lcd.setCursor(6,1);
lcd.print(rtc.getDateStr());
t = rtc.getTime();
if(t.hour == OnHour && t.min == OnMin && AlarmClock == true){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("WAKE UP, LAZY!");
if(curtainTogglestate==0 && curtainTogglestate2==1){
curtainTogglestate=1;
curtainTogglestate2=0;
while(stepCount < curtainDistance) {
myStepper.step(stepsPerRevolution / 100);
stepCount++;
}
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(11,LOW);
delay(1000);
stepCount = 0;
AlarmClock = false;
}
lcd.clear();
}
if (irrecv.decode(&results)){
// Print Code in HEX
Serial.println(results.value, HEX); //this line is only necessary for reading the IR transmitter codes (in the Serial monitor). You can comment it afterwards
switch(results.value){
case OpenCurtain:
if(curtainTogglestate==0 && curtainTogglestate2==1){
curtainTogglestate=1;
curtainTogglestate2=0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("curtain open");
while(stepCount < curtainDistance) {
myStepper.step(stepsPerRevolution / 100);
stepCount++;
}
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(11,LOW);
delay(1000);
stepCount = 0;
lcd.clear();
}
break;
case CloseCurtain:
if(curtainTogglestate==1 && curtainTogglestate2==0){
curtainTogglestate=0;
curtainTogglestate2=1;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("curtain close");
while(stepCount < curtainDistance) {
myStepper.step(-stepsPerRevolution / 100);
stepCount++;
}
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(11,LOW);
delay(1000);
stepCount = 0;
lcd.clear();
}
break;
case OpenAlarmScreen:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Alarm: ");
lcd.setCursor(7,0);
lcd.print(OnHour);
lcd.print(":");
lcd.print(OnMin);
lcd.setCursor(7,0);
lcd.blink();
do {
if (irrecv.decode(&results)){
switch(results.value){
case EnterButton:
Enter = 1;
lcd.setCursor(10,0);
break;
case add1:
OnHour = OnHour + 1;
lcd.setCursor(0,0);
lcd.print("Alarm: ");
lcd.setCursor(7,0);
lcd.print(OnHour);
lcd.print(":");
lcd.print(OnMin);
lcd.setCursor(7,0);
lcd.blink();
break;
case subtract1:
OnHour = OnHour - 1;
lcd.setCursor(0,0);
lcd.print("Alarm: ");
lcd.setCursor(7,0);
lcd.print(OnHour);
lcd.print(":");
lcd.print(OnMin);
lcd.setCursor(7,0);
lcd.blink();
break;
}
irrecv.resume();
}
} while(Enter == 0);
while(Enter == 1) {
if (irrecv.decode(&results)){
switch(results.value){
case EnterButton:
Enter = 2;
AlarmClock = true;
break;
case add1:
OnMin = OnMin + 1;
lcd.setCursor(0,0);
lcd.print("Alarm: ");
lcd.setCursor(7,0);
lcd.print(OnHour);
lcd.print(":");
lcd.print(OnMin);
lcd.setCursor(10,0);
lcd.blink();
break;
case subtract1:
OnMin = OnMin - 1;
lcd.setCursor(0,0);
lcd.print("Alarm: ");
lcd.setCursor(7,0);
lcd.print(OnHour);
lcd.print(":");
lcd.print(OnMin);
lcd.setCursor(10,0);
lcd.blink();
break;
}
irrecv.resume();
}
}
Enter = 0;
break;
}
irrecv.resume();
}
EEPROM.update(address, curtainTogglestate);
EEPROM.update(address2, curtainTogglestate2);
}