Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsThe classic ESP32 has Bluetooth Classic as well as BLE, and the BluetoothSerial library makes it appear to a phone as a serial port. Any free Bluetooth serial terminal app can then send text to it. Here the letters '1' and '0' switch a relay on and off and the ESP32 replies with the state. There is no router, no internet and no pairing code beyond the phone's normal Bluetooth pairing. Note that Bluetooth Classic is available on the original ESP32 but not on the ESP32-C3 or S3 boards.
Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB phone charger. Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
bt_relay.inoVerify & upload in Electrolark#include <BluetoothSerial.h>
BluetoothSerial bt;
const int RELAY_PIN = 26;
const bool ACTIVE_LOW = true; // set false if your relay switches on with HIGH
void setRelay(bool on) {
digitalWrite(RELAY_PIN, (on == ACTIVE_LOW) ? LOW : HIGH);
bt.println(on ? "Relay ON" : "Relay OFF");
}
void setup() {
pinMode(RELAY_PIN, OUTPUT);
setRelay(false);
bt.begin("GB-Relay"); // the name your phone will see
}
void loop() {
if (bt.available()) {
char c = bt.read();
if (c == '1') setRelay(true);
else if (c == '0') setRelay(false);
}
}
BluetoothSerial exists only for the original ESP32. Choose 'ESP32 Dev Module', not an ESP32-C3 or S3 board.
Make sure the upload finished, reset the ESP32, and scan again from the phone's Bluetooth settings.
Flip ACTIVE_LOW in the sketch.
About 10 metres indoors.
No. iPhones do not support Bluetooth Classic serial. Use the BLE temperature beacon project's approach, or Wi-Fi instead.
Bluetooth works without a router, which is handy for a pairing-only gadget.
4 parts: ESP32-WROOM-32 38-Pin Development Board, 5V Relay Module with Optocoupler, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 1 hour. The build on this page has 6 steps.
No. This page has the complete, tested code (bt_relay.ino).
About ₹530 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Using BluetoothSerial on the original ESP32; Reading text commands from a phone; Switching a relay from received text.
Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
Ideas that reuse this build: ESP32 web server relay switch. They are listed under Take it further on this page.
Lights switch on by themselves at dusk and off again in the morning.
A precise thermostat that keeps tropical fish at a steady 25–26 °C.
Starts the pump when the tank runs low and stops it when it is full.
Tap a hidden pad to switch a lamp on or off, even through a wooden desk.
Learning project. Check every circuit and the datasheet of each part before you power it up.