Component
Pin 1
Pin 2
Code Overview, Code Overview, Compile and run
Let's walk through our code: we setup the switch pin to GPIO17 as GPIO.IN because we receive input from the ball
switch whenever he close the circuit by tilting it or not. Then we go for while loop (forever) and print "BALL is HIGH"
if it's closing the circuit or "BALL is LOW" if not. You can tilt the ball switch around to see the data changing.
Compile the script by going into the samples directory and running: python3 ball_switch.py
Raspberry Pi
GPIO17
3V3
20 of 114
Need help?
Do you have a question about the Raspberry Pi & Arduino Starter Kit and is the answer not in the manual?