A comprehensive IoT solution for line detection and proximity sensing using ESP32 and TCRT5000 infrared reflective sensor, featuring a modern web interface for real-time monitoring and data logging.
- Real-time Line Detection: Detects black lines or nearby objects using infrared reflection
- Dual Output Reading:
- Digital output (HIGH/LOW detection)
- Analog output (0-4095 intensity value)
- Visual LED Indicator: Built-in LED responds to detection events
- Detection Counter: Tracks total number of detection events
- Modern Responsive UI: Clean, mobile-friendly design
- Real-time Monitoring: Live sensor data updates every 500ms via AJAX
- Data Visualization:
- Current sensor status (Active/Standby)
- Detection type indicator
- Analog and digital values
- Time since last detection
- Data Logging:
- Save individual readings with timestamps
- Auto-save mode for continuous logging
- Download all readings as text file
- Clear saved data
- Remote Access: Access from any device on the network
- Dual WiFi Modes:
- Station Mode: Connect to existing WiFi network
- Access Point Mode: Creates own WiFi hotspot (fallback)
- WiFi Configuration:
- Web-based WiFi setup interface
- Credentials stored in EEPROM (persistent)
- Automatic reconnection on boot
- Easy network switching
- Status Monitoring: Real-time WiFi connection status and IP display
- Grid scanner system prepared (currently disabled)
- Ready for integration with distance sensors (VL53L0X, VL53L1X, HC-SR04)
- 2D heatmap visualization infrastructure in place
- ESP32 Development Board (ESP32-WROOM recommended)
- TCRT5000 Tracking Sensor Module
- Digital output (D0)
- Analog output (A0)
- Adjustable sensitivity potentiometer
- USB Cable for programming and power
- Jumper Wires
| TCRT5000 | ESP32 Pin | Description |
|---|---|---|
| VCC | 3.3V or 5V | Power supply |
| GND | GND | Ground |
| D0 | GPIO 14 | Digital output |
| A0 | GPIO 34 | Analog output |
Note: GPIO 34 is input-only and ADC-capable (perfect for analog readings)
ESP32 TCRT5000
┌──────────┐ ┌──────────┐
│ │ │ │
│ 3.3V├────────┤VCC │
│ │ │ │
│ GND├────────┤GND │
│ │ │ │
│ GPIO 14├────────┤D0 │
│ │ │ │
│ GPIO 34├────────┤A0 │
│ │ │ │
│ GPIO 2├─LED │ │
└──────────┘ └──────────┘
- PlatformIO IDE (VS Code extension recommended)
- Platform: Espressif 32
- Framework: Arduino
- Board: ESP32 Dev Module
git clone https://github.com/SimedruF/ESP32_TCRT5000_Tracking_Module.git
cd ESP32_TCRT5000_Tracking_Module- Open VS Code
- Install PlatformIO extension if not already installed
- File → Open Folder → Select project directory
Edit src/main.cpp if you need to change:
- Pin assignments
- WiFi AP credentials (default:
ESP32_IR_Receiver/12345678) - Sensor threshold values
- Update intervals
# Build the project
platformio run
# Upload to ESP32
platformio run --target upload
# Monitor serial output
platformio device monitorOr use PlatformIO buttons in VS Code toolbar.
- Power on ESP32: After upload, the device will start in Access Point mode
- Connect to WiFi:
- SSID:
ESP32_IR_Receiver - Password:
12345678
- SSID:
- Open Web Interface:
- Navigate to:
http://192.168.4.1
- Navigate to:
- (Optional) Configure Local WiFi:
- Go to "📡 WiFi Configuration" tab
- Enter your WiFi credentials
- Click "Save and Connect"
- Device will restart and connect to your network
After WiFi configuration, the device will:
- Automatically connect to your WiFi on boot
- Display its IP address in Serial Monitor
- Be accessible at the assigned IP address (e.g.,
http://192.168.1.100)
- Status: Shows current sensor state (🟢 Active / ⚪ Standby)
- Detection Type: LINE DETECTED / No detection
- Analog Value: Raw sensor reading (0-4095)
- Digital Value: Binary state (0=detected, 1=clear)
- Detections Counter: Total detection events
- Last Detection: Time elapsed since last event
- Controls:
- 💾 Save reading
- 📥 Download all readings
- 🗑️ Delete all data
- 🔄 Auto-save toggle
- View current WiFi status and IP address
- Configure or change WiFi network
- Clear saved WiFi credentials
- Reset to Access Point mode
The TCRT5000 module has an onboard potentiometer for sensitivity adjustment:
- Place sensor over the target surface
- Adjust potentiometer until the onboard LED indicator responds correctly
- Fine-tune for optimal detection range (typically 2-10mm)
- Test with different surfaces:
- Black line → Digital output goes LOW
- White surface → Digital output stays HIGH
| Surface | Distance | Digital Output | Analog Value | Status |
|---|---|---|---|---|
| Black line | Close | LOW (0) | High (>2000) | 🟢 Active |
| White surface | Close | HIGH (1) | Low (<1000) | ⚪ Standby |
| No object | Far | HIGH (1) | Very Low (<500) | ⚪ Standby |
Downloaded readings are saved in text format:
========================================
ESP32 TCRT5000 SENSOR - SAVED READINGS
========================================
Total readings: 10
Export date: 1234 seconds since boot
========================================
--- Reading #1 ---
Timestamp: 45s
Status: 🟢 Active
Detection Type: LINE DETECTED
Analog Value: 3245
Digital Value: 0
--- Reading #2 ---
...
ESP32_TCRT5000_Tracking_Module/
├── src/
│ └── main.cpp # Main application code
├── include/
│ └── README # Include folder info
├── lib/
│ └── README # Library folder info
├── test/
│ └── README # Test folder info
├── platformio.ini # PlatformIO configuration
└── README.md # This file
- Saved Readings: Maximum 50 readings stored in RAM
- WiFi Credentials: Stored in ESP32 EEPROM (Preferences library)
- Web Page: Stored in program memory (PROGMEM)
- Web Server: Runs on port 80
- Updates: AJAX polling every 500ms
- AP Mode IP: 192.168.4.1
- Station Mode IP: Assigned by DHCP
- Detection Response: ~50ms
- Web Update Rate: 500ms
- WiFi Reconnection: Automatic with 20 retry attempts
- Maximum Saved Readings: 50 entries
The following features are prepared but currently disabled:
- 2D Heatmap Visualization: Canvas-based grid display
- 256-cell Grid: 16×16 automatic scanning
- Color-coded Intensity: Visual representation of readings
- Export Capability: Download scan data
To Enable: Uncomment the grid scanner sections in main.cpp and add a distance sensor module (VL53L0X, VL53L1X, or HC-SR04).
- Check SSID and password are correct
- Ensure WiFi is 2.4GHz (ESP32 doesn't support 5GHz)
- Clear WiFi credentials and reconfigure
- Check serial monitor for error messages
- Verify wiring connections
- Adjust sensitivity potentiometer
- Check sensor distance (optimal: 2-10mm)
- Test with high-contrast surfaces (black/white)
- Verify device IP address from serial monitor
- Ensure device and client are on same network
- Try Access Point mode if station mode fails
- Check firewall settings
- Verify GPIO 2 connection (built-in LED)
- Check sensor is actually detecting
- View serial monitor for detection events
Expected output during operation:
TCRT5000 + ESP32: Sensor ready.
Digital Pin: 14
Analog Pin: 34
=== WIFI CONFIGURATION ===
WiFi credentials loaded from EEPROM
SSID: MyHomeWiFi
✅ Connected to WiFi!
IP Address: 192.168.1.100
✅ Web server started!
Functions: TCRT5000 sensor monitoring, save readings, WiFi configuration
========================
=== DETECTION EVENT ===
Status: LINE/OBJECT DETECTED
Digital: LOW (detected)
Analog: 3245
=== CLEAR ===
Status: No detection
Digital: HIGH (clear)
Analog: 542
Contributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
- Improve documentation
This project is licensed under the MIT License - see the LICENSE file for details.
SimedruF
- GitHub: @SimedruF
- ESP32 Arduino Core Community
- PlatformIO Development Team
- TCRT5000 sensor documentation and community
⭐ If you find this project useful, please consider giving it a star! ⭐