Moving into this project I was definitely nervous and intimidated. The last two projects haven’t exactly gone my way and I definitely was not prepared to have a second mental breakdown in the FabLab this week. So I came in early and ready to fail.
Luckily, I’m happy to report that it wasn’t that bad 🙂 Hopefully this means I’ll be back on track for the rest of the semester.
Getting into it, I chose a water levelsensor because my story board is as follows:
Basically the dogs owner doesn’t notice that the dogs water bowl is empty, leading to a sad, thirsty dog. Alternatively with the water level sensor and LED, the owner notices the blinking indicating that the water level is low, or a solid light indicating that the water bowl is empty, and is prompted to fill the bowl back up with water.
To begin this process I had to figure out how to connect my Arduino to the sensor. For that I turned to the internet and found that ground (-) should be connected to GND, S to a pin with an integer, and the positive (+) to the +5voltage.
Then I got to work on writing the code.
I didn’t realize that the picture turned out so poorly :\
But first I identified some constants like the
const int analogPin for where I attached the S, then the
const int LED for where I attached the LED, also to ground
and a threshold which I first made a random number just so I could run the code and open the sensor, I think I used the number 50.
Then I defined the LED as an output and the sensor as an input
Then I wrote that
if (analogValue) < threshold
ditigalWrite (LED, HIGH);
so that the LED would know when to turn on. I don’t have a picture of this first code, just the final one. But this first set of code allowed me to use the water level sensor and record the values it found at different levels of water.
Here is a photo of me testing the low water value level and the LED turning on.
I found that there wasn’t a wide range between values and a TA told me I couldn’t change that, so I had to be really careful in picking the right threshold both for the constant light and the blinking LED. I measured a few times and got different answers, so I used the average or the value that was most consistent.
Then I went back to the code and changed the threshold to 169, the medium value. And added 164 as a const int for the constant LED light.
I added a code for blinking if the analogValue was less than the threshold. And changed my original High and Low LED code to if (analogValue)>light so that it would turn on for any value less than 164. The constant light would indicate that the bowl is practically or completely empty.
Here’s a video of the blinking function in action!
I’m not sure if that worked.. it looks like it might be a downloadable link. But the video shows that the LED blinks when the sensor is half submerged. And it continues to blink when the sensor is outside because it is still wet and needed to be dried first (it wasn’t very sensitive unfortunately).
I think this project went well! Especially with the expectations I had coming into it. I don’t think I’d do anything differently, but thinking practically the sensor isn’t really sensitive enough to give immediately accurate information. You’d have to wait until it was dry for it to show that the bowl was actually empty, but it does know pretty soon that the water levels have decreased past the medium threshold! I even played around with slowly taking out more water to see how long it would take the sensor to notice.
Exciting for the next step!