Code: Select all
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(12, GPIO.IN) #sensor1 GPIO.setup(16, GPIO.IN) #sensor2 GPIO.setup(20, GPIO.IN) #sensor3 GPIO.setup(21, GPIO.IN) #sensor4 while True: if GPIO.input(12) == 1: print ("sensor 1 triggered") if GPIO.input(16) == 1: print ("sensor 2 triggered") if GPIO.input(20) == 1: print ("sensor 3 triggered") if GPIO.input(21) == 1: print ("sensor 4 triggered") time.sleep(0.1)
nextguy wrote: ↑Sun Aug 11, 2019 12:05 pmBrilliant thank you so much for your help. Although I understood maybe only 70% of what you wrote, it is a very solid start for my project. I was doing more research since my original post and thought that maybe I would have to put an Arduino board between the sensors and the Pi. So it sounds like if I can find 3.3v sensors then this is an unnecessary step.
Another question, when connecting the sensor pins to the gpio inputs, should I just use a jumper wire? The distance between the sensors and the Pi will probably be a good 10 feet to avoid accidental damage.
Also not sure if you or someone else can answer this, but knowing my use case, is the sw420 vibration sensor a suitable sensor? As mentioned, I will have targets that need to detect an impact. I think I would need to play with thresholds to only trigger on the initial contact and ignore aftershocks. Is there a more appropriate piezoelectric sensor that could do this?
My application is more for athletic training than for amusement. I want the targets to light up only after the previous target has been hit. And only the lit target is scored. I imagine having a display that shows the time it takes between target lighting to target hit, generate stats such as average time, and my ultimate would be to have a speed gun. But that is pie in the sky thinking for now.
No that's not what I want at all. I was just asking if I was choosing the right parts and to help understand how the wiring would work. My last post about the nature and function of my project was only in response to your previous post. I am good now and I am not requesting anymore advice unless someone wants to offer it.