A project to control LEDs on an Arduino UNO R3 using Python.
This repository contains an Arduino sketch (.ino) and a Python script (.py) that allows the user to turn two LEDs on and off via input.
- Arduino UNO R3
- 2 LEDs
- 2 resistors (220Ω recommended)
- Breadboard and jumper wires
- Arduino IDE
- Python 3.x
pyseriallibrary (pip install pyserial)
- Open
led_control.inoin the Arduino IDE. - Connect LED1 to pin 8 and LED2 to pin 9 (with resistors in series).
- Connect Arduino to your PC via USB.
- Upload the sketch to the Arduino.
- Open
led_control.py. - Make sure the
portvariable matches your Arduino COM port:arduino = serial.Serial(port="COM3", baudrate=9600, timeout=1)
- On Windows:
COM3,COM4, etc. - On Linux/macOS:
/dev/ttyUSB0or/dev/ttyACM0.
- On Windows:
- Install pyserial if not already installed:
pip install pyserial
- Run the Python script:
python led_control.py
- Enter your choice:
1→ Turn on LED12→ Turn on LED23→ Turn on LED2, LED10→ Turn off both LEDsq→ Quit the program