Community project

Create A Complete Electrical Schematic Esp32 Sma

ESP32
Photo of Create A Complete Electrical Schematic Esp32 Sma
Generated with AI

Ayansh Agrawal

Published September 17, 2026

This project builds a complete sensor and motor control system around an ESP32 microcontroller, powered by a 2-cell 18650 Li-ion battery pack. The system integrates motion detection via ADXL345 accelerometer, temperature monitoring with DS18B20, current sensing through ACS712, obstacle detection with an IR sensor, and dual motor control via L298N H-bridge driver, all displayed on an OLED screen.

The guide provides a complete wiring diagram, full parts list with resistor values, and ready-to-compile firmware that handles I2C communication, motor PWM control, and real-time sensor data display. Follow the assembly outline to safely integrate power distribution, sensor connections, and motor drivers, with inspection checkpoints before first power-up.

Wiring diagram

Wiring diagram for Create A Complete Electrical Schematic Esp32 Sma

Gather all the parts

QtyComponent
1

2-cell 18650 Li-ion battery pack

7.4 V nominal

A rechargeable two-cell battery pack that supplies about 7.4 V for the motors and regulator.

1

SPST power switch

SPST

A simple on-off switch that disconnects battery power from the motor supply.

1

5 V buck regulator module

5 V

A step-down regulator that safely converts the battery voltage to the 5 V rail.

1

ADXL345 accelerometer module

3.3 V I2C

A small sensor module that measures movement and vibration.

1

ACS712 current sensor module

5 V analog

A Hall-effect module that produces an analog voltage showing motor current.

1

IR obstacle sensor module

5 V module

An infrared module that reports when an object is detected.

1

DS18B20 temperature sensor

3.3 V

A three-wire digital sensor that measures temperature.

1

OLED I2C display module

3.3 V I2C

A small screen that displays the smart car's status and sensor readings.

1

L298N dual H-bridge motor driver module

Dual H-bridge

A motor driver module that lets the ESP32 control two geared DC motors from the battery.

1

ACS712 ADC divider upper resistor

12 kΩ

A resistor that reduces the ACS712 5 V analog output before it reaches the ESP32 input.

1

ACS712 ADC divider lower resistor

22 kΩ

A resistor that completes the ACS712 voltage divider to ground and protects the ESP32 ADC input.

1

DS18B20 pull-up resistor

4.7 kΩ

A resistor that holds the temperature sensor data wire at 3.3 V when it is idle.

1

Green LED series resistor

220 Ω

A resistor that limits the current through the green status LED.

1

Green status LED

Green

A green light that indicates smart car status.

1

Red LED series resistor

220 Ω

A resistor that limits the current through the red status LED.

1

Red status LED

Red

A red light that indicates smart car status.

1

5 V active buzzer

5 V active

An audible buzzer that sounds warnings when switched by the transistor driver.

1

NPN buzzer driver transistor

2N2222 / PN2222A

A transistor switch that lets the ESP32 safely turn the 5 V buzzer on and off.

1

Buzzer transistor base resistor

1 kΩ

A resistor that limits the ESP32 GPIO5 current into the buzzer driver transistor.

1

TT geared DC motor 1

TT DC gearmotor

The first small geared DC motor that drives one side of the car.

1

TT geared DC motor 2

TT DC gearmotor

The second small geared DC motor that drives the other side of the car.

1

IR sensor output divider upper resistor

12 kΩ

A resistor that lowers a possible 5 V IR sensor output to a safe ESP32 input level.

1

IR sensor output divider lower resistor

22 kΩ

A resistor that completes the IR sensor output divider to ground.

Assemble it in 6 steps

1. Place the power parts first

Put the 2-cell 18650 battery holder, the on/off switch, and the 5 V buck regulator on the car chassis. Connect battery BAT+ to the switch IN, connect switch OUT to the L298N Vs/12V input, and connect battery BAT+ to buck IN+ (motor power and regulator input). Connect battery BAT− to buck IN− and the common GND line (ground). Keep the switch OFF while building.

  • Set the buck regulator output to 5.0 V with a meter before plugging it into any module.
  • Use thicker wires for the battery, switch, L298N Vs, and motor connections.
  • Do not reverse the battery leads — reversed battery power can damage the regulator, driver, and ESP32.
  • Do not connect the 7.4 V battery directly to the ESP32 3.3 V or 5 V electronics rail.

