This repository contains the software, schematics, and 3D printing files for a bedside lamp. The software includes various modes that can be toggled using a button. Additionally, there is a distance sensor (VL53L0X
) that enables features such as adjusting the lamp's brightness with a hand gesture.
This is a beta version of the project. The software is still under development, and the hardware may require some adjustments. I cannot guarantee that the project will work as expected and will not be responsible for any damage caused by the project.
This is an overview of the different modes available in the lamp. The modes can be toggled using the button.
- DUBEUYEW ESP32-C3 Development Board Mini
- VL53L0X distance sensor
- Simple push button (hight ≥ 6mm)
- WS2812B 5V LED strip (11 LEDs)
- External 5V power supply
- USB-C and some other necessary cables
- 3x M3 threaded insert
- 3x M3 screws
- 3D printer + filament (white and a color of your choice)
- Soldering iron + solder
- 2x Heat shrink tube
- Screwdriver
You can find the 3D models in the
/printing
folder. The models are designed to be 3D printed and assembled. The lamp consists of three parts: the base, the lampshade, and the lampshade holder.
The components are connected to the ESP32C3 using the following diagram:
The Button does not require a resistor, as the ESP32C3 has internal pull-up resistors.
This table also shows the connections:
Component | Pin | ESP32C3 Pin |
---|---|---|
Button | 1 | GND |
2 | GPIO 4 | |
VL53L0X | VCC | 5V |
GND | GND | |
SDA | GPIO 6 | |
SCL | GPIO 7 | |
WS2812B | VCC | 5V |
GND | GND | |
DI | GPIO 3 |
The
VL53L0X
is the distance sensor, theWS2812B
is the LED strip, and theButton
is the push button.
To attach the lampshade to the base, a threaded insert is used. The insert is placed in the base, and the lampshade is screwed onto it.
This is a PlatformIO project. To compile and flash the software to the ESP32C3, PlatformIO must be installed. Once installed, you can open the project in PlatformIO and flash the software onto the ESP32C3.
Alternatively, a Makefile
is included, allowing you to flash the software via the command line. For this, PlatformIO must be installed, and the PLATFORMIO
environment variable should point to the PlatformIO executable.
If you're familiar with Nix-shell, you can use the shell.nix
file to set up the environment for PlatformIO.
pio run
: Compiles the softwarepio run --target upload
: Flashes the software to the ESP32C3pio run --target clean
: Removes compiled filespio device monitor
: Opens a terminal to view the ESP32C3 output
make
: Compiles the softwaremake upload
: Flashes the software to the ESP32C3make clean
: Removes compiled filesmake monitor
: Opens a terminal to view the ESP32C3 outputmake flash
: Flashes the software and opens the monitormake start
: Cleans, compiles, flashes the software, and opens the monitor
ArrayList
for dynamic arraysButton2
for button input handlingAdafruit_VL53L0X
for the distance sensorFastLED
for LED control
For more details on the libraries, refer to the platformio.ini
file.
The software is written in C++ and is structured as a typical PlatformIO project. The main file is src/main.cpp
, which contains the setup and loop functions. The different modes, services and the controller are implemented in separate files in the /lib
folder.
Every Mode is a class that inherits from the AbstractMode
class. The abstract class already implements the basic functions that every mode should have. In every mode, the following functions must be implemented: setup
, customFirst
, customLoop
, last
, and customClick
.
setup
: This function is called once when the mode is added to the controller when the lamp is turned on.customFirst
: This function is called once when the mode is newly selected.customLoop
: This function is called every loop iteration.last
: This function is called once when the mode is removed from the controller.customClick
: This function is called when a double click is detected from the button.
This project is licensed under the GNU General Public License v3.0. For more information, see the LICENSE
file.