Urgent beginner Question, please help..

Hello everyone,

My name is Jeff, a very new beginner for Arduino who urgently and desperately needs your help for a project. I would really appreciate your kindness if you can help me on this (I am sure it's really simple for you pro guys..):

In my project, I need to control a 3/2-way solenoid valve and a servo together, more precisely I need to synchronize the two parts. The 3/2-way means when the valve is closed, flow will go into the valve from gate A and come out from gate B. When the valve is open, flow will go into the valve from gate A and come out from gate C and subsequently be discharged through a nozzle. The nozzle can be open and closed controlled by a servo. So, what I want to achieve is that when the valve is open, the nozzle must be open simultaneously as well, and vice verse.

My question is that:

1). Based on my description, it this synchronization of two parts possible by using Arduino ? And basically how to do it especially the code (I only know how to control servo)...

2). By watching Youtube, I think I am confident to control the servo, but there is no detailed tutorial about controlling solenoid valve (including setup & especially the code). Anyone could give me a link (or even email me with a code sample ~~~~) to learn how to control a solenoid valve ?

If anyone could give me a hand on this, that will be really fantastic and save my day... Thank you very much.

Kind Regards,
Jeff

That's the water equivilent of a printer A/B switch (one PC, two printers , or One printer, 2 PCs , either way, three connections
one In ,2 out , or two In , one out.

How you control the "3/2-way solenoid valve"? by DC voltage(DC12V /24V) or AC voltage?(AC 110V/230V) how much current?
Please provide datasheet for the solenoid valve.

Be it DC or AC, you can use relay to control them.

or if it is DC solenoid, you can control it with transistor, MOSFET, etc
http://playground.arduino.cc/Learning/SolenoidTutorial

If the solenoid goes to gate C and the nozzle is closed, how bad would that be? The reason I ask is because if that would be a really bad situation, you should have a mechanical interlock, so it's impossible to switch to gate C without opening the nozzle. Is there a back-flow issue? Why not just leave the nozzle open all the time?

Controlling a solenoid valve will be done with a relay or transistor... it's not that hard, but your valve is a little special, so we need specs about how it's wired.

This solenoid for example, is really easy to use. All you do is put 12V across it and it will open. That's easy to do with relays.

How big is this valve and what size servo are you planning to use to control it ?

BillHo:
How you control the "3/2-way solenoid valve"? by DC voltage(DC12V /24V) or AC voltage?(AC 110V/230V) how much current?
Please provide datasheet for the solenoid valve.

Be it DC or AC, you can use relay to control them.

Arduino Playground - HomePage
http://www.instructables.com/id/Connecting-a-12V-Relay-to-Arduino/?ALLSTEPS

or if it is DC solenoid, you can control it with transistor, MOSFET, etc
Arduino Playground - HomePage

For a cheap trial prototype, I will use DC12V, in real setup I will use 230V AC 50 Hz. It does not state the current running in the valve, only power consumption: Inrush (don't know what the term means) AC[VA] 30 or AC[VA/W] 15/8. I have asked the supplier which one I should use.

Thank you very much for your help, I will read those first and maybe ask you more questions if you don't mind :slight_smile:

Regards, Jeff

I think this has already been well answered.
If I may add a little direction also.

It sounds like you have 2 questions
1 - How to use a solenoid.
2 - how to programme this. (I think this has already been talked about).

As for 1 I would like to point you to... It's a really neat tutorial. I think you'll find it useful.
http://www.ecs.umass.edu/ece/m5/tutorials/tip122_transistor_tutorial.html

Of course the implementation of this all depends on the exact components your using (voltage and amps).
If your a beginner I would recommend a Tip122. It's a great general purpose device and rather forgiving.

Don't forget that fly back transistor on any coil based device (motor, fan solenoid, servo etc). I would put that diode, rather than on the coil, on the transistor between pin 2 and 3 with ground on pin 2.

If this is your first motor/solenoid welcome to the rabbit hole. You are about to get into the really cool things an Arduino can do.

More to come.

30 VA INRUSH means = about 2.5A at 12V . The 15/8 means 1.25A at 12V . So basically what it is saying is that for a brief moment,
when it is turned on the inrush current is more than double the current after the inrush. Once it is on it draws just under an amp.
(700mA)

I've just been reading the new information. if your solenoid is AC... That's a different method... you want to use a relay after the transistor to allow that. But still a general purpose npn transistor is a great way to start. particularly in that 12v dc environment.

jasmine2501:
If the solenoid goes to gate C and the nozzle is closed, how bad would that be? The reason I ask is because if that would be a really bad situation, you should have a mechanical interlock, so it's impossible to switch to gate C without opening the nozzle. Is there a back-flow issue? Why not just leave the nozzle open all the time?

Yes, my nozzle is special :slight_smile: It has to be in this way, the valve serves a distribution purpose, when flow comes out from gate C, the nozzle opens and fluid is discharged. After a finite time (e.g. 3.2 seconds) the valve is closed and nozzle is closed simultaneously for 2 main reasons: 1. stop any residuals in the pipe from being discharging out. 2. nozzle is inclined at an angle to the horizontal.

Controlling a solenoid valve will be done with a relay or transistor... it's not that hard, but your valve is a little special, so we need specs about how it's wired.

This solenoid for example, is really easy to use. All you do is put 12V across it and it will open. That's easy to do with relays.

[/quote]

Can I ask if the relay = transistor ? Sorry I am a noob on electronics, I know more about fluid mechanics..

Can I ask if the relay = transistor ? Sorry I am a noob on electronics, I know more about fluid mechanics..
[/quote]

These are 2 different things.

A transistor is a silicon based device... really only useful for DC. It turns on and off really fast! (has 3 legs).

A solenoid is more like a manual switch it has 4 legs. 2 legs power the electro-magnet and then holds the button on. 2 legs for the 'output' of the button). A solenoid will do AC... HIGH voltage... HIGH current. but they are SLOW compared to transistors.