2. Make the shared power rails

From the regulator OUT+ terminal, make a labeled +5V rail to the L298N 5V pin, ACS712 VCC, IR sensor VCC, and buzzer positive pin (power). Join regulator OUT− to every GND connection, including the ESP32 GND, L298N GND, sensors, OLED, LEDs, transistor emitter, and battery negative (ground). Use the ESP32 3.3V pin as the labeled +3.3V rail for the ADXL345, DS18B20, OLED, and DS18B20 pull-up resistor (power).

  • Treat every GND symbol or wire as one shared electrical point, even when the schematic uses separate ground symbols.
  • Keep motor-current wires away from the small sensor wires where possible.
  • A missing shared ground can make sensors and motor controls behave unpredictably.
  • Make sure the ADXL345 and OLED VCC pins go to 3.3 V, not 5 V — 5 V can damage 3.3 V-only modules.

3. Wire the sensors to the ESP32

Wire ADXL345 SCL to GPIO22 and SDA to GPIO21 (shared data wires); wire INT1 to GPIO19 and INT2 to GPIO18 (signals). Wire OLED SCL to GPIO22 and SDA to GPIO21, with VCC to 3.3V and GND to GND (power and ground). Wire DS18B20 DATA pin 2 to GPIO23 and fit the 4.7 kΩ resistor from that same DATA wire to 3.3V (signal pull-up); DS18B20 pin 1 goes to 3.3V and pin 3 to GND. Wire the protected IR divider output to GPIO25 and the protected ACS712 divider output to GPIO34 (signals).

  • On the DS18B20 with its flat face toward you, pin 1 is 3.3 V, the middle pin 2 is DATA, and pin 3 is GND.
  • The two I2C data wires are intentionally shared between the ADXL345 and OLED.
  • Do not bypass the 12 kΩ and 22 kΩ ACS712 divider — direct 5 V analog output can damage GPIO34.
  • Do not bypass the 12 kΩ and 22 kΩ IR divider if your IR module outputs 5 V — it protects GPIO25.

4. Fit the indicators and buzzer driver

Connect GPIO17 to the 220 Ω green LED resistor, then to the green LED anode; connect its cathode to GND (status light). Connect GPIO16 to the 220 Ω red LED resistor, then to the red LED anode; connect its cathode to GND (status light). Connect GPIO5 through the 1 kΩ resistor to the NPN transistor base, connect emitter to GND, collector to buzzer negative, and buzzer positive to +5V (sound control).

  • The LED’s longer leg is usually the anode; the shorter leg or flat-sided end is the cathode.
  • The transistor face and pin order vary by package, so check its printed pinout before inserting it.
  • Each LED must keep its 220 Ω resistor — without it the LED or ESP32 pin can be damaged.
  • A transistor wired with collector and emitter swapped may not operate correctly or can overheat.

5. Connect the driver and motors

Connect L298N ENA to GPIO4, IN1 to GPIO2, IN2 to GPIO15, IN3 to GPIO13, IN4 to GPIO12, and ENB to GPIO14 (motor-control signals). Connect L298N OUT1 and OUT2 to the two terminals of TT Motor 1, and OUT3 and OUT4 to the two terminals of TT Motor 2 (motor power). Mount the motors so their wires cannot rub on the wheels.

  • If a motor runs backward later, swap only that motor’s two wires at OUT1/OUT2 or OUT3/OUT4.
  • Keep the L298N where it can lose heat; it can become warm during motor use.
  • GPIO2, GPIO12, and GPIO15 are ESP32 start-up pins; keep the L298N connections in place and avoid adding extra pull-up or pull-down parts to those wires.
  • Never unplug or reconnect motor wires while battery power is switched on — a loose wire can short the motor supply.

6. Inspect before powering up

With the switch still OFF, check that every module has GND connected to the same common ground, that no 7.4 V wire reaches a 3.3 V device, and that both voltage-divider resistor pairs are fitted. Then plug the ESP32 into USB for programming and use Schematik’s Deploy button; only switch on the battery after the wiring inspection is complete.

  • First power test with the wheels lifted off the table so an unexpected motor movement cannot drive the car away.
  • At start-up the supplied firmware deliberately keeps both motors stopped.
  • If anything becomes hot, smells unusual, or the regulator output is not 5 V, immediately switch off and disconnect the battery.
  • Do not power the car from battery and USB until the common-ground wiring has been checked.

