A real-time color detection system that uses computer vision to detect red, yellow, and green colors from a camera feed and automatically controls corresponding LEDs connected to an Arduino board.
- Real-time Color Detection: Uses OpenCV and HSV color space for accurate color detection
- Arduino LED Control: Automatically controls RGB LEDs based on detected colors
- Multiple Camera Sources: Supports both IP cameras (Android phones) and local webcams
- Web Interface: Modern, responsive web interface with glassmorphism design
- Manual Control: Override automatic detection with manual LED control
- Live Video Streaming: Real-time video feed displayed on web interface
- Status Monitoring: Live status updates of detection state and current color
- Arduino Uno/Nano/ESP32 (any compatible board)
- 3x LEDs (Red, Yellow, Green)
- 3x 220ฮฉ Resistors
- Breadboard
- Jumper wires
- USB cable for Arduino connection
- Option 1: Android phone with IP Webcam app
- Option 2: USB webcam connected to computer
pip install opencv-python
pip install numpy
pip install pyserial
pip install flask
pip install requests- Install "IP Webcam" app from Google Play Store
LED Connections:
- Yellow LED โ Pin 9 (with 220ฮฉ resistor)
- Red LED โ Pin 10 (with 220ฮฉ resistor)
- Green LED โ Pin 11 (with 220ฮฉ resistor)
- All LED cathodes โ GND
Arduino Uno LED + Resistor
Pin 9 -------- Yellow LED ----[220ฮฉ]---- GND
Pin 10 -------- Red LED ----[220ฮฉ]---- GND
Pin 11 -------- Green LED ----[220ฮฉ]---- GND
- Install "IP Webcam" app on Android phone
- Connect phone to same WiFi network as computer
- Open IP Webcam app and start server
- Note the IP address shown (e.g., 192.168.1.100:8080)
- Update
IP_CAMERA_URLin Python code:IP_CAMERA_URL = "http://YOUR_PHONE_IP:8080/video"
- Simply connect USB webcam to computer
- System will automatically detect and use it as fallback
git clone https://github.com/yourusername/color-detection-led-control.git
cd color-detection-led-controlpip install -r requirements.txt- Upload the provided Arduino code to your board
- Note the COM port (Windows) or device path (Linux/Mac)
- Update the port in Python code:
arduino = serial.Serial('COM3', 9600, timeout=1) # Change COM3 to your port
- For IP Camera: Update
IP_CAMERA_URLwith your phone's IP - For USB Camera: No configuration needed
python app.py- Local: http://localhost:5000
- Network: http://your-computer-ip:5000
color-detection-led-control/
โ
โโโ app.py # Main Python application
โโโ arduino_code.ino # Arduino LED control code
โโโ templates/
โ โโโ index.html # Web interface template
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
โโโ images/ # Screenshots and diagrams
โโโ setup_diagram.png
โโโ web_interface.png
โโโ hardware_setup.jpg
- Connect Hardware: Ensure Arduino is connected and LEDs are wired correctly
- Setup Camera: Configure IP camera or connect USB webcam
- Run Application: Execute
python app.py - Open Browser: Navigate to http://localhost:5000
โถ๏ธ Start Detection: Begin automatic color detection- โน๏ธ Stop Detection: Pause automatic detection
- ๐ฎ Manual Control: Override with manual LED control
- ๐ด Red LED
- ๐ก Yellow LED
- ๐ข Green LED
- โซ Turn Off All
- Hold colored objects in front of camera
- System detects: Red, Yellow, Green
- Corresponding LEDs light up automatically
- Real-time feedback in web interface
The system uses HSV color space for detection:
Range 1: H(0-10), S(50-255), V(50-255)
Range 2: H(170-180), S(50-255), V(50-255)Range: H(20-30), S(50-255), V(50-255)Range: H(40-80), S(50-255), V(50-255)- 500 pixels required for color detection
- Helps eliminate noise and false positives
# Windows
arduino = serial.Serial('COM3', 9600, timeout=1)
# Linux/Mac
arduino = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)IP_CAMERA_URL = "http://192.168.1.100:8080/video" # Replace with your IP# Resolution
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
# Frame rate
cap.set(cv2.CAP_PROP_FPS, 30)- Not connecting: Check COM port, try different ports
- LEDs not working: Verify wiring, check resistor values
- No response: Ensure Arduino code is uploaded correctly
- IP Camera not connecting:
- Verify phone and computer on same WiFi
- Check IP address is correct
- Test URL in browser first
- USB Camera not detected:
- Try different USB ports
- Close other camera applications
- Check camera permissions
- Colors not detected:
- Improve lighting conditions
- Adjust HSV ranges in code
- Check minimum pixel threshold
- False detections:
- Increase pixel threshold
- Improve color object contrast
- Page not loading: Check if Flask server is running
- Video not streaming: Verify camera initialization
- Controls not working: Check browser console for errors
1. Camera captures frame
โ
2. Convert BGR to HSV color space
โ
3. Apply color masks for Red/Yellow/Green
โ
4. Count pixels for each color
โ
5. Determine dominant color (if > threshold)
โ
6. Send command to Arduino
โ
7. Arduino controls corresponding LED
โ
8. Update web interface status
- Frame Rate: ~30 FPS (adjustable)
- Detection Latency: <100ms
- Arduino Response: <50ms
- Web Interface Update: 1 second intervals
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Your Name - Initial work - YourGitHub
- OpenCV community for computer vision libraries
- Flask framework for web interface
- Arduino community for microcontroller support
- Color detection algorithms and HSV color space concepts
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Open an Issue
- Contact: your.email@example.com
- Support for more colors
- Mobile app for remote control
- Machine learning based color detection
- Multiple Arduino board support
- Data logging and analytics
- Voice control integration
- Gesture recognition
โญ pengolahan citra kelompok 2 6ti5 โญ