DC FAN SPEED CONTROL WITH IR REMOTE

Fan speed IR remote

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/SPEED_CONTROL_BY_IR.zip

#include <IRremote.h>
int RECV_PIN = 3;
IRrecv irrecv(RECV_PIN);
decode_results results;
int pinLED = 5; //go to MOSFET input
int SpeedFan = 0;
void setup()
{
Serial.begin(9600);
//pinMode(OUTPUT_PIN, OUTPUT);
pinMode(13, OUTPUT);
pinMode(pinLED, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
}

int on = 0;
unsigned long last = millis();
void loop() {
SpeedFan = constrain(SpeedFan, 0, 255);
analogWrite(pinLED, SpeedFan);
Serial.println(SpeedFan);
delay(20);
if (irrecv.decode(&results)) {
if (results.value == 0xEF1020DF) { //use remote without FFFFFFFF for better
SpeedFan++;
}
else if (results.value == 0xEF10A05F) {
SpeedFan- -;
}
irrecv.resume(); // Receive the next value
}
}

//=======OTHER SKET====//setting speed saved in EEPROM====

#include <IRremote.h>
#include <EEPROM.h>
int RECV_PIN = 3;
IRrecv irrecv(RECV_PIN);
decode_results results;
int pinLED = 5; //go to MOSFET input
int SpeedFan = 0;
void setup()
{
Serial.begin(9600);
pinMode(pinLED, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
}

int on = 0;
unsigned long last = millis();
void loop() {
SpeedFan = constrain(SpeedFan, 0, 255);
if (irrecv.decode(&results)) {
if (results.value == 0xEF1020DF) {
SpeedFan++;
EEPROM.write(1, SpeedFan);
}
else if (results.value == 0xEF10A05F) { //use remote without FFFFFFFF for better
SpeedFan- -;
EEPROM.write(1, SpeedFan);
}
irrecv.resume(); // Receive the next value
}
SpeedFan = EEPROM.read(1);
analogWrite(pinLED, SpeedFan);
Serial.println(SpeedFan);
}