Review all connections

1. Connections between "battery_2s" and "ESP32"

Functionbattery_2sESP32
powerBAT+SPST power switch INEXT
groundBAT-GND

2. Connections between "power_switch" and "ESP32"

Functionpower_switchESP32
powerOUTL298N dual H-bridge motor driver module Vs / 12VEXT

3. Connections between "buck_5v" and "ESP32"

Functionbuck_5vESP32
powerIN+2-cell 18650 Li-ion battery pack BAT+EXT
groundIN-GND
powerOUT+5V
groundOUT-GND

4. Connections between "adxl345" and "ESP32"

Functionadxl345ESP32
powerVCC3V3
groundGNDGND
i2cSCLGPIO 22
i2cSDAGPIO 21
digitalINT1GPIO 19
digitalINT2GPIO 18

5. Connections between "acs712" and "ESP32"

Functionacs712ESP32
powerVCC5V
groundGNDGND
analogOUTACS712 ADC divider upper resistor AEXT

6. Connections between "acs_rtop" and "ESP32"

Functionacs_rtopESP32
analogBGPIO 34

7. Connections between "acs_rbottom" and "ESP32"

Functionacs_rbottomESP32
groundBGND
analogAACS712 ADC divider upper resistor BEXT

8. Connections between "ir_sensor" and "ESP32"

Functionir_sensorESP32
powerVCC5V
groundGNDGND
digitalOUTIR sensor output divider upper resistor AEXT

9. Connections between "ir_rtop" and "ESP32"

Functionir_rtopESP32
digitalBGPIO 25

10. Connections between "ir_rbottom" and "ESP32"

Functionir_rbottomESP32
groundBGND
digitalAIR sensor output divider upper resistor BEXT

11. Connections between "ds18b20" and "ESP32"

Functionds18b20ESP32
powerVDD (Pin 1)3V3
digitalDATA (Pin 2)GPIO 23
groundGND (Pin 3)GND

12. Connections between "ds18b20_pullup" and "ESP32"

Functionds18b20_pullupESP32
powerA3V3
digitalBDS18B20 temperature sensor DATA (Pin 2)EXT

13. Connections between "oled" and "ESP32"

FunctionoledESP32
powerVCC3V3
groundGNDGND
i2cSCLGPIO 22
i2cSDAGPIO 21

14. Connections between "green_resistor" and "ESP32"

Functiongreen_resistorESP32
digitalAGPIO 17
digitalBGreen status LED AnodeEXT

15. Connections between "green_led" and "ESP32"

Functiongreen_ledESP32
groundCathodeGND

16. Connections between "red_resistor" and "ESP32"

Functionred_resistorESP32
digitalAGPIO 16
digitalBRed status LED AnodeEXT

17. Connections between "red_led" and "ESP32"

Functionred_ledESP32
groundCathodeGND

18. Connections between "buzzer" and "ESP32"

FunctionbuzzerESP32
power+5V
ground-NPN buzzer driver transistor CEXT

19. Connections between "buzzer_transistor" and "ESP32"

Functionbuzzer_transistorESP32
digitalBBuzzer transistor base resistor BEXT
groundEGND

20. Connections between "buzzer_base_resistor" and "ESP32"

Functionbuzzer_base_resistorESP32
digitalAGPIO 5

21. Connections between "l298n" and "ESP32"

Functionl298nESP32
power5V5V
groundGNDGND
pwmENAGPIO 4
digitalIN1GPIO 2
digitalIN2GPIO 15
digitalIN3GPIO 13
digitalIN4GPIO 12
pwmENBGPIO 14
powerOUT1TT geared DC motor 1 M+EXT
powerOUT2TT geared DC motor 1 M-EXT
powerOUT3TT geared DC motor 2 M+EXT
powerOUT4TT geared DC motor 2 M-EXT

Deploy the firmware

#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>
#include <DallasTemperature.h>


// Forward declarations
void stopMotors();
void configureAdxl345();
void drawStatus(float temperatureC, float currentVoltage, bool obstacle);

