Skip to content

ediiloupatty/Color-LED-Control-OpenCV-Arduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽจ Color Detection & LED Control System

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.

๐ŸŒŸ Features

  • 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

๐Ÿ› ๏ธ Hardware Requirements

Arduino Components:

  • Arduino Uno/Nano/ESP32 (any compatible board)
  • 3x LEDs (Red, Yellow, Green)
  • 3x 220ฮฉ Resistors
  • Breadboard
  • Jumper wires
  • USB cable for Arduino connection

Camera Options:

  • Option 1: Android phone with IP Webcam app
  • Option 2: USB webcam connected to computer

๐Ÿ“‹ Software Requirements

Python Dependencies:

pip install opencv-python
pip install numpy
pip install pyserial
pip install flask
pip install requests

Android App (for IP Camera):

  • Install "IP Webcam" app from Google Play Store

๐Ÿ”ง Hardware Setup

Arduino Wiring:

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

Wiring Diagram:

Arduino Uno    LED + Resistor
Pin 9  -------- Yellow LED ----[220ฮฉ]---- GND
Pin 10 -------- Red LED    ----[220ฮฉ]---- GND  
Pin 11 -------- Green LED  ----[220ฮฉ]---- GND

๐Ÿ“ฑ Camera Setup

Option 1: IP Camera (Android Phone)

  1. Install "IP Webcam" app on Android phone
  2. Connect phone to same WiFi network as computer
  3. Open IP Webcam app and start server
  4. Note the IP address shown (e.g., 192.168.1.100:8080)
  5. Update IP_CAMERA_URL in Python code:
    IP_CAMERA_URL = "http://YOUR_PHONE_IP:8080/video"

Option 2: USB Webcam

  • Simply connect USB webcam to computer
  • System will automatically detect and use it as fallback

๐Ÿš€ Installation & Setup

1. Clone Repository

git clone https://github.com/yourusername/color-detection-led-control.git
cd color-detection-led-control

2. Install Python Dependencies

pip install -r requirements.txt

3. Arduino Setup

  1. Upload the provided Arduino code to your board
  2. Note the COM port (Windows) or device path (Linux/Mac)
  3. Update the port in Python code:
    arduino = serial.Serial('COM3', 9600, timeout=1)  # Change COM3 to your port

4. Configure Camera

  • For IP Camera: Update IP_CAMERA_URL with your phone's IP
  • For USB Camera: No configuration needed

5. Run the System

python app.py

6. Access Web Interface

๐Ÿ“ Project Structure

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

๐ŸŽฎ Usage Instructions

Starting the System:

  1. Connect Hardware: Ensure Arduino is connected and LEDs are wired correctly
  2. Setup Camera: Configure IP camera or connect USB webcam
  3. Run Application: Execute python app.py
  4. Open Browser: Navigate to http://localhost:5000

Web Interface Controls:

  • โ–ถ๏ธ 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

Color Detection:

  • Hold colored objects in front of camera
  • System detects: Red, Yellow, Green
  • Corresponding LEDs light up automatically
  • Real-time feedback in web interface

๐ŸŽจ Color Detection Parameters

The system uses HSV color space for detection:

Red Detection:

Range 1: H(0-10), S(50-255), V(50-255)
Range 2: H(170-180), S(50-255), V(50-255)

Yellow Detection:

Range: H(20-30), S(50-255), V(50-255)

Green Detection:

Range: H(40-80), S(50-255), V(50-255)

Minimum Pixel Threshold:

  • 500 pixels required for color detection
  • Helps eliminate noise and false positives

๐Ÿ”ง Configuration

Arduino Port Configuration:

# Windows
arduino = serial.Serial('COM3', 9600, timeout=1)

# Linux/Mac  
arduino = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)

IP Camera Configuration:

IP_CAMERA_URL = "http://192.168.1.100:8080/video"  # Replace with your IP

Camera Settings:

# 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)

๐Ÿ› Troubleshooting

Arduino Issues:

  • Not connecting: Check COM port, try different ports
  • LEDs not working: Verify wiring, check resistor values
  • No response: Ensure Arduino code is uploaded correctly

Camera Issues:

  • 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

Detection Issues:

  • Colors not detected:
    • Improve lighting conditions
    • Adjust HSV ranges in code
    • Check minimum pixel threshold
  • False detections:
    • Increase pixel threshold
    • Improve color object contrast

Web Interface Issues:

  • Page not loading: Check if Flask server is running
  • Video not streaming: Verify camera initialization
  • Controls not working: Check browser console for errors

๐Ÿ”„ System Flow

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

๐Ÿ“Š Performance

  • Frame Rate: ~30 FPS (adjustable)
  • Detection Latency: <100ms
  • Arduino Response: <50ms
  • Web Interface Update: 1 second intervals

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘ฅ Authors

๐Ÿ™ Acknowledgments

  • OpenCV community for computer vision libraries
  • Flask framework for web interface
  • Arduino community for microcontroller support
  • Color detection algorithms and HSV color space concepts

๐Ÿ“ž Support

If you encounter any issues or have questions:

  1. Check the Troubleshooting section
  2. Open an Issue
  3. Contact: your.email@example.com

๐Ÿ”ฎ Future Enhancements

  • 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 โญ

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published