How Too Peripherals Python Tutorials

Smart Garden project

Post Reply
raspberrypi / howtoo     Views: 5309Prev .. Next
Smart Garden projectPosted: Thursday, April 5, 2018 [21:57:44] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
We have been growing tomatoes, cucumbers and a lot of flowers for the last few year and it became a real job watering, cutting and looking after our garden.
This year I've decided to use some technological help.

Plants watering system would include:
- soil moisture sensors based on ESP8266 CP2102 Module
- water tank
- Raspberry Pi controlling water solenoids via JBtek 8 Channel DC 5V Relay Module and watching the water level in a water tank
- database located on a Mac

So far I am testing soil moisture sensors in a house:

Post 22979864 Image 1
Post 22979864 Image 2
Post 22979864 Image 3

It took me a while to get a Deep Sleep to work on ESP8266 CP2102 Module. Internet blogs in 8 out of 10 missed the part that we have to tie the RST pin to GPIO 16 on the ESP8266. On the NodeMCU, GPIO 16 is represented as D0.

Post 22979864 Image 4

Wiring ESP8266 CP2102 module with YL-69 soil moisture sensor:

Post 22979864 Image 5

Here is a test sketch I am currently running for the module:
View Code/**
An example showing how to put ESP8266 into Deep-sleep mode
*/

#include <ESP8266WiFi.h>

// WiFi credentials.
const char* WIFI_SSID = "SSID";
const char* WIFI_PASS = "SSID_Password";
#define soilPin A0
#define sensorPower 13
int ADCValue = 0;
long sleepTimeSeconds = 45;// this is not exact match - in my case it gives around 15 minutes interval
String sensorId="001"; // Be sure to change this to your sensor ID
WiFiClient client;
int numFields = 1;
char serverAddress[] = "192.168.X.X";

void connect() {

// Connect to Wifi.
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(WIFI_SSID);

WiFi.begin(WIFI_SSID, WIFI_PASS);

// WiFi fix: https://github.com/esp8266/Arduino/issues/2186
WiFi.persistent(false);
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);

unsigned long wifiConnectStart = millis();

while (WiFi.status() != WL_CONNECTED) {
// Check to see if
if (WiFi.status() == WL_CONNECT_FAILED) {
Serial.println("Failed to connect to WiFi. Please verify credentials: ");
delay(10000);
}

delay(500);
Serial.println("...");
// Only try for 5 seconds.
if (millis() - wifiConnectStart > 15000) {
Serial.println("Failed to connect to WiFi");
return;
}
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

Serial.println();

// while (!device.connected()) {
// delay(1000);
// Serial.print(".");
// }

}

void HTTPPost(String fieldData[]){

// This function builds the data string for posting to Your Server and provides the correct format for the wifi
//client to communicate with it.
// It will post "numFields" worth of data entries, and take the data from the fieldData parameter passed to it.
// Be sure to increase numFields to the number of fields you need, and activate the fields in your channel view.
if (client.connect( serverAddress , 80 )){

// Build the Posting data string. If you have multiple fields, make sure the sting does not exceed 1440 characters.
String PostData= "SoilSensor=" + sensorId ;
for ( int field = 1; field < numFields+1; field++ ){
PostData += "&value=" + fieldData[ field ];
}

// POST data via HTTP
Serial.println( "Connecting to Server for update..." );
Serial.println();
client.println( "POST /u/soil.moisture.cgi HTTP/1.1" );
client.println( "Host: WhiteApple" );
client.println( "Connection: close" );
client.println( "Content-Type: application/x-www-form-urlencoded" );
client.println( "Content-Length: " + String( PostData.length() ) );
client.println();
client.println( PostData );
Serial.println( PostData );
client.stop();
}
else {
Serial.println( "Can not connect to the server.." );
}
}

int readSoil()
{
digitalWrite(sensorPower, HIGH); // Turn power to device on
delay(10); // Wait 10 milliseconds for sensor to settle
ADCValue = analogRead(soilPin); // Read the value from sensor
digitalWrite(sensorPower, LOW); // Turn power to device off
return ADCValue; // Return the moisture value
}

void setup() {
Serial.begin(115200);
Serial.setTimeout(2000);

// Wait for serial to initialize.
while (!Serial) {
delay (100);
}

Serial.println("Device Started");
Serial.println("-------------------------------------");
Serial.println("Running Deep Sleep Firmware!");
Serial.println("-------------------------------------");

pinMode( sensorPower , OUTPUT );
digitalWrite( sensorPower , LOW ); // Set to LOW so no power is flowing through the sensor.

}

void loop() {
connect();
delay( 2000 );
String data[ 8 ]; // You can fill data with up to 8 values to write to successive fields in your channel.
digitalWrite(sensorPower, HIGH); // Turn power to device on
delay(10); // Wait 10 milliseconds for sensor to settle
data[ 1 ] = analogRead(soilPin); // Read the value from sensor
digitalWrite(sensorPower, LOW); // Turn power to device off

Serial.print( "Soil Moisture = " );
Serial.println( data[ 1 ] );
delay( 2000 );
HTTPPost( data );
delay( 2000 );
Serial.println("Going into deep sleep..");
ESP.deepSleep(20e6 * sleepTimeSeconds, WAKE_NO_RFCAL);
Serial.println("Awakening now..");
delay( 2000 );
}


