Posts: 1
Joined: Tue Jun 11, 2013 3:07 am

Help Needed: Python Water Drop Photography Script...

Sun Dec 01, 2013 10:31 am

Hi Guys

I have build a water drop rig that is supposed to trigger the camera shutter as soon as a water droplet breaks a laser beam. The event starts with the push of a button (PIN25IN) which in turn triggers a solenoid valve (PIN23OUT) that will release 1 or 2 droplets. (The time between the drops will be determined as I get the rig working). The 1st water drop will break a laser beam that will trigger a switch (PIN18IN) which will release the camera shutter (PIN8OUT).

Problem I am having with my script below is that the solenoid stays open for too long on drop number 2. This seems to be caused by the delay (sleep(0.5) I am trying to write in to have the camera shutter only trigger once.

Please look at my script below and advise why my GPIO8 delay will have an effect on my 2nd droplet timing on the solenoid valve.

GPIO25 - IN - Push-Button
GPIO23 - OUT - Solenoid Valve
GPIO18 - IN - Laser Water Drop Trigger
GPIO8 - OUT - Camera Shutter Release Cable

This is the script I m using:

I have the following script:

GPIO Pin 1: In

from time import sleep
import RPi.GPIO as GPIO
GPIO.setup(23, GPIO.OUT)
GPIO.setup(18, GPIO.IN)
GPIO.setup(8, GPIO.OUT)
GPIO.setup(25, GPIO.IN)

while 1:
if GPIO.input(25):
print'2 Drops Released'
GPIO.output(23, True)
GPIO.output(23, False)
GPIO.output(23, True)
GPIO.output(23, False)

if GPIO.input(18):
print'Shutter Released'
GPIO.output(8, False)
GPIO.output(8, True)

Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: Help Needed: Python Water Drop Photography Script...

Tue Dec 03, 2013 3:49 am

You could put both of your events (watching the button and watching the photodetector) in functions and have the GPIO library run them automatically using the GPIO.add_event_callback function: ... iki/Inputs. When the specified GPIO pin is pulled high or low, the GPIO library will run the function in a separate thread, allowing both to run at the same time.

You might also want to look at the debouncing feature to prevent too many drops from being released when the button is pushed.

Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Help Needed: Python Water Drop Photography Script...

Wed Dec 04, 2013 3:23 pm

Please, please, please use the Code tabs when posting code - you have lost all of the python formating, which is essential for people to copy your code to try it out ;)

Some time ago David Hunt devised an alternative method for water drop controlling. There is no need to detect when the water cuts a beam of light - just experiment with the delay between releasing the drops and when you need to take the photo. See this page :

Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):

Return to “Python”