AG
Published

IR Remote Controlled Room Light Switch using Arduino Nano

An automated smart home project using an IR remote and a servo motor to mechanically toggle a room's light switch.

BeginnerFull instructions provided1 hour3
IR Remote Controlled Room Light Switch using Arduino Nano

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
IR remoteHX1838
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

room_ light_ control

C/C++
it’s some control for your light switch and you can turn on or off your light with the control
#include <IRremote.hpp>
#include <Servo.h>

#define IR_PIN 2

Servo servo1;
Servo servo2;

//           
#define BUTTON_1 0xBA45FF00
#define BUTTON_2 0xB946FF00

void setup() {

  Serial.begin(9600);

  IrReceiver.begin(IR_PIN);

  servo1.attach(9);


  //  
  servo1.write(0);


  Serial.println("Ready");
}

void loop() {

  if (IrReceiver.decode()) {

    unsigned long code =
      IrReceiver.decodedIRData.decodedRawData;

    Serial.print("Received: ");
    Serial.println(code, HEX);

    if (code == BUTTON_1) {

      servo1.write(26);
      

      Serial.println("Mode 1");
    }

    else if (code == BUTTON_2) {

      servo1.write(0);
    

      Serial.println("Mode 2");
    }

    IrReceiver.resume();
  }
}

Credits

AG
1 project • 0 followers
AG. 16yo Maker & Robotics Captain. Fascinated by Quantum Physics, Hardware, and C++. Building things that shouldn't just exist in theory.

Comments