constexpr int L298_ENA = 4;
constexpr int L298_IN1 = 2;
constexpr int L298_IN2 = 15;
constexpr int L298_IN3 = 13;
constexpr int L298_IN4 = 12;
constexpr int L298_ENB = 14;
constexpr int BUZZER_PIN = 5;
constexpr int RED_LED_PIN = 16;
constexpr int GREEN_LED_PIN = 17;
constexpr int ADXL_INT2_PIN = 18;
constexpr int ADXL_INT1_PIN = 19;
constexpr int I2C_SDA_PIN = 21;
constexpr int I2C_SCL_PIN = 22;
constexpr int DS18B20_PIN = 23;
constexpr int IR_PIN = 25;
constexpr int ACS712_ADC_PIN = 34;

constexpr uint8_t OLED_ADDRESS = 0x3C;
constexpr uint8_t ADXL345_ADDRESS = 0x53;
constexpr unsigned long UPDATE_INTERVAL_MS = 500;

Adafruit_SSD1306 display(128, 64, &Wire, -1);
OneWire oneWire(DS18B20_PIN);
DallasTemperature temperatureSensor(&oneWire);

unsigned long lastUpdate = 0;
float lastTemperatureC = -127.0f;
float lastCurrentVoltage = 0.0f;
bool lastObstacle = false;
bool displayAvailable = false;

void stopMotors() {
  digitalWrite(L298_ENA, LOW);
  digitalWrite(L298_ENB, LOW);
  digitalWrite(L298_IN1, LOW);
  digitalWrite(L298_IN2, LOW);
  digitalWrite(L298_IN3, LOW);
  digitalWrite(L298_IN4, LOW);
}

void configureAdxl345() {
  Wire.beginTransmission(ADXL345_ADDRESS);
  Wire.write(0x2D);  // POWER_CTL register
  Wire.write(0x08);  // measurement mode
  Wire.endTransmission();
}

void drawStatus(float temperatureC, float currentVoltage, bool obstacle) {
  if (!displayAvailable) return;

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println(F("ESP32 SMART CAR"));
  display.println(F("Motors: STOPPED"));
  display.print(F("Temp: "));
  if (temperatureC <= -100.0f) {
    display.println(F("sensor check"));
  } else {
    display.print(temperatureC, 1);
    display.println(F(" C"));
  }
  display.print(F("ACS ADC: "));
  display.print(currentVoltage, 2);
  display.println(F(" V"));
  display.print(F("IR obstacle: "));
  display.println(obstacle ? F("YES") : F("NO"));
  display.display();
}

void setup() {
  pinMode(L298_ENA, OUTPUT);
  pinMode(L298_IN1, OUTPUT);
  pinMode(L298_IN2, OUTPUT);
  pinMode(L298_IN3, OUTPUT);
  pinMode(L298_IN4, OUTPUT);
  pinMode(L298_ENB, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(ADXL_INT1_PIN, INPUT);
  pinMode(ADXL_INT2_PIN, INPUT);
  pinMode(IR_PIN, INPUT);

  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(RED_LED_PIN, LOW);
  digitalWrite(GREEN_LED_PIN, HIGH);
  stopMotors();

  Serial.begin(115200);
  Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
  configureAdxl345();
  temperatureSensor.begin();
  analogReadResolution(12);

  displayAvailable = display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS);
  if (displayAvailable) {
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 0);
    display.println(F("ESP32 Smart Car"));
    display.println(F("Sensor monitor ready"));
    display.display();
  }
}

void loop() {
  const unsigned long now = millis();
  if (now - lastUpdate < UPDATE_INTERVAL_MS) return;
  lastUpdate = now;

  temperatureSensor.requestTemperatures();
  lastTemperatureC = temperatureSensor.getTempCByIndex(0);
  const int adcRaw = analogRead(ACS712_ADC_PIN);
  lastCurrentVoltage = (adcRaw * 3.3f) / 4095.0f;
  lastObstacle = (digitalRead(IR_PIN) == LOW);

  digitalWrite(RED_LED_PIN, lastObstacle ? HIGH : LOW);
  digitalWrite(GREEN_LED_PIN, lastObstacle ? LOW : HIGH);
  digitalWrite(BUZZER_PIN, lastObstacle ? HIGH : LOW);

  Serial.print(F("Temp C: "));
  Serial.print(lastTemperatureC, 1);
  Serial.print(F(" | ACS ADC V: "));
  Serial.print(lastCurrentVoltage, 2);
  Serial.print(F(" | Obstacle: "));
  Serial.println(lastObstacle ? F("YES") : F("NO"));

  drawStatus(lastTemperatureC, lastCurrentVoltage, lastObstacle);
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace — diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik