Controlling Fan With IR Remote Using Arduino Mega 2560

Introduction

  • In this article you will learn about how to control Fan with IR Remote using Arduino Mega 2560.
  • We can control the fan by using the remote in our place if we want to control the fan by the remote. 
Parts Of Lists
  • Arduino Mega 2560
  • IR Remote
  • Servo Motor
  • Bread Board
  • Hook Up wires 
Connection
 
Step 1
 
Connect the IR Remote to the Arduino Mega 2560
  • Connect the IR Sensor to the Arduino board Vin -3pin,
  • Connect the IR Sensor to the Arduino board Gnd - Gnd.
  • Connect the IR Sensor to the Arduino board Vcc - 5v.  
Step 2
 
Connect the ServoMotor To the Arduino Mega 2560
  • Connect the Vcc of the Servo Motor to the 5v of the ArduinoMega2560.
  • Connect the gnd of the Bluetooth to the Gnd of the ArduinoMega2560.
  • Connect the Vin of the Bluetooth to the 09 of the ArduinoMega2560.
Programming
  1. #include <IRremote.h>      //must copy IRremote library to arduino libraries  
  2. #include <Servo.h>  
  3. #define plus 0xA3C8EDDB   //clockwise rotation button  
  4. #define minus 0xF076C13B  //counter clockwise rotation button  
  5.   
  6. int RECV_PIN = 3;       //IR receiver pin  
  7. Servo servo;  
  8. int val;                //rotation angle  
  9. bool cwRotation, ccwRotation;  //the states of rotation  
  10.   
  11. IRrecv irrecv(RECV_PIN);  
  12.   
  13. decode_results results;  
  14.   
  15. void setup()  
  16. {  
  17.   Serial.begin(9600);  
  18.   irrecv.enableIRIn(); // Start the receiver  
  19.   servo.attach(9);     //servo pin  
  20. }  
  21.   
  22. void loop()   
  23. {  
  24.   if (irrecv.decode(&results)) {  
  25.     Serial.println(results.value, HEX);  
  26.     irrecv.resume(); // Receive the next value  
  27.   
  28.     if (results.value == plus)  
  29.     {  
  30.       cwRotation = !cwRotation;      //toggle the rotation value  
  31.       ccwRotation = false;         //no rotation in this direction  
  32.     }  
  33.   
  34.     if (results.value == minus)  
  35.     {  
  36.       ccwRotation = !ccwRotation;   //toggle the rotation value  
  37.       cwRotation = false;            //no rotation in this direction  
  38.     }  
  39.   }  
  40.   if (cwRotation && (val != 175))  {  
  41.     val++;                         //for colockwise button  
  42.   }  
  43.   if (ccwRotation && (val != 0))  {  
  44.     val--;                         //for counter colockwise button  
  45.   }  
  46.   servo.write(val);  
  47.   delay(20);          //General speed  
  48. }  
Explanation
  • In this article I explained about the Contolling the fan by using IR remote.
  • It can control the speed of ON/OFF and this is can be made by the Arduino Mega 2560.