The main idea of this device is to track temperature, humidity, light level, and soil moisture, and control a water pump to enable remote watering.
After a nice chat with @alvarolb on this thread, I got the system working.
I did two iterations with an Arduino MKR1000, the first was in a breadboard, and the second in a little more appropriate container (just a little).
First Iteration
The thing was connected to a DHT11 (temperature and humidity sensors), a light sensor, soil moisture sensor, and a Relay module, that activates an aquarium pump. As I was saying, the first iteration looks pretty ugly, but worked and allowed me to be sure that the system worked before starting soldering… here you can see it.
I can’t believe how easy was to integrate everything thanks to thinger.io library. I hope I can get access soon to the web api part, since there are some things that I’d like to work on, (like keeping a history of the readings, being able to configure a refresh rate on a donut chart, different than the refresh rate of the history chart, for the same device reading type… etc.
Anyway, I’m really happy with the speed I was able to get this working thanks to the library, and how simple and clean the code ended up looking.
#define _DEBUG_
#include <SPI.h>
#include <WiFi101.h>
#include <ThingerWifi.h>
#include <DHT.h>
#define USERNAME "your_user_name"
#define DEVICE_ID "your_device_id"
#define DEVICE_CREDENTIAL "your_device_credential"
#define SSID "your_wifi_ssid"
#define SSID_PASSWORD "your_wifi_ssid_password"
ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
const int LedPin = 6;
// PIN configuration
const int DhtSensorPin = 2;
const int WaterRelayPin = 3;
const int SoilMoistureSensorPin = A5;
const int LightSensorPin = A6;
int ledState = LOW;
int waterRelayState = LOW;
const int DhtType = DHT11;
DHT dht(DhtSensorPin, DhtType);
void setup() {
Serial.begin(9600);
dht.begin();
// configure wifi network
thing.add_wifi(SSID, SSID_PASSWORD);
pinMode(LedPin, OUTPUT);
pinMode(WaterRelayPin, OUTPUT);
// Configure the LED
// Need to track the state separatelly from the real pin, since MKR1000 does not respond the correct value when reading an output pin
thing["led"] << [](pson & in) {
if (in.is_empty()) {
in = ledState;
}
else {
ledState = in ? HIGH : LOW;
digitalWrite(LedPin, ledState);
}
};
// Configure the Water Relay
// Need to track the state separatelly from the real pin, since MKR1000 does not respond the correct value when reading an output pin
thing["water"] << [](pson & in) {
if (in.is_empty()) {
in = waterRelayState;
}
else {
waterRelayState = in ? HIGH : LOW;
digitalWrite(WaterRelayPin, waterRelayState);
}
};
thing["dht11"] >> [](pson & out) {
out["humidity"] = dht.readHumidity();
out["celsius"] = dht.readTemperature();
out["fahrenheit"] = dht.readTemperature(true);
};
thing["light"] >> [](pson & out) {
out = map(analogRead(LightSensorPin), 0, 1023, 0, 100);
};
thing["moisture"] >> [](pson & out) {
out = map(analogRead(SoilMoistureSensorPin), 0, 1023, 0, 100);
};
}
void loop() {
thing.handle();
}
Second Iteration
The main purpose here was to make all the hardware fit into a container that I could place into a planter. The electronics are almost the same. The only difference is that I used different pins, since it made easier placing everything together.
I didn’t plan the position of each element, I inserted each of them acording to the space left in the board, so I think I was lucky that everything fitted there…
This would be the board…
And the back side:
Here you can see the soil moisture inserted into the case
Ant how the board fits next to it…
After that, I placed the batteries on the remaining space…
And the relay, goes inverted, on top of the MKR1000, (the only space left…)
Finally, this is how it looks assembled
TODO: upload the code of the second iteration…