 In the last video, I showed you how to use this 24 volt pump, how it works, how to write the code for it, how to connect the tubing, and how to move water from one bucket to another without using your hands at all. In this video, we're going to be adding one more step to this project. We're going to be adding this water valve solenoid. We're going to go over how this water valve solenoid works, how to set it up with tubing, how to wire it up, and how to code it so that we don't have to use our hands to control it. One thing before we get started, if you do like these videos, please do me a favor and subscribe to the channel, because for some reason, 98% of people who watch these videos don't stay for the next one. So let's change that number. A water solenoid is a special type of valve that uses electricity to control the flow of water. Water goes in through one side, comes out through the other, and using electricity, you can block the flow. This right here is just a regular solenoid. It doesn't connect to any type of water compartment, it's just on its own a solenoid. There's a big piece here with a bunch of wiring around, and then there's some cables that go to those wires to create a magnetic field. And when there's a magnetic field, we can move this rod in and out without using our hands. While a water solenoid works the same way, this is actually right over here. So you can see there's this little piece of plastic here for the water components, and then the solenoid right here, and that would go like this. So it pushes in and out, and you can see that by the top here. Now we're going to take it apart quickly so you can see what I'm talking about. So once we take the actual solenoid off, we're left with this part. This contains everything we need to block the flow of water. When you take this off right here, be careful that nothing pops off. We have a couple different pieces. First we have this, which seals the water from the electricity, because the solenoid gets direct electricity inside here where the magnet is. As you can see, these are 12 volt connections, and then that goes to a power supply. So this we do not want water touching. Then inside the plunger, we have a spring for this, which is the magnetic piece that moves back and forth, depending on if there's electricity or not. Then under the plastic seal and the piece inside of it, the magnet that moves back and forth, we have this. This is the actual plunger that when you push down, it blocks the flow of water, and when you open it, it lets it through. So water flows in through one side and comes out the other. But if there's electricity pushing this piece down on the plunger, like this, the water is going to be blocked across. And then as long as the solenoid is strong enough to hold this piece, water will never flow through. But I'm guessing we're probably going to run into this problem later on. When water flows through at a certain pressure, this will not be able to hold the water anymore, and the water will flow out no matter what. But we're going to give it a try. So let's put it back together. The spring goes in there. Metal piece goes in there. Make sure it's all lined up perfectly like this. Push down on that. And then our solenoid fits like this. There's arrows all over it to show you how it should go in. And then we just got to put the screws back on. And that's our water valve solenoid. Now one key thing that you should know about the solenoid versus the water pump, think of the solenoid like a traffic light, and the water is the cars in traffic. Cars are going in all sorts of direction, and you want to control the flow of the traffic using something like a solenoid. So a solenoid in this system is like a red light and then a green light. When it's closed, it's a red light. When it's open, it's a green light. So we could decide if we want flow to go through or not. So if I was to place it on our system in the middle here, we can close it and water should not flow over to the other side. And then we can open it and water should flow to the other side as long as the pump is on. So let's get started with the demo. So to build this out, we're going to need a couple of different parts. First off, the solenoid, some PEX tubing, an adapter which is going to take us from PEX to a smaller line, a relay and some wires, and some of that small tubing for the solenoid since it's not made for PEX. So we're going to be cutting in the middle of these two buckets. So I've already sliced one here. I'm going to slice again here. We're going to bring it down to the table and that's where we're going to run the solenoid. Just going to squeeze that on there. Okay, now we have an elbow pointing back down and squeeze that on nice. All right, so now we have our pump connected to a couple of elbows bringing it down to the table. Now from the table, we're going to be connecting the adapters and the solenoid and then pumping the solenoid into this second cup on the other side of the screen. See right here and right here, there's arrows pointing the direction of where the water flow should go so it should be going like that. So we're going to take our water solenoid, we're going to plug it into the quick connect as tight as we can. So we have pump, tubing, down to the table. At the table, we go elbow into PEX, PEX into tubing, tubing into solenoid and solenoid into the next bucket with the super skinny tube. So from last time we have this white cable, which is for a power supply that turns or that powers the pump. And then right here we have a blue relay which connects the power supply and the pump together. And then we can control that relay using our code and the Arduino. Now we're going to need to set up our electronics for the solenoid. So here I have a 12 volt power supply that I'm going to be using on the side just like we did for the pump. This power supply like always has a red and black cable. Those are positive and negative. So first off, let's start by plugging in our relay into the Arduino. To do that, we're going to need three different cables, one for ground, one for positive right in the middle, and then one for signal. One thing I forgot to mention is the Arduino only has one 5 volt port and we're going to be using multiple 5 volt devices. So since we're not going to be creating cables that split and do all mess like that, we're going to be using a breadboard. On a breadboard, you can use a row of slots for the same power source. So we're just going to grab a second set of cables. We're going to be unplugging the pump relay. We're going to just plug in 5 volt and ground and then put those on the breadboard like this. All right, now we're going to just plug in the relay from the water pump. 5 volt into 5 volt, ground into ground. Now we're going to be connecting up the relay for the solenoid pump. What we want to do is we want to connect the power source for the solenoid and the actual solenoid together and put a relay in the middle just like we did for the water pump. It's the same exact situation. Power source, the item we're powering, and in the middle we're going to put a relay. So I have my relay right here. I'm just going to plug in the cable here. So we have ground, we have power, and we have signal. Ground will be going into ground like this. Then power will be going into power like this. And then this blue cable right here is our signal cable. And that's going to be going into pin number 3 on the Arduino. We used 4 for the water pump. We're going to be using 3 for the solenoid. Let's keep it simple like that. Now let's do the same wiring setup that we did for the pump and let's make sure we don't make the same mistake where we used normally closed instead of normally opened. This is our negative. Our negative will be going to the negative of the power source like before. And I'm just going to grab some shrink tubing and do like last time. So it's nice and sealed with water. So we're just going to take the red wire from our power supply and we're going to put it in the bottom one of the relay. Make sure your relay says which port it is so you don't use the wrong one. Mine it's the bottom one. Now we're going to take the power line from the solenoid and we're going to stick it in the middle. The middle it's the COM port. Looks like it's a bit of a tight fit. So I'm just going to squeeze it in. So now we have a power supply our solenoid and a relay in the middle of the two right here. You can kind of think of our relay working the same as our solenoid. Our solenoid has one place to another like a source to an output and it's going to be blocking the two. Our relay is doing the same thing but from power to power and this is doing it from water to water. So I'm just going to go over everything. We have our power supply for our pump which goes into the relay. The relay blocks the power to the pump and then the relay connects to our board. Then we have our power supply for the solenoid which goes into the relay which is blocking the power to the solenoid and then our relay plugs into our Arduino. So the same setup twice for two different things. Now let's plug in the Arduino to the computer and start writing some code to make this all work. You can see that the relay is turning on and off because it still has the code from the last project. So the Arduino is just running that over and over and over which I think was one second of pump on and then five seconds off something like that. So what we're going to do is we're just going to highlight this and control slash then we're just going to upload it to our board. Oh no upload port working. Okay we got to click on our board first. Then we got to connect it there. All right nice so now the code should stop running on the Arduino because there is no code because it's all commented out. To undo that just press control slash and until you upload the the code won't run because it still has the old one. The first thing we're going to do is add another variable just like this one relay pin four. We're going to be adding one solenoid pin three. This is the pin for the solenoid this is the pin for the pump. To make it a little easier I'm just going to call this pump pin now we just have to go replace pump pin. Right here right here and right here. So we're going to do the same exact thing. So we can actually just take this and duplicate it. So we're going to put solenoid pin in pin mode output because we're going to be telling the relay what to do so we're outputting information the relay is not talking to us it's not telling us anything so it's not an input. Then in the next step we're going to have to make a couple different changes. Because I don't want the pump to build up a bunch of pressure while the solenoid is closed and then for something to burst and spray water everywhere all over the electronics what I'm going to do is I'm going to turn on the pump for a second it's going to build up pressure very quickly and then after that second I'm going to be opening up that solenoid valve letting out some water and then repeating the process. Now one more thing is the pump is not only very powerful but it's using big half inch tubing and then we're reducing that into this very thin tubing. So not only are we holding a bunch of pressure we have to reduce it down to a smaller pipe and that's going to build up pressure like crazy. So we're going to try as small as we can intervals and slowly add time and see how far we can go before something explodes. So for the code we're going to do the same thing digital right pump pin high is on and then low is off and then delay is a delay for how long we want to put. So this is one second this is five seconds. So what I was thinking is we put on the pump for one second. Let's copy paste this you can remove this and this not to confuse anybody. Now we're going to put the solenoid pin here on for one second and I'm just going to copy that off again and then I'm going to remove this and then we're going to put the solenoid pin low. So in this scenario what would happen is the pump would turn on for one second on its own. Then the solenoid would open and the pump would still run for another second because the pump only turns off down here. So the solenoid and the pump only turn off here after two one second delays. So the pump is on for two seconds the solenoid is open for one of those seconds. So one second we're building up pressure and then one second we're opening up and letting that pressure release. So just to start off we're going to put two half second delays make sure everything is good no leaks no water exploding and then we'll put those higher and higher as we go. So let's go over it one more time. Our pump pin is on so pump is pumping water pumping water but the solenoid is closed. Then solenoid opens pump is still on pump is putting water through the solenoid which is open and into here for half a second. Then both turn off and repeat the whole process. One thing I want to do quickly before we start is I want to see if I'm triggering the solenoid properly because maybe the power and the negative are on the wrong sides. So we're just going to comment out these two rows. Remember control slash commenting out these two control slash and then putting this one and then I'm just going to grab this I'm going to put that over there and I'm going to turn these into 1.5 seconds each. So what should happen now is the solenoid should open for a second and a half and then close for a second and a half and we can actually see if it's working. Now let's see if the relay okay the relay is opening and closing. The relay is going on and off but we didn't plug in this power supply yet to the wall so I'm just going to do that I'm filling the relay oh I can feel the solenoid freaking out you could probably hear that on the mic let me put the mic really close to it. So I'm going to plug in the pump into the power supply right now and I'm going to unplug the solenoid to make sure the solenoid stays open and I'm going to turn on the pump for a really small amount of time and I want to see if the water flows through if it doesn't flow through the solenoid is closed and then we have some kind of problem here so let's just go like this we're going to highlight this close it like that now I just want to turn on the pump for half a second and then I want to turn it off and I'm going to put a delay of five seconds so pump goes on half a second and then pump turns off five seconds and repeats so let's see this relay should stop working now this one's working check it out in five seconds it's going to turn on for a second oh and we have water leak damn look how much water is coming out that pump is definitely overkill oh it's just steady flow at this point look at that oh my god okay I'm gonna get the towel on there let me get some more and the pump is off and it's still just flowing I'm kind of tempted to just get a cup and pour it all in there it's still flowing I think it's just siphoning we got it oh it's definitely siphoning I didn't think of that I gotta lift this up like that and I gotta take this goddamn connector off okay whoa yeah it was definitely like if I push look at this if I push this down it's gonna start siphoning out yep I did not think of that okay now it's stopped because the bucket just kept going down it wasn't stopping I mean I have like seven towels on the floor now turned a five-minute project into a 25-minute mess oh that's disgusting that's brown water okay so instead of using this stupid connector that doesn't work and cost me $20 I'm gonna be returning that and I'm just going to make this reduction tube so while my little homemade coupler is drying up with the super glue I'm going to be making a little attachment in the middle here nice and tight well it's super messy but it seems like it works when I actually blow on the end and I cover this side no air comes out so knowing that I think it's going to seal really good now what I want to see is can we get water to flow through here all the way to this and come out safely somewhere and I'm going to try and actually pinch the tube and I'm going to see if I can create enough pressure to blow something else out here and then we can figure out what to do next okay it's starting to pump some water it's really low flow though all right so we do have flow it's just extremely weak okay so after that whole mess let's just go over everything one last time the idea here is that if we had a split here into two rows we could put a solenoid on each row and we can open one and close the other and then kind of divert the water like I said earlier like we're diverting traffic so we can say like okay turn left or turn right no one goes everyone can go we have all those options now to control and we don't have to do it by turning on and off the pump the pump can stay on full time so one more time plug in the Arduino make sure you're on the Arduino pin like this so from the start we're turning on the pump we're going to turn on the pump for one second I don't want too much pressure to build up because something will end up blowing again then I want to open up the solenoid after one second of the pump for one second so one second open one second close then after that we're going to close both pump and solenoid and we're going to wait five seconds and I'm just going to make sure in that five seconds that there's no leaks there's no problems and I have time to pull out the power supplies so what's happening now is you can see this relay has a red light that turns on one second later this relay has a red light that turns on and then they both turn off for five seconds and wait red light one second later red light and both turn off and the next time they turn off for five seconds right now I'm going to plug them both in pump is on then the solenoid opens okay we have a little bit of a leak but nothing big we can kind of ignore it for now so we're getting flow but not enough so we're going to change in the code we're going to make the pump run for longer just a little bit longer all right so our pump is going to turn on for one pump five seconds then our relay is going to open the solenoid and we have water flow now let's try and see if we can build up even more pressure and not have just a little drizzle of water I want a nice flow so I'm going to make the pump run for three seconds now yeah so we definitely have a water leak as you can see right here I need more towels well I'm going to end it with that we had some water leaks we had some problems I kind of didn't expect this stuff to happen so the video is probably going to be a lot longer than I expected it to but I hope you enjoyed this video the next video we're going to be adding a pressure sensor and a flow sensor in the middle so we can see some numbers and see what's happening with our project if you enjoy this type of content do me a favor and subscribe to the channel because 98% of people who watch my videos don't stay for more if you like the video like the video if you have something you want to tell me or if there's something you want to see in the next video when we're going to do a pressure sensor and a flow sensor let me know in the comments and I'm going to see you in the next one