This article is part of an assignment portfolio submitted for the subject SIT210 - Embedded Systems Development through the School of IT, Deakin University.
About the ProjectThe following project is for a Smart Dog Water Bowl that automatically refills when the water bowl gets dry, based on the reading from a capacitive soil moisture sensor. Whenever the water bowl is refilled, the user is alerted via an email through IFTTT.
Inspiration for this ProjectI own two Cavalier King Charles Spaniels called Jimmy and Leo. Sometimes when I get home from work as a relief teacher their water bowl is dry, and on extremely hot days, which occur often in Australia, I feel guilty when this occurs. That said, even on days which aren't hot, these two boys have a habit of guilting me with their puppy dog eyes.
The Particle Argon and Particle Photon communicate through the Particle Cloud. The Particle Argon measures the moisture and publishes events "dry" or "full" depending upon its reading and if that state has changed. This event is subscribed to by the Particle Photon, which will turn on if dry, to refill the bowl through a solenoid valve connected to the hosing. When the bowl is refilled an event will be published that will cause IFTTT to send an email to the dog owner.
The moisture level is visualised via a webhook through api.ThingSpeak which produces a line graph and a gauge of the water level.
How to SetupStep 1: Modifications to Pet Water Dispenser
To begin, we modified a pet water dispenser to accommodate the capacitive soil moisture sensor by drilling a 12mm hole towards the back using a cordless drill and then cutting out the remains with a hacksaw. We then smoothed out the notch where the sensor would sit with a round file. A picture of the modification is shown below.
It had previously been planned to modify the large water container also by drilling a hole to accommodate the wiring of a waterproof moisture sensor and a larger hole as an inlet for the hose and then seal those with sealant once the hose and wires to sensor were in, but after sealing with Selley's All Clear, the bottle was flooding the bowl overnight so this idea was scrapped.
Step 2: Set Up Relay and Solenoid
To set up the relay first plug in your Particle Photon to the headers of the Particle Relay Shield for Photon. Next connect the wiring into the COM and NO contact terminals of the relay (Note: the NC contact terminal should be empty) you will be using. In the case below, we chose to use pin D6 as our RELAY_PIN in the code which corresponded to the 5 V relay, RELAY 4, on the relay shield.
Next crimp on an insulated 1/4" female spade contact terminal to each wire. These will connect to the two male connectors on the 12V solenoid valve. Then connect the 2 lengths of hosing to 2 female 1/2" hose connectors by heating the hosing with boiling water, sliding it onto each adapter and securing the hosing with O-ring clamps. This set up can be seen below.
It should be noted that the solenoid is 12 V, but the relay was only 5 V. So one of the wires was cut in two and a female DC barrel jack adaptor added to provide the required voltage to power the solenoid valve. It does not matter which wire as polarity does not matter for most solenoid valves.
To the end of the hosing which will be connected to the tap, connect a 12 mm hose connector as shown below.
As the weather in South Australia has been very wet, the dog water bowl was set up indoors using an indoor tap adaptor.
Step 3: Set Up Capacitive Soil Moisture Sensor
Connect the Particle device to the red and green LED's and the capacitive soil moisture sensor as shown in the fritzing diagram of the breadboard below.
The following wiring diagram will match the code provided on the Github link below.
Step 4: Coding
Once the wiring for both the relay and sensor is set up, copy and save the C++ code provided into a new app file on the Particle Web IDE, verify and flash it to your Particle devices.
In the project created, the code to publish from the sensor was flashed to a Particle Argon, and the code subscribing and controlling the relay was flashed to a Particle Photon.
Calibration of the capacitive soil moisture sensor reading is now required. To do so, position the sensor in the water bowl and take readings in air, when bowl is half full and when the bowl is full. The readings were viewed through the serial monitor while the Particle Argon was plugged into the laptop. These readings are printing from the following lines of code in the loop:
// Take the reading
int moistureValue = analogRead(SENSOR_PIN);
// Print to serial so you can keep track, particularly when determining
// moisture values from sensor when dry and when water bowl is full.
Serial.print("Moisture Level: ");
Serial.println(moistureValue);
Serial.print(Time.hourFormat12());
Serial.print(":");
Serial.print(Time.minute());
Serial.print(":");
Serial.print(Time.second());
To view these readings open the Arduino IDE (as both Particle and Arduino use.ino files) and select Tools -> Port -> /dev/cu.usbmodem..... as shown in the diagram below.
Then select Tools -> Serial Monitor to view the readings.
From these readings I determined the moisture reading to be 2190 when full and 3220 when dry. I then mapped these values to 100 % and 0 % respectively with the following line of code for ease of reading how full the bowl was.
// Map these values to a percentage of how full. In this case when water bowl // was full moisture reading was 2190 and when dry it was 3220.
int moisturePercentage = map(moistureValue, 2190, 3220, 100, 0);
Once you have these readings, a test run can be attempted. Both Particle devices will already be running, so connect the solenoid to the tap and adjust the water flow accordingly, then test whether the solenoid opens and the red LED switches on when the moisture sensor is dry and the solenoid closes, the green LED switches on and red LED switches off when the moisture sensor is exposed to water.
Step 5: Set Up IFTTT
Whilst doing a test run, check the events are being published by the Particle devices by checking the Particle Console and selecting the Events log or My Devices.
We can see "full" has been published both times the Particle Argon has been powered on from the Events log above.
The event "on" from the Particle Photon connected to the relay is the event we will be setting up to send an email to the user for via IFTTT.
If you haven't already set up an IFTTT account here.
Once your account is set up, create a new applet by clicking "Create" in the top right corner, as shown below.
On the next page click on the button "If This".
On the following page search for Particle and click on the Particle icon.
On the next page select "New event published". If you haven't already, connect your Particle account by following the prompts.
On the "New event published" page enter the details shown below and click "Create trigger".
This will take you back to the If This Then That page, where you will click on the "Then That" button.
On the following page search for gMail and click on the gMail icon.
On the next page select "Send yourself an email". If you haven't already, connect your gMail account by following the prompts.
On the "Send yourself an email" page enter the details shown below and click "Create action".
After clicking "Create action" you will be taken to the following page. Click on the "Finish" button.
Step 6: Set Up Webhook
We will now create a webhook so as to graph the moisture percentage value on ThingSpeak. To do so, we will first insert the following lines of code into the smartdogwaterbowlpublish.ino app:
// ThingSpeak
const char * eventName = "thingSpeakMoisturePercentageReading_";
// ThingSpeak Channel information
unsigned long myChannelNumber =XXXXXXX;
const char * myWriteAPIKey = "XXXXXXXXXXXXXXXX";
Particle.publish(eventName, "{\"Moisture Percentage\": \"" + String(moisture) + "\", \"key\": \"" + myWriteAPIKey + "\" }", PRIVATE, NO_ACK);
delay(PUBLISH_INTERVAL); // Moisture level read every minute
For my Channel Number and myWriteAPIKey, you will be able to find the characters to enter on the following screen of the ThingSpeak page where the yellow circles are.
The line of code:
Particle.publish(eventName, "{\"Moisture Percentage\": \"" + String(moisture) + "\", \"key\": \"" + myWriteAPIKey + "\" }", PRIVATE, NO_ACK);
will resolve to a JSON block assigned to the event name, "thingSpeakMoisturePercentageReading_":
{
"Moisture Percentage":"97"
"key":"XXXXXXXXXXXXXXXX"
}
Next in the Particle Photon Cloud interface, a new "Integration" of the type "WebHook" is built by entering the following data:
Click on "Advanced Settings" and enter the following as a JSON block, attaching each parameter as a field number to appear on the ThingSpeak channel:
{
"event": "thingSpeakMoisturePercentageReading_",
"url": "https://api.thingspeak.com/update",
"requestType": "POST",
"api_key": "XXXXXXXXXXXXXXXX",
"field1": "{{{Moisture Percentage}}}"
}
Click on "Save" and start up the Integration.
If you haven't already, create a ThingSpeak account to receive and process the data. Now create a new "Channel", give it a name and defined fields to receive data matching the JSON block above, as shown below:
Set "Metadata" setting to "JSON" and save the Channel. The data can now be visualised as graphs and gauges.
On the left, we have created a line graph set to "Spline" on a "15 minute" timescale, showing the last 480 results (results over last 8 hours). Set the "Y-axis minimum" to "0" and the "Y-axis maximum" to a little over 100, e.g. 110. This shows when the dogs have drunk from the water bowl wherever there is a steep decline.
On the right, we created a gauge widget which shows the current moisture percentage level of the bowl. The settings for this gauge are shown below.
Please enjoy the following demonstration of the Smart Dog Water Bowl in action.
Comments