Control an LED with Python on Automation HAT Mini
Prerequisites:
- Pimoroni Automation HAT Mini
- Raspberry Pi (with Raspbian OS and Python installed)
- Standard LED
- Resistor (220 ohm - 1k ohm depending on your LED)
- Jumper wires
Setup:
Connect the LED to your Automation HAT Mini:
- First, connect the anode (longer, positive lead) of your LED to one lead (leg) of the resistor.
- Connect the other lead of the resistor to the 5V or 3.3V Power pin on your Raspberry Pi
- Make sure you have picked a suitable resistor for your LED and power source. E.g., A 470 ohm resistor would typically be okay for a 2V, 20mA LED at a 5V supply.
- Connect the cathode (shorter, negative lead) of the LED to the OUT 1 on the Automation HAT Mini.
Python Script:
Here's a simple Python script that will use the Automation HAT's library to control your LED:
This script will blink the LED on and off, spending one second in each state.
Running the Script:
- Save the python script on your Raspberry Pi.
- Open terminal and navigate to the directory containing the script:
cd greenwise
Now you can run the script, if your script was named led_control.py for example, you would use:
python3 led_control.py
The LED connected to the Automation HAT Mini should now be blinking every second!
Reminder: Always double-check your connections and ensure you are working within the voltage and current ratings for your particular components.
Always be careful when working with electricity.
Funded by the European Union. Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Education and Culture Executive Agency (EACEA). Neither the European Union nor EACEA can be held responsible for them.
Project Number: 2023-3-CY02-KA210-YOU-000173087