Arduino - Soil Moisture Sensor

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
please go to Eli the computer guy calm in order to view schematics code and more for the projects that you are learning about welcome back so in this video we get to pull out the turkey baster so what does a turkey baster have to do with our dueño projects i'm gonna show you in a couple of minutes so the project that we're going to be dealing with today is we are going to be using a soil moisture sensor for an Arduino again when you think about creating Arduino projects one of the things you should think about is what are the real-world applications what are the real things people would actually care about and one of the things really is basically determining whether this the moisture in the soil is of the appropriate level think about how many people have flower gardens or herb gardens or basically you know all the people out there they've got all these wonderful potted plants and they have to replace the potted plants every month because they forget to water them or they overwater them right this is a real this is a real legitimate issue watering your plants the appropriate level is a real problem for real adults and so with this this soil moisture sensor does is basically it reads the resistance between the two prongs so there's a positive Prague and a negative prong you put this into the soil and the current tries to go between these two prongs and it sees what the resistance there is so basically the more resistance there are is the drier the soil is the less resistance there is the wetter the soil is so we're able to take that as an analogue reading so we're able to get a number output and then once we have that number output we can make that a value of a variable and then we can put that into a function for all kinds of different things to happen maybe you could post to a server so if you have if you have these with Arduino Uno wi-fi's in multiple different Gardens they can post to a server you can wake up in the morning and you can see which gardens should be watered or which Gardens should not be watered and if you don't want to connect to a network maybe you could simply have the Arduino Uno have a a green LED or a red LED green LED if the soil is right a red LED if the soil is bad or again we're in the Arduino we're in the Arduino world not only do we want to be notified of problems but really if the system can automatically rectify the problem that's really the good thing I mean that's really what the modern world is about so what we can also have is we can have the Arduino Uno basically be able to read at the value of the variable and if that value is whatever it shouldn't be it could do something such as turn on a water pump to automatically water people's garden so again imagine flower gardens imagine herb gardens imagine that type of thing you place these in there you have them connected to different water pumps when it gets too dry it then pumps out water into the garden and you have a great little automatic irrigation system one of the great things you can do with Arduino is to is again you can have multiple sensors so you could have the the soil moisture sensor you can have a photovoltaic fan sensor basically determine what the Sun like sunlight currently is and you could have a temperature sensor so one of the things you could do is you don't want a water plants in the middle of the day when it's too hot so basically you could say if the soil is dry and the temperature is below 80 degrees and it's dark then water the plants so these are the types of things that you types of project so you can start doing once you add in things like this little moisture sensor so with that let's go over to my little workbench to show you how to put this little project together then I will show you the very simple code and then show you the example of how it all works in action so here the components that we're going to need for this particular project you will notice some non-technical components here we need these non-technical components to be able to test this sensor and be able to see how the readings work so I just have a little glass of water here this is just plain normal water and I also have a mug of potting soil so this is just relatively a dry potting soil so we can put the sensor into that to determine how wet it is and then we have the turkey based or the turkey baster so since this is a dry soil what we're going to do is we're going to put the moisture sensor into the dry soil see what the reading is and then we're going to start adding water and see how the reading changes so those are the non like really technical components beyond that this is all that is required for this project so we have our soil moisture sensor here and so when you buy this this all comes as a kit you have these prongs so the prongs here depending on which ones you buy they actually don't have any brain power to them basically these are just prongs that you plug into the ground and then you have the positive and negative wires that you then run to this little controller unit here so this is the brains of this particular unit then past that when you take a look at the the module for this unit you'll have positive so you have VCC and you have ground now you can plug the VCC either into a five volt or into three volt you will get a different reading from it depending on whether it goes into five volt or three volts so just whatever you're going to do for your project just keep doing that because if you set a value for a variable in an if statement that should trigger and then you change the input going in you may run into some issues there then past that we have the analog output so all the way on the right-hand side we have the analog output so the analog output we have coming down here to a zero so with this particular type of moisture sensor you can actually have digital output or analog output in order to read a specific number what we're gonna be using today is the analog output and this is really all you need for what we're going to be doing today you just assemble this again we have it going through five volt we have going to ground and then we have the analog wire going to a zero this is how the project is built so let's go over and take a look at the code so here is the code here is literally all the code however that is that is all the code that we're going to be doing today so there's no libraries or anything else this is very simple since basically over we're doing this reading from an analog sensor so first thing we're gonna have to do is you're gonna have to define the analog pin so we're gonna define a zero and we are going to call that the soil sensor so in order to reference a zero now we will save soil sensor then we go down and we set up the environment and all we're going to do here is we were simply going to do cereal dump again 9600 so this starts the serial monitor service so that we can actually read out from the arduino and see what the sensor readings are then pass that we get into the loop and literally oh my god oh my god it's three lines here whoo that's it so we got in so creating a variable sensor value equals analog reads the function analog read a soil sensor so we're going to analog read a serial a zero and then we're simply going to serial dot print line the value of sensor value then we're going to delay for 500 milliseconds or about half a second repeat repeat repeat repeat so basically all we're going to be doing for this particular project is reading the analog value from that sensor pen and then printing it out to the serial monitor so let me let me upload this code to the Arduino Uno and I'll show you how it works so I've connected the arduino uno and i have uploaded the sketch so now that it's powered we can go to tools we can go to serial monitor and we can see what the output is so we can see that we are currently getting an output of 1023 so if we we take a look we have the sensor right now and the sensor is not connected to anything at all it's not in the soil it's not in water and so we can see the max value the max resistance that we're going to get is a thousand 23 now one of the things I'm going to show you is the minimum resistance so if the high is a thousand twenty-three what I want to do and this kind of shows you how this works is if I connect both sides so this is simply one wire I'm connecting the male to one side the male to the other and as we can see the value goes down to zero so when there is no resistance at all it's zero when there's the max resistance it's a thousand 23 so that's your high and your low from there one of the interesting things to see is if we take our little glass of water here and we simply put our sensor into the glass of water we can see that the value for the sensor actually does not go down to zero a lot of people would think if you put this in water that the value will go down to zero but as you can see it's down that two hundred and fifty two hundred and forty range so you don't actually get a zero value when you put it in the water then from there what we're going to do is we're going to take this and we're going to put it into our soil and so we can show all the way down into our soil and we can start to see of what the value is now one of the things that I will tell you when you're using these sensors is it does take a few minutes let's just say it takes a few minutes before the number fully stabilizes when I say a few minutes in my playing around with this I would really say it takes about twenty minutes I don't know exactly what's going on between the two little prongs in there what's happening with the soil and everything else but basically what I found in order to get a truly stable number it takes about 20 minutes for everything to work out so just realize if you're gonna be using a sensor don't think that you can simply shove it into the soil and you will get the specific number you're looking for immediately it will take a little bit before it equalizes so here we can see it's equalizing out to about 391 again it's still going up a little bit 392 one of the things I might be useful is with the serial monitor you can do things like show time stamp so you can start printing this out with the time stamp and then the nice part is what you can do is you can walk away go have a cup of coffee go to the bathroom whatever else and then you can see what the current value is you can scroll up a little bit to see how long it's taken to get there so this is just one of those things just to keep in mind to get a pitch to get deep this state's table number you're really looking for give it about 10 20 minutes but here we've got a relatively stable number again we're saying seeing that 397 398 so it's 1 since we have that what I'm going to do is I'm going to take the turkey baster I'm going to grab a little bit of water here a little bit of water here and then we're gonna go over and we're going to put the water into our little thing and this will show the value go down so as we now are watering watering our little sensor we can see the value has gone all the way down dude like 167 170 mark again this is one of the things as soon as you add water because the water is gonna percolate through the soil plus there's some chemical reactions with the water the whole nine yards so you just realize when you put water in to the container the the soil sensor will immediately start reading values but you shouldn't take the values as being an accurate again until I would give it about 10 minutes that's one to be one thing to be thinking about if you're gonna be doing a project like an automatic watering project one of the things that I would say is have the sensor check the value or trigger let's say every 10 minutes or so so that way if if the value is below level so you turn the pump on you pump water into the plant into the pot and then I would have it wait 10 minutes before it determines whether or not more water should go in because as you can see it takes a little bit of time before it stabilizes so if you just simply keep pumping water in you may run into an issue with you know the very though the value of the variables so on and so forth and so basically that is all on there is for this particular project so what you do is you you you take your soil you plug this in you shove it in there leave it for about 10 20 minutes see what the see what this the reading is when it's dry then put enough water in there put in amount of water in there that you think is appropriate what you think the the level the water level should be then again leave a sensor for about 10 20 minutes to figure out what that value is and then take those values turn it into an if-else and then have the if/else do something within your sketch again you can have it post to a server you can have it turn on an LED light or get you can even have it turn on a water pipe there's something like that so that's all there is to this particular project and I think it's a pretty enough 250 neat little little sensor at the end of the day so that's all there is those per dealer project so you have your little soil moisture sensor basically what this does is it's able to read their resistance it sends sends a positive through one prog it tries to pick the positive up through the ground on the other prog if electricity can flow freely then you get a value of zero if the electricity cannot flow at all you get a value of a thousand twenty three if you're using five volt and then basically in between there is what your sensor readings for your soil will be again if you're gonna be using these sensors I would say the one issue it is it's kind of weird cuz it's not a digital sensor there's no real brains or anything to it but really and truly you should wait about 20 minutes before you really trust the reading that your sensor is giving you again I don't know what's going on with the the soil composition or the soil chemistry or anything like that what I found is it does take a surprising amount of time this isn't like a lot a lot of sensors a lot of sensors you shove the sensor in you do something the sensor it automatically gives you whatever reading that's giving you this is one of those shove it in go grab a cup of coffee drink your cup of coffee come back and then see what the reading is because if you go off of the immediate readings you'll probably run into issues going in the future now one of the things that I will warn you is we used our turkey baster today so this is one of the few times this is one of the few times you want water [Music] no project but do realize when you're dealing with water water does conduct electricity and so if you do things like like it wasn't paying attention you'll be surprised I wasn't paying attention when I was experimenting with this and so at one point I was shoving the sensor into the water and then I shove the sensor too far into the water and the water actually got up into into where the wire connectors are and so and then I started getting a lot of weird readings because the water was shorting at these connections up here and so I was getting weird readings even though it wasn't actually connected anything so do be careful about that with water if you're gonna use this in a real world like a production environment I would use something like there's something called liquid electrical tape it was really cool and so if I was gonna put this out in the real world once I made all the connections I would shellac this I would say lack the top part the top part with liquid electrical tape cuz again you've got the little you've got a little solder points on the back you've got these wires up here if these get wet remember what all this is doing all this this sensor is doing is it seeing what the resistance is between the two sides well the two sides are here the two sides are here the two sides are here so if you get a short not just down here on the prongs but you get a shore up here and the solder connections or if you get a short here up on the wires well then you're gonna start getting readings as if there's moisture when there may not be so if you're gonna put this out into the real world again I would use something called a liquid electrical tape if you're just using this as an experiment you're playing around just make sure keep the top of this darn thing dry if the top of this gets wet then you'll run into problems there are other issues people have with these particular sensors a lot of people say at their toy sensors because they will be great at over time since there's an electrical current going through the soil these sensors many times will corrode relatively quickly what quickly actually means at the end of the day it depends on what environment you are you're in you know what the soil composition is how wet the soil is so on and so forth one thing that you may think about though is if you want to try to keep the sensor the the sensor you know good for as long as possible is you might do something such as triggering when the sensor is actually powered up so right now in this particular project what we did is we powered this using the 5 volt the standard 5 volt power connector in there dueño board again we can use five older three volt well that means this is powered up all the time so even when it's not reading from the analog sensor it is still powered which means this thing is still going to be getting corroded one of the things you might think about doing is actually using one of the digital pins to power this so what you could do is since the digital pen can send five volt you could turn a digital pin on in order to power this collect the reading from whatever for whatever the reason is and then you could turn off both the the reading pen and the digital pen and therefore electricity would not be going through this all the time if you're going to be doing that type of thing though do make sure to test the hell out of it I'm not sure how that would work from a stability issue again as I said before you shove this into soil it takes a while before you start to get a good reading so if you turn Power on onto the sensor and you turn power off to the sensor one of my questions would be is how long would it take before you start getting a stable reading from it so these are the different types of things to think about but one of the things that also realize at the end of the day again focus to talk about these being toys and they're almost disposed disposable but they're also insanely inexpensive again all this is a little board with some foil on it in the connector I think I bought thing about five of the whole modules think you think they might cost a dollar a piece so it is one of those things to be thinking about it's like well if they die every year it takes a year to kill on these things let's say it takes a year to kill one is that's a dollar a year is it worth a dollar a year in order to keep your plants water that it just may be one of those things to think about ago well it's disposable yes it will die yes it will corrode every year but for a dollar maybe two dollars a year that's something that I think is a reasonable price so these are all some of the things you should be thinking about if you're gonna use one of these analog soil moisture sensors so that's all there is to this particular class go out grab your turkey baster shovel these things in the soil and again the big thing is just just be careful how you use your turkey baster just make sure the water goes in the right location or you can run into all kinds of problems and we're not gonna even go into if you squirt water directly on there Arduino board don't do this don't do that water and Arduino boards general do not mix if you have water around you Arduino board just be very very very careful with that as always I enjoy doing this video and I look forward to seeing with the next one
Info
Channel: Eli the Computer Guy
Views: 15,633
Rating: undefined out of 5
Keywords: Eli, the, Computer, Guy, Repair, Networking, Tech, IT, Startup, Arduino, iot
Id: 7ZvmfXmLcww
Channel Id: undefined
Length: 19min 26sec (1166 seconds)
Published: Sun Oct 06 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.