aaravpatel0124
Published

Remote Control Light Bulb using a Relay

Controlling a high voltage light bulb using a relay module with an Arduino

IntermediateFull instructions provided17,225
Remote Control Light Bulb using a Relay

Things used in this project

Story

Read more

Schematics

Circuit

Code

Code snippet #1

Plain text
#include <IRremote.h>
int relayPin = 2;
int irPin = 7;
IRrecv irRecive(irPin);
decode_results results;

void setup() {
  Serial.begin(9600);
  irRecive.enableIRIn();
  pinMode(relayPin, OUTPUT);
}

void loop() {

  if (irRecive.decode(&results)) {

    Serial.print("Received value = ");
    Serial.println(results.value);
    Serial.print("Received code = ");
    Serial.println(results.decode_type);
    Serial.print("Received bits = ");
    Serial.println(results.bits);
    
    switch (results.value) {
      case 16754775:
        Serial.println("LIGHTS ON");
        digitalWrite(relayPin, HIGH);
        break;

      case 16769055:
        Serial.println("LIGHTS OFF");
        digitalWrite(relayPin, LOW);
        break;

      default:
        Serial.println("case: default");
        delay(1000);
    }
    
    irRecive.resume();
  }

}

Code snippet #2

Plain text
#include <IRremote.h>
int relayPin = 2;
int irPin = 7;
IRrecv irRecive(irPin);
decode_results results;

void setup() {
  Serial.begin(9600);
  irRecive.enableIRIn();
  pinMode(relayPin, OUTPUT);
}

void loop() {

  if (irRecive.decode(&results)) {

    Serial.print("Received value = ");
    Serial.println(results.value);
    Serial.print("Received code = ");
    Serial.println(results.decode_type);
    Serial.print("Received bits = ");
    Serial.println(results.bits);
    
    switch (results.value) {
      case 16754775:
        Serial.println("LIGHTS ON");
        digitalWrite(relayPin, HIGH);
        break;

      case 16769055:
        Serial.println("LIGHTS OFF");
        digitalWrite(relayPin, LOW);
        break;

      default:
        Serial.println("case: default");
        delay(1000);
    }
    
    irRecive.resume();
  }

}

Credits

aaravpatel0124

aaravpatel0124

2 projects • 2 followers

Comments