Login

Sending Sensor Data to Thingspeak

In the previous post, we saw how to send some test data to the cloud. In this post, we will be sending actual sensor data to the cloud. For this, the sensors we will be using are a soil moisture sensor, and DHT11 humidity and temperature sensor.

The objective of this experiment is to create an IOT based Agricultural solution which constantly monitors the water content of the soil and the temperature and humidity of the surrounding environment in which crops are being grown. Once all the data is obtained and sent to the cloud, the data will be interpreted and a water pump will automatically pump the required amount of water for the optimal growth of the plant. Pretty cool right?

What will we be measuring?

  1. Soil moisture content in % of water
  2. The humidity of the environment in %
  3. Temperature in Celcius

 

Thingspeak configuration:

To get started, create a new channel following the same procedure as described in the previous post. However, since we will be logging three different kinds of data (i.e., the temperature, humidity, and Soil moisture content), create three unique fields instead of two, and give them appropriate names.

Hardware: 

  1. NodeMCU Board
  2. Soil moisture sensor
  3. DHT11 sensor
  4. Jumper wires
  5. Serial data cable
  6. Dry soil sample
  7. Wet soil sample

Connections: 

DHT11: 

‘+’ —> NodeMCU 3.3V

‘-‘ —> NodeMCU GND

‘out’ —>  NodeMCU D5

Soil Moisture Sensor:

GND —> NodeMCU GND

VCC —> NodeMCU

AOUT —>  NodeMCU AO

 

Code: 

#include <DHT.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ThingSpeak.h>
#define DHTPIN D5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const char* ssid = “Balasundar-EXT”;
const char* password = “9900002967”;
WiFiClient client;
unsigned long myChannelNumber = 354734;
const char * myWriteAPIKey = “JBNXNMFKVWQJ1NNV”;
uint8_t temperature, humidity;
float sensor_output = 0;
float percent_water = 0;
int state=1;
void setup()
{
Serial.begin(115200);
dht.begin();
delay(10);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
// Print the IP address
Serial.println(WiFi.localIP());
ThingSpeak.begin(client);
}
void loop()
{

//static boolean data_state = false;
temperature = dht.readTemperature();
humidity = dht.readHumidity();
Serial.print(“Temperature Value is :”);
Serial.print(temperature);
Serial.println(“C”);
Serial.print(“Humidity Value is :”);
Serial.print(humidity);
Serial.println(“%”);
sensor_output = analogRead(A0); //Read sensor data from A0 pin
percent_water = map(sensor_output,550,10,0,100); //In dry soil, we get serial value of 550, and in the wet soil, it drops to 10. 550 —> 0% water & 10 —> 100% water
Serial.println(“Reading value from sensor…”);
Serial.println(“Percentage of water in the soil is:”);
Serial.print(percent_water);
Serial.print(“%”);
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel. Here, we write to field 1.

if (state==1) {
ThingSpeak.writeField(myChannelNumber, 1, temperature, myWriteAPIKey);
state = state+1;
Serial.println(state);
Serial.println(“Channel 1 transmitted”);
}

else if ( state == 2){

ThingSpeak.writeField(myChannelNumber, 2, humidity, myWriteAPIKey);
state=state+1;
Serial.println(state);
Serial.println(“Channel 2 transmitted”);

}
else {
ThingSpeak.writeField(myChannelNumber, 3, percent_water, myWriteAPIKey);
Serial.println(state);
Serial.println(“channel 3 transmitted”);
state = 1;
}
Serial.println(state);
delay(30000);
}

Upload the above code making the same changes to the Wi-Fi SSID, Password, WriteAPI key and Channel ID as in the previous post. Upload this code to your Arduino board once complete.

Calibrating Soil Moisture sensor: 

The DHT11 comes pre-calibrated and hence we need not do any additional calibration of our own. However, the soil sensor needs to be calibrated according to our needs. Initially place the soil sensor in the sample of dry soil with no moisture content. Note down the serial monitor value when the sensor is placed in this condition. Next, place the sensor in the optimum soil moisture condition for the plant you require. Again, note down the Serial Monitor reading. In my case, the values I obtained are 550 —> 0% water (Dry soil) & 10 —> 100% water (optimum water in soil). This value will vary from person to person. Using the Arduino map function, we assign these extremities to the serial monitor voltage readings as explained in the code above.

There you go! We are now logging the temperature, humidity and soil moisture data into the three field onto our channel, which can be monitored at all times.

In the next post, we will control a pump to water the soil when the soil moisture content falls below a certain limit, to create a completely intelligent and autonomous feedback system.

 

 

August 21, 2018

3 responses on "Sending Sensor Data to Thingspeak"

  1. Please send the link of next post(to control the water pump based on the sensor value)to my mail ID given below
    v.yogapradeep@gmail.com

  2. Online Cialis Sales No Doctor Viagra Donde Puedo Comprar Cialis En Guanajuato Levitra Para Durar Mas Cephalexin Trigger Imha

  3. Il Cialis E Mutuabile Cephorum Animal Tablets For Sale Cheap Viagra On Line Cialis Wirkdauer

Leave a Message

Your email address will not be published.

top

Knowledge and Content by Li2 Technologies | © 2021 NASSCOM Foundation | All rights reserved

X