Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Peter Wallhead
Published © GPL3+

Wireless LED Lamp with IR Remote Control

An Arduino controlled glowing orb LED lamp with IR remote control.

IntermediateShowcase (no instructions)4 hours10,659
Wireless LED Lamp with IR Remote Control

Things used in this project

Hardware components

DIY Snow Globe Kit - 108mm Diameter
×1
Wireless Charging Module 5V/1A
×1
USB cable - A/MiniB [3ft]
×1
Arduino Nano R3
Arduino Nano R3
×1
IR Remote Control Kit For Arduino
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Lamp Base STL

Lamp Base on Thingiverse

Code

Code For IR Remote Control Of Lamp

Arduino
#include <IRremote.h>

int RECV_PIN = 12;
int ledPins[] = {5, 6, 9};

IRrecv irrecv(RECV_PIN);
decode_results results;

int on = 0;
int mode = 1;
int minmode = 1;
int maxmode = 2;
int ledcolor = 0;
int minledcolor = 0;
int maxledcolor = 2;
unsigned long last = millis();

int brightness = 0;
int fadeAmount = 5;


void setup() {
  int i;
  for (i = 0; i < (sizeof(ledPins)/sizeof(int)); i = i + 1) {
    pinMode(ledPins[i], OUTPUT);
  }

  irrecv.enableIRIn();
}

void led_active_control(int led) {
  leds_off();
  digitalWrite(ledPins[led], HIGH);
}

void leds_off() {
  int i;
  for (i = 0; i < (sizeof(ledPins)/sizeof(int)); i = i + 1) {
    digitalWrite(ledPins[i], LOW);
  }
}


void loop() {
  if (irrecv.decode(&results)) {
 
    if (millis() - last > 250) {
      Serial.println(results.value, HEX);
      if(results.value == 0xFF38C7 || results.value == 0x58A310EF) {
        on = !on;
      }
      
      if(results.value == 0xFF10EF) {
        if(ledcolor > minledcolor) { 
          ledcolor -= 1;
        }
      }
      
      if(results.value == 0xFF5AA5) {
        if(ledcolor < maxledcolor) { 
          ledcolor += 1;
        }
      }

      if(results.value == 0xFF4AB5) {
        if(mode > minmode) { 
          mode -= 1;
        }
      }

      if(results.value == 0xFF18E7) {
        if(mode < maxmode) { 
          mode += 1;
        }
      }
    }
    last = millis();
    irrecv.resume();
  }
  
  if(on) {
      if(mode == 1) {
        led_active_control(ledcolor);
      } else if(mode == 2) {
        leds_off();
        
        analogWrite(ledPins[ledcolor], brightness);

        brightness = brightness + fadeAmount;

        if (brightness <= 0 || brightness >= 255) {
          fadeAmount = -fadeAmount;
        }
        delay(30);
      }
      
    } else {
      leds_off();
    }
}

Credits

Peter Wallhead
2 projects • 9 followers
Embedded systems developer, hardware hacker and tech industry enthusiast.

Comments