Using BASIC stamp with electric solenoid valve, need help
Hi, my group and i are trying to build a water cooler that dispenses water using a motion sensor. The whole device has to be run using a Parallax BASIC Stamp 2, and we're having trouble figuring out how to program our water valve using the stamp. The valve is a EHCOTECH electric solenoid valve, 12V with 500mA. The BASIC stamp 2 can have a maximum of 5V running through it, so we're thinking we need a transistor.
Any ideas on how to program the water valve using the stamp, circuit models, or any general advice is welcome!
Also i can be reached by email at peavlerk123@gmail.com
thanks in advance!
Any ideas on how to program the water valve using the stamp, circuit models, or any general advice is welcome!
Also i can be reached by email at peavlerk123@gmail.com
thanks in advance!
Comments
Hi peavlerk, Welcome to the Forums :thumb:
I'll let some of our Amazing Forumistas speak up on the how and the specifics, but you'll need to connect some sort of transistor to supply that much energy to your solenoid. I'm partial to a type of transistor called a MOSFET - I have piles of IRF511's in my junk drawer. The transistor will take the little signal (from the Stamp) and turn on the high-powered solenoid by connecting its three pins in a particular way....
But there's lots of other methods too. Let's see what some of these are...
-MattG
You'll need a transistor and a relay to drive the 12v 500mA solenoid valve. There are actually a lot of ways, but here's one of the easiest. You can use any general purpose NPN transistor for the schematic I am using below. A 2N2222 would work perfectly. Be sure to include the diode across the relay coil since relay coils, when de-energized, have a big reverse-polarity spike that can kill your driver transistor otherwise.
Connect your solenoid to the 12v supply through the contacts of the relay, and connect the base of the transistor to the Basic Stamp via a small resistor, like 220 ohms. You'll want to have the pin you connect to the transistor be LOW when you want the solenoid off, and HIGH when you want the solenoid on.
Let me know if this was helpful and welcome to the forum! There's a lot of very helpful folks here who love this kind of stuff.
Dave
PS., Matt's MOSFET is a great suggestion as well, I'm just guessing that you're more likely to have a general purpose NPN transistor laying around than a MOSFET :-)
Thanks again!
Assuming you have the above mentioned items and know how to use them, you'll want to set up the pin that you have connected to the driver for the solenoid in your program. Let's say you have the driver connected to pin 1, and you want to call it by the name "Valve" in your program. Your code would contain the following:
Now later in the program, you'd set your Valve to LOW when you want tthe valve to be off, and HIGH when you want it to be on. Here's a paracode example:
Let us know how familiar you are with PBasic, or if you're starting COMPLETELY from scratch, and we can go from there.
Dave
We do have the cable to program the stamp, and we have used the Editor before, but only in a class, and even then it wasn't very extensive. Just to make sure that we understand completely, just assume that we have never used the editor, and I apologize for the inconvenience this may cause! So yes we have the required program and cable to do it, we just dont have the know-how.
Thanks again for all the help you've already given, and for any future advice!
First, you'll need to start the Basic Stamp Editor. Once it's up, you'll have a blank screen that has a tab at the top called "Untitled1".
So to get you started, copy and paste this code into that window:
Save that file as ValveControl.bs2, and load in (Control R) into the stamp (make sure your programming cable is hooked up and the stamp is powered on, etc).
Now power down your stamp. Make and hook up the valve control circuit I showed you in the previous post. Be sure to hook up the base of the 2N2222, through the 220 or 330 ohm resistor, to IO pin 1 (actual pin 5 I believe, but check the manual. If you don't have the manual, in the editor, look at the top toolbar (File, Edit, Directive...), and click Help, then Basic Stamp Manual (PDF). There you'll find the whole BS2 universe opened up to yo ufor the asking.)
Then, take a momentary pushbutton switch, hook up a 330 ohm resistor to IO pin 2 (probably pin 6 on the chip), one leg of the momentary pushbutton to the other end of the resistor, and the remaining leg of the pushbutton to your +5v supply line (the same +5v that supplies the stamp. *** Be careful - if you're using a board that it powered by a 9v battery, or an external power supply, use the Vdd line, not the Vin line!!! If in doubt, measure it with a meter!)
You may also want to put a 10k resistor between the Sense pin (IO2) and Ground, to prevent a false high reading.
Now once you've hooked up those connections, and you've checked it several times, carefully, slowly, and preferably by multiple people, then power your Stamp board back on.
If you've hooked it all up correctly (and I haven't made any mistakes in my directions), the valve should activate whenever you push the button, and release whenever you let the button go.
Let me know if that worked or not.
Tomorrow, we'll either troubleshoot what went wrong (by the way, do all this AT YOUR OWN RISK. I'm not responsible if you cook your BS2, or yourself, or your neighbor's toaster...) -OR - if it works, we'll go over how to change it from a manual switch being pushed, to it reading whatever you're using for motion/proximity/distance sensors.
This stuff - once you get the basics - is immensely fun. There is almost no limit to what you can get microcontrollers to do, and you'd be surprised at how fast you can come up to speed on these things, and the levels of complexity you can achieve in a short time.
So take your time, be careful, pay attention to details.... and have fun. You're in for a fun ride!
Let me know how you make out with the above instructions.
Dave
Actually, yes, that is kind of a stiff load for a 2N2222 now that I think about it!
... but I will provide a link.
http://www.radioshack.com/product/index.jsp?productId=2062478
It includes code and a schematic. Pin 7 is labelled Solenoid and all the code that reference that label either opens or closes the valve.
Not sure about the PING))) as I've never had need to use it. But... curiosity got the better of me, so... here's the first example code from the parallax store page for the PING:
Now if it were ME, the first thing I'd probably do is just run the above code to see it work. If it did... I'd then add an IF-THEN statement, using inches as the reference, and say something like if inches <= 6, then HIGH pin-that-controls-relay-for-solenoid, ENDIF
I'd also probably add a time-on hold function, so that if the relay gets triggered, it stays triggered for at least a second or something.
I might also add a counter routine so that the PING has to report at least two polling cycles where inches is <= 6 before trigerring the relay, to help avoid false detections, and I might drop th ePAUSE from 500 to maybe 250.
But there are a LOT of PING users on here with ACTUAL experience using these items, so they may have different and better advice... keep us posted!
Dave