Thursday, August 8, 2013

More Solenoid Frustration

Well, I drew a new diagram:
And wired it that way (things spread out):

As soon as I connect the 9V wires the solenoid clicks. Running the program makes no change. Here's my Python code:

import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
Solenoid_pin = 7

GPIO.setup(Solenoid_pin, GPIO.OUT)


for x in range(5): # wait 5 sec
time.sleep(1)
print x
GPIO.output(Solenoid_pin, GPIO.HIGH)
print 'Valve OPEN.'
for x in range(5): # wait 5 sec
time.sleep(1)
print x
GPIO.output(Solenoid_pin, GPIO.LOW)
print 'Valve CLOSED.'
for x in range(5): # wait 5 sec
time.sleep(1)
print x

GPIO.cleanup()

Nothing tricky. I even tested my GPIO pin 7 with an LED -- worked fine.

Comments, anyone?

2 comments:

  1. Hi Dick,
    look at the data sheet for your transistor :)

    You have Collector, Base, and emitter mislabeled on your diagram. You have the solenoid connected to the base so the transistor is always "on".

    ReplyDelete
  2. Also, you might be interested in this capacitive soil moisture sensor. If you coated it in plastic I think it could be quite rugged.

    http://zerocharactersleft.blogspot.com/2011/11/pcb-as-capacitive-soil-moisture-sensor.html

    ReplyDelete