ESP32-Controlled Self-Balancing Robot with MPU-6050 and L298N Motor Driver
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed for a two-wheeled self-balancing robot that uses an MPU-6050 sensor to detect the tilt angle and an L298N motor driver to control two DC motors. The ESP32 microcontroller reads the angle from the MPU-6050 and adjusts the motor speeds accordingly to balance the robot. The circuit also includes a 7805 voltage regulator, a 74HC595 shift register, various resistors, a piezo buzzer, an NPN transistor, a servo motor, an ultrasonic sensor, an LED strip, an LCD display, and input devices such as a pushbutton, a rocker switch, and a potentiometer.
Component List
L298N DC Motor Driver
- Description: A motor driver module capable of driving two DC motors.
- Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, ENA, IN1, IN2, IN3, IN4, ENB
Rocker Switch
- Description: A switch to control the power supply to the circuit.
- Pins: Output, Input
2x 18650 Batteries
- Description: A power source for the circuit.
- Pins: VCC, GND
LED: Two Pin (Red)
- Description: A red indicator LED.
- Pins: Cathode, Anode
Resistor (200 Ohms)
- Description: A resistor with a resistance of 200 Ohms.
- Pins: Pin1, Pin2
74HC595 Shift Register
- Description: An 8-bit serial-in, parallel-out shift register.
- Pins: Q0-Q7, GND, VCC, DS (DATA), OE (Enable), ST_CP (RCLK), SH_CP (SRCLK), MR (SRCLR), Q7' (QH)
7805 Voltage Regulator
- Description: A voltage regulator that outputs 5V.
- Pins: Vin, Gnd, Vout
HC-SR04 Ultrasonic Sensor
- Description: A sensor for measuring distance via ultrasonic waves.
- Pins: VCC, TRIG, ECHO, GND
WS2815 LED Strip
- Description: An addressable LED strip.
- Pins: GND, B0, D0, +12V
NTC Thermistor
- Description: A temperature sensor.
- Pins: A0, A1
LCD Display 20x4 I2C
- Description: An LCD display with I2C interface.
- Pins: SCL, SDA, VCC, GND
Pushbutton
- Description: A momentary pushbutton switch.
- Pins: Pin 1-4
Potentiometer
- Description: A variable resistor.
- Pins: GND, Output, VCC
MPU-6050 Gyroscope/Accelerometer
- Description: A sensor for detecting orientation and movement.
- Pins: VCC, GND, SCL, SDA, XDA, XCL, AD0, INT
ESP32 - 38 Pins Microcontroller
- Description: A microcontroller with Wi-Fi and Bluetooth capabilities.
- Pins: Various GPIOs, 3V3, EN, GND, 5V, TXD, RXD, SCL, SDA
Resistor (10k Ohms)
- Description: A resistor with a resistance of 10k Ohms.
- Pins: Pin1, Pin2
Piezo Buzzer
- Description: A device that emits sound when powered.
- Pins: Pin 1, Pin 2
NPN Transistor
- Description: A transistor used as a switch or amplifier.
- Pins: E, C, B
Resistor (1k Ohms)
- Description: A resistor with a resistance of 1k Ohms.
- Pins: Pin1, Pin2
Servo Motor
- Description: A motor capable of precise position control.
- Pins: GND, VCC, PWM
DC Motor with Encoder (x2)
- Description: Motors with built-in encoders for speed and direction feedback.
- Pins: Encoder B, Encoder A, GND, VCC, Motor +ve, Motor -ve
L293D Motor Driver
- Description: A motor driver capable of driving a DC motor.
- Pins: Enable 1,2, Input 1-4, Output 1-4, GND, VCC1, VCC2
DC Motor
- Description: A basic DC motor.
- Pins: Pin 1, Pin 2
Wiring Details
L298N DC Motor Driver
- 12V: Connected to the rocker switch output.
- GND: Common ground with other components.
- 5V: Connected to the 7805 voltage regulator output.
- ENA, ENB: Controlled by the 74HC595 shift register.
- IN1-IN4: Controlled by the 74HC595 shift register.
- OUT1-OUT4: Connected to the DC motors with encoders.
Rocker Switch
- Input: Connected to the 2x 18650 batteries VCC.
- Output: Connected to the L298N motor driver 12V and the 7805 voltage regulator Vin.
2x 18650 Batteries
- VCC: Connected to the rocker switch input.
- GND: Common ground with other components.
LED: Two Pin (Red)
- Cathode: Connected to the common ground.
- Anode: Connected to a 200 Ohm resistor.
Resistor (200 Ohms)
- Pin1: Connected to the LED anode.
- Pin2: Connected to the pushbutton Pin 2.
74HC595 Shift Register
- GND: Common ground with other components.
- VCC: Connected to the 7805 voltage regulator output.
- Q0-Q7: Control various inputs on the L298N motor driver.
- DS (DATA), OE (Enable), ST_CP (RCLK), SH_CP (SRCLK): Controlled by the ESP32 microcontroller.
7805 Voltage Regulator
- Vin: Connected to the rocker switch output.
- Gnd: Common ground with other components.
- Vout: Connected to the 74HC595 VCC and other 5V components.
HC-SR04 Ultrasonic Sensor
- VCC: Connected to the 7805 voltage regulator output.
- TRIG, ECHO: Controlled by the ESP32 microcontroller.
- GND: Common ground with other components.
WS2815 LED Strip
- +12V: Connected to the 2x 18650 batteries VCC.
- D0: Controlled by the ESP32 microcontroller.
- GND: Common ground with other components.
NTC Thermistor
- A0: Connected to a 10k Ohm resistor.
- A1: Common ground with other components.
LCD Display 20x4 I2C
- SCL, SDA: Connected to the ESP32 microcontroller.
- VCC: Connected to the 7805 voltage regulator output.
- GND: Common ground with other components.
Pushbutton
- Pin 1: Connected to the ESP32 microcontroller.
- Pin 2: Connected to the LED cathode and common ground.
Potentiometer
- GND: Common ground with other components.
- Output: Connected to the ESP32 microcontroller.
- VCC: Connected to the 3V3 output from the ESP32 microcontroller.
MPU-6050 Gyroscope/Accelerometer
- VCC: Connected to the 7805 voltage regulator output.
- GND: Common ground with other components.
- SCL, SDA: Connected to the ESP32 microcontroller.
ESP32 - 38 Pins Microcontroller
- Various GPIOs: Control and receive data from other components.
- 3V3: Provides power to the potentiometer.
- GND: Common ground with other components.
- 5V: Receives power from the 7805 voltage regulator output.
Resistor (10k Ohms)
- Pin1: Connected to the NTC thermistor A0.
- Pin2: Connected to the 3V3 output from the ESP32 microcontroller.
Piezo Buzzer
- Pin 1: Connected to the common ground.
- Pin 2: Connected to the NPN transistor base.
NPN Transistor
- E: Common ground with other components.
- C: Connected to the piezo buzzer pin 2.
- B: Connected to a 1k Ohm resistor.
Resistor (1k Ohms)
- Pin1: Connected to the NPN transistor base.
- Pin2: Connected to the ESP32 microcontroller.
Servo Motor
- GND: Common ground with other components.
- VCC: Connected to the 7805 voltage regulator output.
- PWM: Controlled by the ESP32 microcontroller.
DC Motor with Encoder (x2)
- GND, VCC: Power connections.
- Motor +ve, Motor -ve: Connected to the L298N motor driver outputs.
- Encoder A, Encoder B: Connected to the ESP32 microcontroller.
L293D Motor Driver
- GND: Common ground with other components.
- VCC1: Connected to the 7805 voltage regulator output.
- Enable 1,2: Controlled by the ESP32 microcontroller.
- Input 1-4: Controlled by the ESP