IR remote and motor problem

Hello.
I am building a ventilator with a motor and I use a remote control to turn it on/off and vary intensity.
The code is pretty simple but whenever I press the first button I cannot press another one (for instance to change intensity or to turn it off). Here is the code:

#include <IRremote.h>

#define ENABLE 4
#define DIRA 5

int receiver = 11;
int gLed = 3;
int yLed = 6;
int rLed = 9;
int piezoPin = 8;
int button = 12;
int i;

IRrecv irrecv(receiver);
decode_results results;

void piezo() {
digitalWrite(piezoPin, HIGH);
delay(10);
digitalWrite(piezoPin, LOW);
}

void piezoOff() {
digitalWrite(piezoPin, HIGH);
delay(10);
digitalWrite(piezoPin, LOW);
delay(10);
digitalWrite(piezoPin, HIGH);
delay(10);
digitalWrite(piezoPin, LOW);
}

void setup() {
irrecv.enableIRIn();
pinMode(gLed, OUTPUT);
pinMode(yLed, OUTPUT);
pinMode(rLed, OUTPUT);
digitalWrite(gLed, LOW);
digitalWrite(yLed, LOW);
digitalWrite(rLed, LOW);
pinMode(piezoPin, OUTPUT);
pinMode(ENABLE, OUTPUT);
pinMode(DIRA, OUTPUT);
pinMode(button, INPUT_PULLUP);
}

void translateIR()
{
switch(results.value)
{
case 0xFF30CF: {
digitalWrite(gLed, HIGH);
digitalWrite(yLed, LOW);
digitalWrite(rLed, LOW);
piezo();
digitalWrite(ENABLE, LOW);
digitalWrite(DIRA, LOW);
delay(10);
analogWrite(ENABLE, 100);
digitalWrite(DIRA, HIGH);
break;
}
case 0xFF18E7: {
digitalWrite(gLed, LOW);
digitalWrite(yLed, HIGH);
digitalWrite(rLed, LOW);
piezo();
digitalWrite(ENABLE, LOW);
digitalWrite(DIRA, LOW);
delay(10);
analogWrite(ENABLE, 200);
digitalWrite(DIRA, HIGH);
break;
}
case 0xFF7A85: {
digitalWrite(gLed, LOW);
digitalWrite(yLed, LOW);
digitalWrite(rLed, HIGH);
piezo();
digitalWrite(ENABLE, LOW);
digitalWrite(DIRA, LOW);
delay(10);
analogWrite(ENABLE, 250);
digitalWrite(DIRA, HIGH);
break;
}
case 0xFFA25D: {
digitalWrite(gLed, LOW);
digitalWrite(yLed, LOW);
digitalWrite(rLed, LOW);
digitalWrite(ENABLE, LOW);
digitalWrite(DIRA, LOW);
piezoOff();
break;
}
}
}

void loop() {
if(irrecv.decode(&results))
{
translateIR();
irrecv.resume();
}
}

Please post your code properly.

What kind of motor?
Can you provide a wiring diagram?

use Serial.println () to verify the codes being received

What version of the IRremote library are you using? If the newest version, did you see this warning?

warning: 'bool IRrecv::decode(decode_results*)' is deprecated: Please use IrReceiver.decode() without a parameter and IrReceiver.decodedIRData. .

You can either change your code to work with the new version of the library, following the instructions from here or you can delete the new version of the IRremote library from your sketchbook/libraries folder and install an older version (2.x.x) and keep the code the way that it is. The older versions are available for install from the IDE library manager.

If you enable the serial port, the same warning will be printed to serial monitor when the first IR code is received from a remote.

Thanks for your help. I have already solved the coding problems.

Please share the solution so that, in the future, members that come across this thread can benefit from it.

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