Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32 Bluetooth-Controlled LED with Potentiometer and Pushbutton

View and Edit Project In Cirkit DesignerImage of ESP32 Bluetooth-Controlled LED with Potentiometer and Pushbutton

Circuit Documentation

Summary

This circuit is designed to control an LED using an ESP32 microcontroller via Bluetooth signals from an Android cell phone. The circuit includes a 5V battery for power, a rotary potentiometer for adjusting brightness, a pushbutton for manual control, and a resistor to limit current through the LED.

Component List

  1. 5V Battery

    • Description: Provides power to the circuit.
    • Pins: Positive, Negative
  2. ESP32 38 PINS

    • Description: Microcontroller used for controlling the LED and handling Bluetooth communication.
    • Pins: GND, 23, 22/SCL, 1, 2, 21/SDA, 19, 18, 5, 17/TX2, 16/RX2, 4, 0, 15, D1, D0, CLK, 3V3, EN, VP, VN, 34, 35, 32, 33, 25, 26, 27, 14, 12, 13, D2, D3, 11, 5V/VIN
  3. PR-Rotary Potentiometer

    • Description: Used to adjust the brightness of the LED.
    • Pins: GND, OUT, VCC
  4. LED: Two Pin (red)

    • Description: Indicates the status of the circuit.
    • Pins: Cathode, Anode
  5. Resistor

    • Description: Limits the current through the LED.
    • Pins: Pin1, Pin2
    • Properties:
      • Resistance: 200 Ohms
  6. Pushbutton

    • Description: Provides manual control for the LED.
    • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)

Wiring Details

5V Battery

ESP32 38 PINS

PR-Rotary Potentiometer

LED: Two Pin (red)

Resistor

Pushbutton

Code Documentation

/*
 * This Arduino Sketch controls an LED connected to pin 23 of an ESP32
 * microcontroller via Bluetooth signals from an Android cell phone.
 * The LED can be turned on or off based on the received Bluetooth commands.
 */

#include <BluetoothSerial.h>

BluetoothSerial SerialBT;
const int ledPin = 23; // Pin connected to the LED

void setup() {
  pinMode(ledPin, OUTPUT); // Set the LED pin as an output
  SerialBT.begin("Svetlo_pico"); // Initialize Bluetooth with a name
  Serial.begin(9600); // Initialize serial communication at 9600 baud rate
  Serial.println("The device started, now you can pair it with Bluetooth!");
}

void loop() {
  // Waiting for command from mobile
  if (SerialBT.available()) {
    String command = SerialBT.readStringUntil('\n'); // Read command
    command.trim(); // Remove whitespace characters (e.g., \r or space)

    if (command.startsWith("SET ")) {
      int brightness = command.substring(4).toInt(); // Get value after "SET "
      brightness = constrain(brightness, 0, 255); // Limit value to range 0–255
      analogWrite(ledPin, brightness);
      SerialBT.println("Brightness set to " + String(brightness));
    }

    if (command == "ON") {
      digitalWrite(ledPin, HIGH); // Turn on LED
      SerialBT.println("LED ON");
      Serial.println("LED ON");
    } else if (command == "OFF") {
      digitalWrite(ledPin, LOW); // Turn off LED
      SerialBT.println("LED OFF");
      Serial.println("LED OFF");
    } else {
      SerialBT.println("Unknown command. Use ON or OFF.");
      Serial.println("Unknown command.");
    }
  }
}

This code initializes the ESP32 microcontroller to control an LED via Bluetooth. The LED can be turned on or off based on commands received from a paired Android cell phone. The code also allows for setting the brightness of the LED using a "SET" command followed by a value between 0 and 255.