ESP32-C3 Dual LED Controller

by vitorccsiqueira in Circuits > Arduino

43 Views, 0 Favorites, 0 Comments

ESP32-C3 Dual LED Controller

pcb.jpg
led-both.jpg
led-02.jpeg
led-01.jpg

A simple ESP32-C3 project to control 02 LED strips via a web interface and a physical push button.

Supplies

  1. 01 ESP32-C3 Mini board
  2. 01 Push Button
  3. 02 Green LED
  4. 03 220Ω Resistors
  5. 02 10KΩ Resistor
  6. 02 N-channel MOSFET able to work with 3.3v logic (e.g.: IRFZ44N)
  7. 01 P-channel power MOSFET IRF9540N
  8. 02 LED Strip (12v)
  9. 01 Power Supply (12v)
  10. 01 Mini 360 DC-DC Bulk Converter

Schematics

schematics.png

Notes:

  1. Gate resistor (220Ω) is optional but recommended to prevent spikes.
  2. Pull-down resistor (10kΩ) between Gate and GND is optional but prevents accidental turn-on during boot.
  3. IRF9540N is optional but protects against reverse-polarity


The PCB

prototype.jpg
pcb-01.png
pcb-02.png

You can build a protoboard or order a PCB

NOTE: Gerber file is located at Github

The Code

NOTE: We are using PlaformIO IDE instead of Arduino IDE. Platform IO is a plugin for Microsoft Virtual Studio Code. It is a more robust IDE compared to official Arduino IDE. It also allows us to easily create our own private libraries and use a more object oriented code.


1) Create a new project in PlatformIO IDE

2) Find the code at GitHub and place at your project folder

3) The PINs can be customized in the main.cpp

#include <Arduino.h>
#include <NoDelay.h>
#include <HttpServer.h>
#include <WifiHandler.h>
#include <LedRelay.h>
#include <PushButton.h>
#include "types.h"

#define RELAY_PIN_1 1
#define RELAY_PIN_2 0
#define LED_PIN_1 3
#define LED_PIN_2 4
#define BUTTON_PIN 10
#define WIFI_SSID "MY_SSID"
#define WIFI_PWD "MY_PASSWORD"

4) Build & Upload the code to your ESP32-C3 board

5) Done!

The Web Interface

web_interface.png

Now, you control the LEDs by a Web Interface.


NOTE: Assign a Static IP to your device in your home router.

Sample of Push Button

push-button.jpg

You can also control the LEDs by a Push Button

Simple API

Additionally, the LED can be controlled via a simple API, making it easy to integrate with home automation (e.g.: set up a cron job to turn it on and off automatically):

GET http://192.168.1.190/status
POST http://192.168.1.190/cycle
POST http://192.168.1.190/toggle-1
POST http://192.168.1.190/toggle-2
POST http://192.168.1.190/turn-on-1
POST http://192.168.1.190/turn-on-2
POST http://192.168.1.190/turn-off-1
POST http://192.168.1.190/turn-off-2

NOTE: Change http://192.168.1.190 to your actual device IP. Assign a Static IP to your device in your home router.