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. int RECV_PIN = 3; //IR receiver pin
  6. Servo servo;
  7. int val; //rotation angle
  8. bool cwRotation, ccwRotation; //the states of rotation
  9. IRrecv irrecv(RECV_PIN);
  10. decode_results results;
  11. void setup()
  12. {
  13. Serial.begin(9600);
  14. irrecv.enableIRIn(); // Start the receiver
  15. servo.attach(9); //servo pin
  16. }
  17. void loop()
  18. {
  19. if (irrecv.decode(&results)) {
  20. Serial.println(results.value, HEX);
  21. irrecv.resume(); // Receive the next value
  22. if (results.value == plus)
  23. {
  24. cwRotation = !cwRotation; //toggle the rotation value
  25. ccwRotation = false; //no rotation in this direction
  26. }
  27. if (results.value == minus)
  28. {
  29. ccwRotation = !ccwRotation; //toggle the rotation value
  30. cwRotation = false; //no rotation in this direction
  31. }
  32. }
  33. if (cwRotation && (val != 175)) {
  34. val++; //for colockwise button
  35. }
  36. if (ccwRotation && (val != 0)) {
  37. val--; //for counter colockwise button
  38. }
  39. servo.write(val);
  40. delay(20); //General speed
  41. }
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.