Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
antiElectron
Published © CC BY

Mood Lamp with IR Remote Control

Arduino based mood lamp with IR remote control based on WS2812B.

BeginnerWork in progress2 hours3,265
Mood Lamp with IR Remote Control

Things used in this project

Hardware components

WS2812b
×1
Microchip ATMEGA 328P-PU
×1
Flora RGB Neopixel LEDs- Pack of 4
Adafruit Flora RGB Neopixel LEDs- Pack of 4
×1
ATtiny85
Microchip ATtiny85
×1
Salvaged lens from old HP scanner
×1
IR receiver (generic)
×1
IR Remote
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Flashforge Dreamer
3D Printer (generic)
3D Printer (generic)

Story

Read more

Code

Neopixel_IR

Arduino
The sketch it is fully working and support SSD1306 OLED display for debug purposes
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_NeoPixel.h>
#include "IRremote.h"

#define OLED_RESET 4
#define PIN 6

Adafruit_SSD1306 display(OLED_RESET);

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, PIN, NEO_GRB + NEO_KHZ800);


int receiver = 11;
int brt = 10;
int r = 10;
int g = 10;
int b = 10;
int n;
char brtf[4];
char rf[4];
char gf[4];
char bf[4];

unsigned long lastCode;

IRrecv irrecv(receiver);           // create instance of 'irrecv'
decode_results results;            // create instance of 'decode_results'



void setup()
{

  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3D);  // initialize with the I2C addr 0x3D (for the 128x64)
  display.clearDisplay();                     // clear OLED display
  display.setTextColor(WHITE);                // set text color
  display.display();
 
  display.setTextSize(2); 
  display.setCursor(0,0);
  display.print("BRT");
  display.setCursor(0,16);
  display.print("R");
  display.setCursor(0,32);
  display.print("G");
  display.setCursor(0,48);
  display.print("B");
  display.display();

  strip.begin();
  strip.show(); // Initialize all pixels to 'off' 
  Serial.begin(115200);
//  Serial.println("IR Receiver Raw Data + Button Decode Test");
  irrecv.enableIRIn(); // Start the receiver
}


void loop(){

  dtostrf(brt,3, 0, brtf);                                   // format to five digits with two decimals
  dtostrf(r,3, 0, rf);                                     // format to five digits with two decimals
  dtostrf(g,3, 0, gf);                                 // format to five digits with two decimals
  dtostrf(b,3, 0, bf);                                 // format to five digits with two decimals
  display.setCursor(90,0);
  display.print(brtf);
  display.setCursor(90,16);
  display.print(rf);
  display.setCursor(90,32);
  display.print(gf);
  display.setCursor(90,48);
  display.print(bf);  
  display.display();
  display.fillRect(89, 0, 128, 64, BLACK); 

    strip.setBrightness(brt);

    r;
    g;
    b; 
  for (n = 0; n < 16; n++){
 n;
       strip.setPixelColor(n, r, g, b); 
   }

   

   strip.show(); 

  if (irrecv.decode(&results))  {
 
    if(results.value != 0xFFFFFFFF){
       lastCode = results.value;
    }

 Serial.println(results.value, HEX);  //UN Comment to see raw values
    translateIR(); 
    irrecv.resume(); // receive the next value
  }
  delay(50);
}


void translateIR(){

  switch(lastCode){
    
  case 0xFF02FD:  
    brt=254;
    color();
    break;

  case 0xFFA857:  
    brt=brt-1;
     if (brt < 0){
      brt=0; 
    }
    color();
    break;

  case 0xFF629D:  
    brt=brt+1;
    if (brt > 254){
      brt=254; 
    }
    color();
    break;

       case 0xFF6897:     
    r = r + 1;
        if (r > 254){
      r=254; 
    }
        if (r < 0){
      r=0; 
    }
    color();   
    break;

       case 0xFF30CF:     
    r = r - 1;
        if (r > 254){
      r=254; 
    }
        if (r < 0){
      r=0; 
    }
    color();
    break;


       case 0xFF9867:     
    g = g + 1;
        if (g > 254){
      g=254; 
    }
        if (g < 0){
      g=0; 
    }
    color(); 
    break;


       case 0xFF18E7:     
    g = g - 1;
        if (g > 254){
      g=254; 
    }
        if (g < 0){
      g=0; 
    }
    color(); 
    break;

   
       case 0xFFB04F:     
    b = b + 1;
        if (b > 254){
      b=254; 
    }
        if (b < 0){
      b=0; 
    }
    color();  
    break;


       case 0xFF7A85:    
    b = b - 1;
        if (b > 254){
      b=254; 
    }
        if (b < 0){
      b=0; 
    }
    color();  
    break;

       case 0xFF10EF:   
    r=254;
    g=0;
    b=0;
    color();  
    break;

       case 0xFF38C7:  ;  
    r=0;
    g=254;
    b=0;
    color();  
    break;

       case 0xFF5AA5:   
    r=0;
    g=0;
    b=254;
    color();  
    break;

       case 0xFF4AB5:  
    r=254;
    g=254;
    b=254;
    color();  
    break;

}
}

void color(){

 /*   
    Serial.print("Brightness: ");Serial.println(brt);
    Serial.print("R: ");Serial.println(r);
    Serial.print("G: ");Serial.println(g);
    Serial.print("B: ");Serial.println(b);  
    */  
}

Credits

antiElectron
20 projects • 117 followers

Comments