So far so good. Two sensors report to the database every 15 minutes.
Stay tuned for battery powering ESP8266 CP2102 module.There's no place like ~
RE: Smart Garden projectPosted: Saturday, April 7, 2018 [02:29:29] - 2
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Worked a little on a GUI to control and view the data.

Post 23082569 Image 1

Post 23082569 Image 2

It is coming alone. As long as it is useful.There's no place like ~
Soil moisture sensors failed in 3 daysPosted: Friday, April 13, 2018 [22:39:00] - 3
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Soil moisture sensors YL-69 failed one after another in 3 and 3.5 days.

Post 23673540 Image 1

Post 23673540 Image 2

Time to move to something new.
New sensor on the list is SEN0193 capacitive soil moisture sensor.There's no place like ~
Capacitive Soil Moisture Sensor SKU:SEN0193Posted: Friday, April 13, 2018 [22:47:15] - 4
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
New sensor arrived in a mail. More information available on:
https://www.dfrobot.com/wiki/index.php/Capacitive_Soil_Moisture_Sensor_SKU:SEN0193

Connecting it to a ESP8266 CP2102 Module is straight-forward enough.
Sensor: A - Module: A0 pin
Sensor "+" - Module: 3V3 pin
Sensor "-" - Module: GND

Post 23674035 Image 1

Run a calibration sketch to make sure readings are true.
Then I just changed:
Serial.begin(115200);
to
Serial.begin(9600);

and sketch above just started working. It will require re-calibrating min and max values and it is ready to go.

Post 23674035 Image 2

Post 23674035 Image 3

Hope to post some updates soon.There's no place like ~
Powering ESP8266 CP2102 module with LD1117V33Posted: Saturday, April 14, 2018 [16:43:10] - 5
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Testing battery power option for ESP8266 CP2102 module:

Post 23738590 Image 1

Schematics found on:
henrysbench.capnfatz.com/..

Post 23738590 Image 2
Stay tuned..There's no place like ~
Soil moisture inserts designPosted: Friday, April 20, 2018 [00:04:47] - 6
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Here is inserts 3D model for soil moisture sensors. It will insert into PVC 1 1/4" pipe.
FIrst with 9v battery model in place:

Post 24197087 Image 1

and the one with battery removed:

Post 24197087 Image 2
Capacitive sensor and WiFi module not installed.There's no place like ~
Prototype imagesPosted: Friday, April 20, 2018 [19:34:39] - 7
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Did some prototyping for soil moisture sensor. Printed parts to verify fit of the parts.

Post 24267279 Image 1

Post 24267279 Image 2

Post 24267279 Image 3

Post 24267279 Image 4

Post 24267279 Image 5
Looks goodThere's no place like ~
Soil Moisture sensor V1.2Posted: Friday, April 27, 2018 [20:47:41] - 8
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Just got my package from AliExpress with Soil Moisture sensors V1.2.
Six sensors ordered April 12, 2018 from China and delivered on April 27, 2018 for US $20.53 S/H included.
One sensor V1.0 on eBay cost me US $14.74 delivered.

One V1.2 sensor already hooked-up on a testbed - works just as V1.0 using the same Arduino sketch and wiring is the same.
Here is some comparison pictures:

Post 24876461 Image 1

Post 24876461 Image 2

Post 24876461 Image 3

Post 24876461 Image 4

Post 24876461 Image 5

and here is a microscope pictures of the chip used on V1.0

Post 24876461 Image 6

and V1.2 chip:

Post 24876461 Image 7

if it makes sense for someone who is more familiar with electronics..
also, it caught my attention - here is an image of some sort of capacitor (my guess) used on V1.2 sensor. It has a glass body with liquid in it.

Post 24876461 Image 8

you can see it on sensor pictures above but it is too small to see.There's no place like ~
First soil moisture sensor tested outsidePosted: Wednesday, May 2, 2018 [16:33:24] - 9
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
First soil moisture sensor tested outside on battery power. It is about 50 feet away from WiFi AP. Sends readouts every 15 minutes without a hitch.

Post 25293204 Image 1

Post 25293204 Image 2

This is a close-up after removing it for liquid tape contacts treatment:

Post 25293204 Image 3

Post 25293204 Image 4

Parts made out of fiberglass resin reinforced with fiberglass in a silicone mold.There's no place like ~
Making some more soil moisture sensorsPosted: Tuesday, May 15, 2018 [14:34:50] - 10
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Just came out of the mold:

Post 26409290 Image 1

Post 26409290 Image 2

Post 26409290 Image 3

Post 26409290 Image 4

Needs some cleaning and then do some assemblyThere's no place like ~
Project partsPosted: Sunday, May 27, 2018 [00:49:34] - 11
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Parts of the project:

Connecting a JBtek 8 Channel DC 5V Relay Module
www.codemacs.com/raspberr..

Building a water tower:
www.codemacs.com/raspberr..

Soil moisture sensor V3.0:
www.codemacs.com/raspberr..There's no place like ~
Smart Garden project partsPosted: Wednesday, June 12, 2019 [02:09:41] - 12
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
3D printed sprinkler:
www.codemacs.com/raspberr..There's no place like ~
raspberrypi / howtooPrev .. Next
 
Post Reply
Home - Raspberrypi: How Too Peripherals Python Tutorials
Our Telegram Group