Does that make sense (perhaps not)?

raschemmel:
30 VA INRUSH means = about 2.5A at 12V . The 15/8 means 1.25A at 12V . So basically what it is saying is that for a brief moment,
when it is turned on the inrush current is more than double the current after the inrush. Once it is on it draws just under an amp.
(700mA)

Thank you for quick reply, amazingly I am not alone at 2:18 am (well unless you are not in Europe~). Can I ask how you work it out ? Is it not P=VI ? e.g. 30=230I so I=130 mA. Ok, so if I run 230V AC, then I can't use transistor, if I run 12V then transistor is good, am I getting this right ?

Regarding to the code, a few more newbie questions here:

1). To write the code to control the valve, I have to know the amp and frequency of the valve right ?

2). If I have one working code for the valve, one working code for the servo (small servo, used at RC jet..), can I simply copy and paste the two codes one after the other to form a new code ? Or I have to modify them both ?

3). In my application, I don't need the valve to repeat each cycle, for example, both valve and servo delay for 3 seconds from beginning, then start together for 3 seconds then all stop. In other words I am doing discrete releases. So I assume that I just don't need the 'loop' word whilst rest will be the same ?

Thank you for helping me here.

Regards, Jeff

Jeff27:
Can I ask if the relay = transistor ? Sorry I am a noob on electronics, I know more about fluid mechanics..

These are relays

This is the circuit that transistor control the relay

These are Transistors


Jeff27:
2). If I have one working code for the valve, one working code for the servo (small servo, used at RC jet..), can I simply copy and paste the two codes one after the other to form a new code ? Or I have to modify them both ?

Eh... you trying to start a religious war? I'm gonna say NO... don't just copy and paste code. Understand it first. Understand every detail of the code, that's how we learn. Don't use any code if you don't know everything it does. I'm really experienced and I posted a question about that today. Some code I'm using is doing something I didn't expect, and I didn't understand why. I refuse to proceed until I understand what is happening.

So really, use those sketches as examples and yes, use the copy/paste function to save you some typing, but don't use copy/paste to save you from writing code. Never use any code that you don't understand. You're going to need to mix this stuff together in a special way anyway, so it's not like you can just mash the two existing programs together. You're going to need to interleave the logic in a way that makes the Arduino do what you want.

3). In my application, I don't need the valve to repeat each cycle, for example, both valve and servo delay for 3 seconds from beginning, then start together for 3 seconds then all stop. In other words I am doing discrete releases. So I assume that I just don't need the 'loop' word whilst rest will be the same ?

You can't get rid of the loop function. The way the Arduino works with sketches requires that. It sets up the runtime environment, then it initializes your program (sets up globals and all that), then it calls the "setup()" function and expects that to 'return/terminate' at some point, then it calls the loop function over and over again forever. That's how ALL Arduino programs work, so you need to do things in the loop function.

Here's a video explaining why we have a loop, how to use it, and why you don't want to block it, and why an Arduino program doesn't start and then exit like programs on your desktop. BTW - you're not attempting this advanced project without having done the examples, are you???

So, what's gonna happen here is, most of the time your Arduino will be sitting there doing nothing. The loop will run, it will do nothing, it will exit, and the Arduino will run the loop again. It will check a million times if it needs to open the valve and eventually the time will come, and it will open the valve and then it will go back doing nothing really fast until it's time to close the valve again. Most of the time, Arduinos do nothing really, really fast, over and over again.

Swmitchell:
Don't forget that fly back transistor on any coil based device (motor, fan solenoid, servo etc). I would put that diode, rather than on the coil, on the transistor between pin 2 and 3 with ground on pin 2.

Thank you for the reply, although I don't get the detail you suggested, but I will try to assemble it using 12V DC solenoid valve, and maybe I can understand more when I am doing it :slight_smile:

Jeff27:
I don't get the detail you suggested

Yeah, that's why you need to do the examples. You don't need to build all of them, but you need to understand them. The example showing how to use a relay explains the flyback diode. When the coil from the electromagnet in your relay shuts down, the stored energy comes out of that coil, and you don't want it to go back into the Arduino or someplace where it's gonna cause a problem. With the diode there, that stored energy has only one direction to go. It's like using a one-way valve to prevent back-flow from a pump when it stops.

You're going to need to mix this stuff together in a special way anyway, so it's not like you can just mash the two existing programs together. You're going to need to interleave the logic in a way that makes the Arduino do what you want.

Hehe~ I agree that you should know the code before you run it. I run Matlab and yes always understand the codes then make your own. Reason I asked 'copy and paste' is because by watching the servo control on Youtube, I got a feeling that Arduino code maybe is not difficult, then only need a little twist to combine the servo and solenoid. But if you clearly said I need to modify and mix the two codes together, then I will have to take time to learn it.. Btw, is there any example of this kind of mixture control of different motors & solenoid ?

You can't get rid of the loop function...
https://www.youtube.com/watch?v=3VZgaJBrZD8

Thank you for the source, I will learn from it, that's why I like Youtube :smiley: :smiley:

Kind Regards, Jeff

jasmine2501:

Jeff27:
I don't get the detail you suggested

Yeah, that's why you need to do the examples. You don't need to build all of them, but you need to understand them. The example showing how to use a relay explains the flyback diode. When the coil from the electromagnet in your relay shuts down, the stored energy comes out of that coil, and you don't want it to go back into the Arduino or someplace where it's gonna cause a problem. With the diode there, that stored energy has only one direction to go. It's like using a one-way valve to prevent back-flow from a pump when it stops.

Yes, the more I keep reading the better I understand it...Thank you for explaining those, for a 12V DC solenoid valve, now I will think and decide what transistor and diode I will buy together... :frowning: :roll_eyes:

BillHo:

Jeff27:
Can I ask if the relay = transistor ? Sorry I am a noob on electronics, I know more about fluid mechanics..

These are relays....

Thank you for explaining those to me. I certainly need to learn more about electronics....Ugrrr, didn't really expect my project will go this far. So, for a 12V DC solenoid valve (I will buy from Amazon), any good recommendation for transistor, diode and battery please ?

Best wishes, Jeff

Jeff27:

BillHo:

Jeff27:
Can I ask if the relay = transistor ? Sorry I am a noob on electronics, I know more about fluid mechanics..

These are relays....

Thank you for explaining those to me. I certainly need to learn more about electronics....Ugrrr, didn't really expect my project will go this far. So, for a 12V DC solenoid valve (I will buy from Amazon), any good recommendation for transistor, diode and battery please ?

Best wishes, Jeff

IMO, you should probably use a relay for this. A transistor and a relay are both switches than can be controlled by an electrical signal. The transistor is exceptionally fast at switching, but it doesn't carry a lot of power. The relay is a mechanical switch operated by an electromagnet, so it can carry as much power as it's rated for. ANY switch of any size can be operated this way, so you'll see lots of different types of relays available. You need one that can handle whatever your solenoid is using. BTW, a solenoid is also a 'switch' operated by an electromagnet, but it's not switching electricity, it's typically switching a pressurized fluid such as water, gasoline, or air.

The word solenoid actually refers to the magnet...