Circuit Connections
Single IR Sensor Line Follower Robot
🎯 Lesson Objective
In this lesson, students will learn:
• How to connect the IR sensor to the ESP32
• How to connect the L298N motor driver to the ESP32
• How to connect the DC motors to the motor driver
• How to properly supply power to the robot system
By the end of this lesson, students will be able to correctly wire all the components required for the Single IR Sensor Line Follower Robot.
1️⃣ IR Sensor Connection
The IR sensor is responsible for detecting the black line on the surface.
The sensor has three pins:
• VCC – Power supply
• GND – Ground connection
• OUT – Signal output
Connection with ESP32
VCC → 3.3V (ESP32)
GND → GND (ESP32)
OUT → GPIO 34 (ESP32)
The OUT pin sends a digital signal to the ESP32 indicating whether the sensor detects a black or white surface.
2️⃣ Motor Driver Connection (L298N)
The L298N motor driver controls the movement and direction of the DC motors.
The ESP32 sends control signals to the motor driver through input pins.
L298N Control Pins
IN1 → GPIO 26 (ESP32)
IN2 → GPIO 27 (ESP32)
IN3 → GPIO 14 (ESP32)
IN4 → GPIO 12 (ESP32)
These pins control the direction of both motors.
3️⃣ DC Motor Connections
Two DC motors are connected to the motor driver.
Motor A (Left Motor)
Motor wires → OUT1 and OUT2 of L298N
Motor B (Right Motor)
Motor wires → OUT3 and OUT4 of L298N
These connections allow the motor driver to control both motors independently.
4️⃣ Power Supply Connections
The robot requires power for both the motors and the microcontroller.
Motor Driver Power
Battery Positive → 12V terminal of L298N
Battery Ground → GND of L298N
ESP32 Power
ESP32 can be powered using:
• USB cable
or
• External 5V supply
Make sure all grounds are connected together.
Common Ground Connections:
ESP32 GND → L298N GND → Battery GND
This is important for proper communication between components.
5️⃣ Circuit Summary
Below is a quick summary of all connections used in this project.
IR Sensor
VCC → 3.3V
GND → GND
OUT → GPIO 34
Motor Driver Control
IN1 → GPIO 26
IN2 → GPIO 27
IN3 → GPIO 14
IN4 → GPIO 12
Motors
Left Motor → OUT1 & OUT2
Right Motor → OUT3 & OUT4
Power
Battery → L298N
ESP32 → USB or 5V supply
6️⃣ Important Wiring Tips
To ensure the robot works correctly, follow these tips:
✔ Double-check all wiring connections
✔ Ensure the battery polarity is correct
✔ Make sure all GND connections are common
✔ Place the IR sensor facing downward toward the ground
✔ Keep the sensor about 1–2 cm above the surface
Proper wiring is essential for reliable robot performance.
🚀 What Happens Next
Now that all components are connected correctly, the next step is to write the program that controls the robot’s movement.