RGB night lamp


  • Mod

    My niece and I made a night light based on a halloween-themed candy jar. Color and brightness can be controlled by a mobile app. The app also has a "party mode".

    RGB night light controlled from mobile phone app – 00:23
    — Mikael Falkvidd

    RGB night light (esp32, BLE-controlled from mobile using Blynk) – 00:20
    — Mikael Falkvidd

    The app looks like this:
    Kalle Blynk_cropped.png

    Hardware-wise, we used:

    • plastic skull with candy (eating the candy was a tough job, but someone had to do it)
    • esp32
    • rgb led strip
    • capacitor

    Kalle esp32.JPG

    We put some fluffy cotton inside the skull to diffuse the light.

    Sketch:

    #include <FastLED.h>
    #define NUM_LEDS 60
    #define DATA_PIN 13
    CRGB leds[NUM_LEDS];
    
    // Blynk
    #define BLYNK_PRINT Serial
    #define BLYNK_USE_DIRECT_CONNECT
    //#define BLYNK_DEBUG
    #include <BlynkSimpleEsp32_BLE.h>
    #include <BLEDevice.h>
    #include <BLEServer.h>
    char auth[] = "YOUR-BLYNK-AUTH-HERE";
    
    byte mode = 0;
    byte r = 0;
    byte g = 0;
    byte b = 0;
    void setup() {
      Serial.begin(115200);
      Serial.println("Started");
      delay(2000); // sanity check delay - allows reprogramming if accidently blowing power w/leds
      FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
      Serial.println("Started");
      Blynk.setDeviceName("NIGHT_LIGHT");
      Serial.print("Blynk token: ");
      Serial.println(auth);
      Blynk.begin(auth);
    }
    
    void loop() {
      switch (mode) {
        case 0:
          FastLED[0].showColor(CRGB(r, g, b), NUM_LEDS, 255);
          break;
        case 1:
          pride();
          break;
      }
      FastLED.show();
      Blynk.run();
    }
    
    BLYNK_WRITE(V1) // zeRGBa assigned to V1
    {
      // get a RED channel value
      r = param[0].asInt();
      // get a GREEN channel value
      g = param[1].asInt();
      // get a BLUE channel value
      b = param[2].asInt();
    #ifdef DEBUG
      Serial.print("RGB: ");
      Serial.print(r);
      Serial.print(",");
      Serial.print(g);
      Serial.print(",");
      Serial.print(b);
    #endif
    
    }
    BLYNK_WRITE(V0) // On/off
    {
      mode = param.asInt();
      FastLED.clear();
    }
    void pride()
    {
      static uint16_t sPseudotime = 0;
      static uint16_t sLastMillis = 0;
      static uint16_t sHue16 = 0;
    
      uint8_t sat8 = beatsin88( 87, 220, 250);
      uint8_t brightdepth = beatsin88( 341, 96, 224);
      uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
      uint8_t msmultiplier = beatsin88(147, 23, 60);
    
      uint16_t hue16 = sHue16;//gHue * 256;
      uint16_t hueinc16 = beatsin88(113, 1, 3000);
    
      uint16_t ms = millis();
      uint16_t deltams = ms - sLastMillis ;
      sLastMillis  = ms;
      sPseudotime += deltams * msmultiplier;
      sHue16 += deltams * beatsin88( 400, 5, 9);
      uint16_t brightnesstheta16 = sPseudotime;
    
      for ( uint16_t i = 0 ; i < NUM_LEDS; i++) {
        hue16 += hueinc16;
        uint8_t hue8 = hue16 / 256;
    
        brightnesstheta16  += brightnessthetainc16;
        uint16_t b16 = sin16( brightnesstheta16  ) + 32768;
    
        uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
        uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
        bri8 += (255 - brightdepth);
    
        CRGB newcolor = CHSV( hue8, sat8, bri8);
    
        uint16_t pixelnumber = i;
        pixelnumber = (NUM_LEDS - 1) - pixelnumber;
    
        nblend( leds[pixelnumber], newcolor, 64);
      }
    }
    

  • Contest Winner

    Looks awesome. Might be fun to put it outside before your front door on 31th October. Still have a Halloween project on my ever growing bucketlist xd

    Blynk is awesome for controlling Halloween projects.


Log in to reply
 

Suggested Topics

  • 5
  • 2
  • 10
  • 8
  • 1
  • 40
  • 2
  • 1

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts