Hi
Can you tell me how to make the connections, and the code, to light an LED using a push button? I have a Raspberry Pi 4
Using a push button to turn on an LED
1 Raspberry Pi 4
1 normally open button
1 LED
1k ohm resistor
Wiring
Insert the LED into the Breadboard paying attention in which row you insert the longest leg (positive pole). The shorter leg connects to the blue rail using a male-male cable.
Insert the resistor so that one of its ends is in the row of the positive pole of the LED (see image). Connect the other end to GPIO pin 24 using a male-female cable.
Insert the button in the middle of the breadboard. Then connect one of the legs to GPIO pin 18. The other to the blue rail.
Connect the blue rail to the GND pin.
Script
from gpiozero import LED, Button from signal import pause led = led(24) button=Button(18) button.when_pressed=led.on button.when_released=led.off pause()
Save the script by clicking Save, and then run it by clicking Run. Finally press the button and check that the LED lights up.