You are currently viewing Automatic wakeup light with ESP 32

Automatic wakeup light with ESP 32

In order to convince me to get out of bed I made myself a wakeup light that starts increasing it’s intensity by time. In the following article is described how to read out infrared commands from a remote and how to use them so send commands based on times from an ESP 32.

Parts List:

PartQtyAmazon US*Amazon DE*Banggood*
ESP321https://amzn.to/3ov5FORhttps://amzn.to/2Xd5ifBhttps://banggood.com/custlink/DGKySK2d2F
LED Strip (I used a warm white + colors one with IR Receiver + Remote + Power supply)1https://amzn.to/38eRMOMhttps://amzn.to/2XcNam5https://banggood.com/custlink/mGvRI3URko
IR Diode (sender)1https://amzn.to/397sQrVhttps://amzn.to/38ezQUuhttps://banggood.com/custlink/mvGE8K2hzT
IR Receiver1https://amzn.to/38YAUeshttps://amzn.to/3hMJCAhhttps://banggood.com/custlink/DDKY9mMy2s
Breadboard + cables (optional)1https://amzn.to/2XeUjCkhttps://amzn.to/38gnwD8https://banggood.com/custlink/KD3YSGqy73
Parts List (*contains affilate links)

In Order to make it cheaper and because I had some parts lying arround I just bought a simple LED Strip having a IR receiver and remote. For controlling the LED Strip all I needed to do now is to read out the commands with an IR Receiver and some code on the ESP32.


Read out the commands

NOTE:

Install the modified IRremote library when you are using an ESP32!

Because the ESP32 is handling IR sending (which we need later) a bit differently this modified library is needed. Withouth this only the receive part is working for the ESP32. There is not much done, just the ESP32 handling was added. It can be found here: https://github.com/SensorsIot/Definitive-Guide-to-IR/tree/master/ESP32-IRremote

More info on that can be found in this video:

credits go out to this awesome swiss guy in the video 😃

*TODO ADD WIRING SCHEMATIC*

In the pictures below I wired both sender and receiver, but at the end when you already have the Hex commands you will only need the sender

Just upload the below code snipped to your ESP32 (note this snipped comes with the IRremote library samples) and attach the IR Receiver as shown in the wiring diagram. Now when you the ESP is started up you can open the serial monitor and push some buttons on the LED remote. You should be able to see some Hex values similar to this:

0xFFE817 //LED ON
0xFF08F7 //LED 25% brightness

Note down the Hex Codes you wan to be able to send from the ESP to the LED controller.

/*
 * IRremote: IRrecvDump - dump details of IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
 * LG added by Darryl Smith (based on the JVC protocol)
 */

#include <IRremote.h>

/* 
*  Default is Arduino pin D11. 
*  You can change this to another available Arduino Pin.
*  Your IR receiver should be connected to the pin defined here
*/
int RECV_PIN = 13;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(115200);
  irrecv.enableIRIn(); // Start the receiver
}


void dump(decode_results *results) {
  // Dumps out the decode_results structure.
  // Call this after IRrecv::decode()
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
  else if (results->decode_type == NEC) {
    Serial.print("Decoded NEC: ");

  }
  else if (results->decode_type == SONY) {
    Serial.print("Decoded SONY: ");
  }
  else if (results->decode_type == RC5) {
    Serial.print("Decoded RC5: ");
  }
  else if (results->decode_type == RC6) {
    Serial.print("Decoded RC6: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->address, HEX);
    Serial.print(" Value: ");
  }
  else if (results->decode_type == LG) {
    Serial.print("Decoded LG: ");
  }
  else if (results->decode_type == JVC) {
    Serial.print("Decoded JVC: ");
  }
  else if (results->decode_type == AIWA_RC_T501) {
    Serial.print("Decoded AIWA RC T501: ");
  }
  else if (results->decode_type == WHYNTER) {
    Serial.print("Decoded Whynter: ");
  }
  Serial.print(results->value, HEX);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

  for (int i = 1; i < count; i++) {
    if (i & 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
      Serial.write('-');
      Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println();
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    dump(&results);
    irrecv.resume(); // Receive the next value
  }
}

On the next page we take care of sending the commands to the LEDs IR receiver.