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

Solar-Powered ESP32 Light-Tracking System with Servo Control

View and Edit Project In Cirkit DesignerImage of Solar-Powered ESP32 Light-Tracking System with Servo Control

Circuit Documentation

Summary

This circuit is designed to read values from four Light Dependent Resistors (LDRs) connected to an ESP32 microcontroller and adjust two micro servos based on the light intensity detected by the LDRs. Additionally, it reads the battery voltage and prints it to the serial monitor. The circuit is powered by a 3.7V battery, which is charged using a solar panel through a TP4056 charging module. A step-down converter is used to provide a stable 5V supply for the servos and other components.

Component List

  1. Solar Panel

    • Pins: +, -
    • Description: Converts sunlight into electrical energy.
    • Purpose: Provides power to charge the battery.
  2. Micro Servo 9G

    • Pins: GND, +5V, PWM
    • Description: Small servo motor.
    • Purpose: Adjusts position based on LDR readings.
  3. Photocell (LDR)

    • Pins: pin 0, pin 1
    • Description: Light-dependent resistor.
    • Purpose: Detects light intensity.
  4. Resistor

    • Pins: pin1, pin2
    • Description: Resistor with various resistance values.
    • Purpose: Used in voltage divider circuits with LDRs.
    • Properties:
      • Resistance: 10 Ohms
      • Resistance: 10000 Ohms
  5. Battery Indicator

    • Pins: +, -
    • Description: Indicates battery status.
    • Purpose: Displays battery charge level.
  6. TP4056

    • Pins: OUT-, B-, B+, OUT+, IN-, IN+
    • Description: Lithium battery charging module.
    • Purpose: Manages charging of the 3.7V battery.
  7. 3.7V Battery

    • Pins: +, -
    • Description: Rechargeable lithium battery.
    • Purpose: Provides power to the circuit.
  8. Step Down 5V Converter

    • Pins: +, -
    • Description: Converts higher voltage to 5V.
    • Purpose: Provides stable 5V supply.
  9. ESP32 (30 pin)

    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
    • Description: Microcontroller with Wi-Fi and Bluetooth capabilities.
    • Purpose: Controls the servos and reads LDR values.
  10. Pushbutton

    • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
    • Description: Mechanical switch.
    • Purpose: User input for various functions.

Wiring Details

Solar Panel

Micro Servo 9G (Servo 1)

Micro Servo 9G (Servo 2)

Photocell (LDR) 1

Photocell (LDR) 2

Photocell (LDR) 3

Photocell (LDR) 4

Resistor 1 (10 Ohms)

Resistor 2 (10k Ohms)

Resistor 3 (10k Ohms)

Resistor 4 (10k Ohms)

Battery Indicator

TP4056

3.7V Battery

Step Down 5V Converter

ESP32 (30 pin)

Pushbutton 1

Pushbutton 2

Pushbutton 3

Code Documentation

/*
 * This code reads values from four LDRs connected to the ESP32 and adjusts two
 * servos based on the light intensity detected by the LDRs. It also reads the
 * battery voltage and prints it to the serial monitor.
 */

#include <ESP32Servo.h>

Servo myservo1, myservo2;

// Pin LDR (Light Dependent Resistors)
const int LDR1 = 34; // GPIO34 (A0 pada ESP32)
const int LDR2 = 35; // GPIO35
const int LDR3 = 32; // GPIO32
const int LDR4 = 33; // GPIO33

// Pin untuk voltmeter (baca tegangan baterai)
const int BATTERY_PIN = 36; // GPIO36 (VP)

// Variabel LDR
int rRDL1 = 0, rRDL2 = 0, rRDL3 = 0, rRDL4 = 0;
int max1 = 0, max2 = 0, max3 = 0;
const int THRESHOLD = 5; // Threshold untuk menghindari jitter

// Variabel Servo
int ser1 = 0, ser2 = 0;

// Tegangan baterai
float batteryVoltage = 0.0;
const float VOLTAGE_DIVIDER_RATIO = 2.0; // Rasio tegangan resistor divider

void setup() {
  // Attach servo ke pin GPIO ESP32
  myservo1.attach(13); // GPIO13
  myservo2.attach(12); // GPIO12
  
  // In