41
41vi4p/Obstacle_Avoidance_Bot
ESP32 autonomous robot with obstacle avoidance (HC-SR04 ultrasonic + dual IR sensors) and WiFi manual control via mobile web interface. Features PWM speed control, real-time sensors, and built-in AP (192.168.4.1). Ideal for robotics and IoT projects.
ESP32 Obstacle Avoidance Bot with Web Control
A smart obstacle avoidance robot with dual operation modes: autonomous navigation and manual web-based control via WiFi.
Features
- ๐ค Auto Mode: Autonomous obstacle avoidance using ultrasonic and IR sensors
- ๐ฎ Manual Mode: Web-based remote control from any smartphone/tablet
- ๐ฑ Responsive Web UI: Touch-optimized interface for mobile devices
- โก PWM Speed Control: Adjustable motor speed (0-255)
- ๐ Real-time Sensor Data: Live sensor readings on web interface
- ๐ Mode Switching: Seamless switching between Auto and Manual modes
Hardware Requirements
Components
- ESP32 Development Board
- HC-SR04 Ultrasonic Sensor (1x)
- IR Obstacle Sensor Modules (2x - front and back)
- L298N Motor Driver (or similar with EN pins)
- DC Motors (2x)
- Robot Chassis
- Power Supply (suitable for motors and ESP32)
Pin Configuration
| Component | ESP32 Pin |
|---|---|
| HC-SR04 TRIG | GPIO 25 |
| HC-SR04 ECHO | GPIO 26 |
| Front IR Sensor | GPIO 15 |
| Back IR Sensor | GPIO 5 |
| Left Motor IN1 | GPIO 13 |
| Left Motor IN2 | GPIO 12 |
| Right Motor IN1 | GPIO 14 |
| Right Motor IN2 | GPIO 27 |
| Left Motor EN (PWM) | GPIO 18 |
| Right Motor EN (PWM) | GPIO 19 |
WiFi Access Point
SSID: ObstacleBot
Password: robot123
Setup Instructions
1. Hardware Assembly
- Mount all sensors and motors on the robot chassis
- Connect components according to the pin configuration table above
- Ensure proper power distribution to motors and ESP32
- Double-check all connections before powering on
2. Software Upload
- Install Arduino IDE and ESP32 board support
- Install required libraries (already included in ESP32 core):
- WiFi.h
- WebServer.h
- Open
obstacle_avoidance_bot.ino - Select your ESP32 board from Tools > Board
- Select the correct COM port
- Upload the sketch to your ESP32
3. First Run
- Power on the robot
- Open Serial Monitor (115200 baud) to see startup messages
- Note the Access Point IP address (typically
192.168.4.1)
Usage Guide
Connecting to the Bot
-
Connect to WiFi
- On your phone/tablet, go to WiFi settings
- Connect to network:
ObstacleBot - Enter password:
robot123
-
Open Web Interface
- Open browser and navigate to:
http://192.168.4.1 - The control panel will load automatically
- Open browser and navigate to:
Operating Modes
Auto Mode (Default)
- Bot autonomously avoids obstacles
- Uses ultrasonic sensor for distance detection
- IR sensors for close-range detection
- Automatically navigates around obstacles
Manual Mode
- Full manual control via web interface
- Directional buttons: Forward, Backward, Left, Right
- Hold buttons to move, release to stop
- Real-time control with immediate response
Speed Control
- Adjust speed slider (0-255)
- Changes apply immediately to both Auto and Manual modes
- Default speed: 200
- Lower speeds for precision, higher for faster movement
Sensor Monitoring
- Distance: Ultrasonic sensor reading (cm)
- Front IR: Obstacle detection status
- Back IR: Rear obstacle detection status
- Current Speed: Active motor speed value
Web Interface Features
Responsive Design
- Optimized for mobile phones and tablets
- Touch-friendly button sizes
- Prevents accidental page scrolling
- Works on all modern browsers
Control Layout
โฒ (Forward)
โ โ โบ (Left, Stop, Right)
โผ (Backward)
Real-time Updates
- Sensor data refreshes every 500ms
- Immediate command execution
- Visual feedback for mode changes
Troubleshooting
Cannot Connect to WiFi
- Ensure ESP32 is powered on
- Check Serial Monitor for AP IP address
- Try forgetting network and reconnecting
- Verify password is correct:
robot123
Motors Not Responding
- Check motor driver connections
- Verify EN pins (18, 19) are connected
- Test in Manual mode first
- Check power supply to motors
Sensors Not Reading
- Verify sensor pin connections
- Check sensor power (VCC/GND)
- View sensor data in web interface
- Check Serial Monitor for debug output
Web Page Not Loading
- Verify WiFi connection
- Use correct IP:
192.168.4.1 - Try different browser
- Check Serial Monitor for errors
Customization
Change WiFi Credentials
Edit in the sketch:
const char* AP_SSID = "ObstacleBot";
const char* AP_PASSWORD = "robot123";Adjust Pin Assignments
Modify pin definitions at the top of the sketch to match your wiring.
Tune Obstacle Avoidance
const int DISTANCE_THRESHOLD_CM = 20; // Obstacle detection distance
const unsigned long BACKUP_TIME_MS = 400; // Backup duration
const unsigned long TURN_TIME_MS = 450; // Turn durationChange IR Sensor Logic
If your IR sensors are active HIGH:
const bool FRONT_IR_ACTIVE_LOW = false;
const bool BACK_IR_ACTIVE_LOW = false;Safety Notes
- Always test in a safe, open area first
- Keep emergency stop accessible (Manual mode > Stop button)
- Monitor battery levels to prevent motor driver damage
- Start with lower speeds when testing
- Ensure proper motor driver heat dissipation
Version History
- v1.0 - Initial release with Auto/Manual modes and web control
License
Open source - modify and use as needed for your projects!
Support
For issues or questions, check:
- Serial Monitor debug output (115200 baud)
- Web interface sensor readings
- Pin connection verification
Enjoy your obstacle avoidance bot! ๐ค