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

540 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

  4. tadalafil pills 20mg: http://tadalafilonline20.com/ order tadalafil

  5. prescription drugs without a doctor: https://genericwdp.com/ usa pharmacy india

  6. prescription drugs without a doctor generic pills for ed

  7. india pharmacy mail order india pharmacy drugs

  8. generic drugs without doctor’s prescription: https://genericwdp.com/ generic pills for sale

  9. viagra amazon generic viagra walmart
    best place to buy v

  10. viagra without a doctor prescription usa 100mg viagra

  11. buy viagra online usa viagra discount
    viagra discou

  12. viagra amazon viagra 100mg price
    viagra price

  13. viagra over the counter walmart п»їviagra pills
    via

  14. how can i get valtrex valtrex online australia

  15. best place to buy generic viagra online https://viagrapills100.com/ viagra discount

  16. 100mg viagra https://viagrapills100.com/ where to buy viagra

  17. how much is viagra https://viagrapills100.com/ where to buy viagra

  18. cheap ed pills buy ed pills from canada
    cheap ed pills in m

  19. generic viagra without a doctor prescription cheap ed pills usa</

  20. https://zithromaxst.com/# where can you buy zithromax

  21. radiohead cialis 10mg or 20mg interests
    synonymous joslin
    ta

  22. http://gabapentinst.com/# neurontin generic south africa

  23. http://gabapentinst.com/# canada neurontin 100mg lowest price

  24. http://zithromaxproff.com/# zithromax 500 mg lowest price drugstore online
    zithromax online paypal

  25. http://zithromaxproff.com/# zithromax online paypal
    zithromax price canada

  26. keflex price: cefixime capsules
    cleocin online

  27. order ciplox: augmentin capsules
    doxycycline for sale

  28. trusted india online pharmacies: reputable online pharmacies

  29. order medications online from india: best india pharmacy buy

  30. best ed pills: levitra pills mail order erectile dysfu

  31. order erectile dysfunction pills online: cialis pills

  32. non prescription viagra non prescription viagra viagra

  33. metformin online usa: buy metformin online – can you order

  34. ed meds online: buy erection pills – erectile dysfun

  35. metformin 500mg tablets in india: buy metformin – metformin

  36. tadalafil 20mg: generic tadalafil – tadalafil without a docto

  37. generic tadalafil: generic tadalafil – tadalafil generic cost

  38. buy ventolin: ventolin for sale – ventolin otc nz
    ventol

  39. buy ventolin online: buy ventolin – where can i buy ventoli

  40. ventolin australia buy: cheap ventolin – ventolin hfa price

  41. tadalafil online: generic tadalafil – tadalafil generic india

  42. http://edpillst.com/# non prescription ed drugs
    medication for ed

  43. https://edpillst.com/# medicine for impotence
    ed pills comparison

  44. legitimate online pharmacy usa erectile dysfunction medications</

  45. canada pharmacy online canadian pharmacy near me – express pha

  46. buy cialis rush ed pills – buy cialis online in canada
    buy c

  47. buy cialis online in canada ed pills – can i buy cialis in to

  48. good poster ! your powerbloger! good luck~~I’m still learning from you, while I’m improving myself. I certainly enjoy reading everything that is written on your website.Keep the posts coming. I loved it!

  49. cheap generic cialis erectile dysfunction medications – how to

  50. cialis for daily use buy cialis tadalafil tablets – where can

  51. nice meet you! great bloger!you’re actually a just right webmaster. The site loading velocity is incredible. It kind of feels that you’re doing any unique trick. Also, The contents are masterwork. you’ve performed a excellent process in this topic!

  52. cialis 5mg tablet buy cialis online viagra – buy cheap cialis