This project connects a button on an Arduino to a Python script that plays a sound alarm (beep) and blinks an LED when the button is pressed. It's a basic example of how to integrate Arduino hardware with Python for simple I/O interactions.
- Uses a push-button to trigger an alarm.
- Plays a beep sound using the Windows
winsound
module. - Blinks an LED (or activates a buzzer) on the Arduino.
- Python 3.9 or later (Windows only, due to
winsound
) - Arduino board (e.g., Uno)
- Button connected to digital pin 2
- LED or buzzer connected to digital pin 3
- Standard Firmata firmware uploaded to the Arduino
-
Install Python libraries:
pip install pyfirmata
Upload Firmata firmware to Arduino:
Open Arduino IDE.
Go to File > Examples > Firmata > StandardFirmata.
Upload it to your board.
Circuit Setup:
Button between digital pin 2 and GND (use pull-up/pull-down as needed).
LED/buzzer between digital pin 3 and GND (with resistor if needed).
Run the script:
bash Copy code python alarm.py (Replace alarm.py with your filename.)
π₯ How It Works The Python script uses pyfirmata to communicate with the Arduino over USB.
When the button is pressed, the script:
Beeps using winsound.Beep().
Blinks an external LED or activates a buzzer connected to the Arduino.
π§ Notes This script only works on Windows because winsound is a Windows-only module.
Ensure that no other program (like Arduino IDE) is using the COM port while running the script.
You can modify the pin numbers or beep duration to suit your hardware.
π Files alarm.py β Main Python script
README.md β This file
π License This project is free to use and modify.
π Acknowledgments pyFirmata β Python interface for Arduino