ESP32-based Lamp With Beautiful Effects and Cloud Management
by too_smart in Circuits > LEDs
489 Views, 4 Favorites, 0 Comments
ESP32-based Lamp With Beautiful Effects and Cloud Management
Hi everybody, my name is Kostia, and I lead the development team of the 2Smart Cloud IoT platform. When preparing the platform for release to the public, we tested its mechanics from the point of view of ordinary users, for which we realized various ideas for smart devices. In this article, I'll tell you how we built our version of the popular open-source project Gyver Lamp and share everything Instructables users need to build a similar device.
First of all, I want to thank the creators of the original effects lamp project. After which, I want to describe what changes our team made to that project to improve it:
- using a more modern and advanced ESP32 microcontroller instead of ESP8266,
- designing a compact printed circuit board for the chosen microcontroller,
- adding a touch button to control the lamp,
- implementation of a Reset button on the board under a technical hole in the case,
- connecting the device to the free modern mobile application 2Smart Cloud with the ability to fully remote control and many convenient user features.
You can see what you will end up with if you follow the instructions below here: https://www.youtube.com/watch?v=AaLOyuaB4uc
Of course, you won’t have to pay anything for using the MQTT broker and the 2Smart Cloud mobile application, don’t worry about it) Unless you plan to connect commercial batches of devices, everything will be ok.
So, let's go!
Supplies
- Esp32 devkit – 1.
- Matrix of addressable LEDs 16x16 – 1.
- Micro USB connector MC-215 – 1.
- Power supply + cable.
- Touch button – 1.
- Clock button – 1.
- PLA plastic for making a case on a 3D printer ~0.2kg.
- MicroUSB connector PCB – 1.
- Wires 27cm long – 3 multi-colored.
- Small screw – 2.
- Large screw – 2.
- Plastic clamps – 3.
PCB Design
You can use the PCB layout we developed, which is available as a Gerber file in this project's GitHub, and order board production from local manufacturers or services like https://jlcpcb.com/.
Case Production
While the PCB is being made, you can start making the case for the lamp. Use our case design or one of the ready-made designs on the Thingiverse website or other sources, or create your own if you have 3D design skills.
Please note that our PCB design includes a Reset button, which must be accessed on the bottom of the case via a hole. If you use your own custom case design, be sure to include this hole or drill it when the board is ready!
Flashing the Microcontroller
We recommend installing the firmware on the microcontroller before you begin soldering parts to the PCB. You can find the ready-made firmware for the lamp in the 2Smart GitHub. You have two options on what to do with this firmware:
- Use as is. This is the easiest way when your lamp will be another instance of the product we have developed. The advantage of this choice is that you don't have to make any changes to the firmware code; you may not even know anything about how to program. The disadvantage of this method is that you will get the same lamp effects that we decided to add to the project. No experiments with your effects will be available to you.
- Modify the firmware for yourself. In this case, you will have to make small changes so that the lamp is registered in the cloud MQTT broker of the 2Smart Cloud platform as your device. But you will not be limited in the range of effects and can implement any of your ideas or use other people’s ideas from the net.
If you choose the second option, I will leave here a link to instructions on how to modify the firmware to publish the device on your behalf, as well as add new effects. Although the instructions describe adding effects for the LED strip, the firmware there is similar to that installed on the lamp.
Below, I will describe the flow of working with the first option, when you take the firmware as is and do not change anything in its code.
To install the lamp firmware on the microcontroller, use Plarformio or Esptool.
How to install firmware using Platformio
Go to your project folder, and then go to the firmware folder. In this folder, open a command prompt.
1 - Need have:
- python (>= v3) installed. You can control it in the terminal
python --version
- platformio (>= v5.1.1)
pip install -U platformio
2 - Have connected the MCU to your computer.
3 - Device should be listed in /dev as one of these:
(Linux)
/dev/ttyUSB0
(OSX)
/dev/cu.SLAB_USBtoUART
/dev/cu.usbserial-0001
4 - Build and write
pio run -t uploadfs
pio run -t upload
5 - If everything is okay it should start in AP mode and blink once in a second.
If you want, just build
pio run
CLI guide https://docs.platformio.org/en/latest/core/userguide/index.html
How to install firmware using esptool
- Install the latest version of esptool.
- Connect esp32 to your computer. WARNING - DO NOT connect usb when led strip or matrix is connected.
- Open the Firmware folder.
- Upload the firmware using next commands:
esptool.py --chip esp32 --port "/dev/ttyUSB0" --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_size detect 2686976 spiffs.bin
esptool.py --chip esp32 --port "/dev/ttyUSB0" --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader_dio_40m.bin 0x8000 partitions.bin 0xe000 boot_app0.bin 0x10000 firmware.bin
If everything is okay it should start in AP mode and blink once in a second.
Change the --port argument according to your OS.
Assembling the Device
So, you have a ready-made printed circuit board, a case for the lamp, a flashed microcontroller, and all the necessary components and tools. It's great! Let's assemble the lamp so we can finally turn it on and start using it!
- Prepare the touch button - unsolder the diode (if we don’t want it to glow) and put a jumper on the A pad.
- Solder three wires to the touch button.
- Unsolder all wires from the matrix except for the DIN connector.
- Solder the DOUT connector soldered from the matrix to the inner side of the board.
- Solder the reset clock button to the back of the board.
- Solder the Micro-USB input to the inner side of the board.
- Solder ESP32 to the inside of the board.
- Connect through the soldered micro-USB power supply and check that the matrix works.
- Pass the wires of the touch button through the hole in the tube and solder to the board, the signal wire directly to pin D19.
- Install the assembled controller in the seat in the lower part of the case.
- Install the inner tube.
- Put on and fix the matrix using zip ties. The matrix strips should be placed horizontally.
- Lay the wires.
- Put the lid on the inner tube without pressing tightly. If the lamp switches modes on its own after assembly, the lid should be slightly raised.
- Close everything with an external case and turn on the power.
Pairing the Lamp With the Mobile Application
Now, all you have to do is pair your lamp with a mobile app to control it remotely, including using Siri/Google Assistant voice commands and more.
- Connect the lamp to a power source.
- Install the 2Smart Cloud mobile application (iOS / Android) on your smartphone or tablet and sign up.
- Click the “Add new device” button on the “Devices” screen.
- Find "2Smart Lamp" in the device list.
- Press "Start Pairing" and then "Continue".
- Open Wi-Fi settings and enter the credentials for your 2.4 GHz Wi-Fi.
- Connect to the 2Smart Lamp Wi-Fi hotspot and press "Complete the pairing".
- Enjoy the magic!