From Flashlight to MQTT with ESP8266

Internet of Things with this Flashlight?

Not really, the idea is the LED light can be powered by any power bank. And the flashlight or small LED is also connected to Internet to turn on/off remotely. The flashlight is not best candiate for this approach, but this may be suitable for USB adapter laying around. You can you plug a small LED to USB port and light up temperary.

But first, yes, I used that buzzword, aka IOTs, but this one could make a good combination of using the circuit in Step 2 with an ESP8266 and then control the light intensity by MQTT method.

Three components for IOT system are:

  • A subscriber: in this case the LED light acts as a client
  • A publisher: we will work on a dash control later
  • and a MQTT server or a broker: A Raspberry Pi is the best use for this. Think the broker as the exchange floor.

We need to add some parts as well:

  • Replace 12V boost up by MT3608 boost up board, $1.92/5pcs, this one can boost the voltage of a 18650 battery (about 3.7V) to 28 V, enough to power 8LEDs (instead of 3).
  • The default or "un-push" position in the switch is connected to the GPIO 1 or 2 in the ESP8266 for PWM signal.
  • ESP8266 01, $1.68 each. Like this one
  • AMS1117 3.3 V, a voltage regulator for ESP8266, some capacitors
  • A USB module to flash ESP8266, $0.78/pcs like $1.92/5pcs this one
Links are for reference.
Let put things together

The limiting current circuit is identical to the previous one for a flashlight. We added a ESP8266 to send a Pulse-Width Modulation (PWM) signal to the Gate of the MOSFET when the switch is in default mode. If the switch is pushed, the Gate is pulled up, and the light is turned on. Small LED attached GPIO 0 as the indicator of the PWM signal.

flashlight v.2
A slightly different than the flashlight. Using MT3608 could boost up the voltage close to 28V, enough for 8 LEDs in series.
Solder the Parts and Upload the Code
  • Soldering parts together, and use the schematics above. Some pre-made 3.3 voltage circuit may save you some time ( $1.38/5pcs like this). I was confused to remember the pin when flipping the PCB board and ended up satisfy some AMS1117 voltage regulator.
  • 8 leds
    After soldering on PCB
  • Download the code here from the GitHub, and upload the code to ESP 8266 using Arduino IDE.
  • Upload code to ESP8266 -01. A small note: ESP8266-01 is a small factor with 8 pins version of ESP8266 that have two pins (GPIO 0 2) for general purposes, but uploading a code to the chip is not as easy with other verison of ESP8266 such as Wemos.
    1. Plug the USB module for ESP8266 to your computer, make a small modification by soldering GPIO 0 to GND.
    2. Select the right port, ESP8266 (512kB or 512+512)
    3. quickly tap the RST Pin with GND pin to put the ESP8266 into Flashmode
    Upload code to ESP8266 -01.

    I highlighted the line to show the topic that the subscriber subscribed to. Any message posted to this topic will be passed along to other clients (subscribers) to this topic. The EPS8266 in this circuit will listen to the JSON message posted to the topic and sparse out if a change was made in channel Three.

    change topic
    Change the topic as you wish.
    json stream
    Extract intensity from JSON stream.