- Funding
Not Applicable.
- Competing interest:
Not Applicable.
- Code Availbility:
Arduino Program files
Program for Node 1 (Arduino+ Soil Moisture+ nrf24L01)
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8);
int sensor = A1;
int sensorvalue;
int percentage;
const byte address[6] = "00001";
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
pinMode(sensor, INPUT);
}
void loop() {
sensorvalue = analogRead(sensor);
percentage = map(sensorvalue,860,436,0,100);
radio.write(&percentage, sizeof(percentage));
}
Program for Node 2 (Arduino+ nrf24L01+ DHT11+ ESP8266 Wifi module)
#include <SoftwareSerial.h>
SoftwareSerial espSerial = SoftwareSerial(2,3); // arduino RX pin=2 arduino TX pin=3 connect the arduino RX pin to esp8266 module TX pin - connect the arduino TX pin to esp8266 module RX pin
#include <SimpleDHT.h>
#include <ESP8266_Lib.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8);// ce cns//
const byte address[6] = "00001";
int value;
int pinDHT11 = 4;
SimpleDHT11 dht11(pinDHT11);
String apiKey = "310ACMEQ7T9YN80T";
// replace with your channel's thingspeak WRITE API key
String ssid="Nahu55"; // Wifi network SSID
String password ="123456789"; // Wifi network password
#define ESP8266_BAUD 9600
ESP8266 wifi(&espSerial);
boolean DEBUG=true;
//========================================================================
showResponce
void showResponse(int waitTime){
long t=millis();
char c;
while (t+waitTime>millis()){
if (espSerial.available()){
c=espSerial.read();
if (DEBUG) Serial.print(c);
}
}
}
//========================================================================
boolean thingSpeakWrite(float value1, float value2,float value3){
String cmd = "AT+CIPSTART=\"TCP\",\""; // TCP connection
cmd += "184.106.153.149"; // api.thingspeak.com
cmd += "\",80";
espSerial.println(cmd);
if (DEBUG) Serial.println(cmd);
if(espSerial.find("Error")){
if (DEBUG) Serial.println("AT+CIPSTART error");
return false;
}
String getStr = "GET /update?api_key="; // prepare GET string
getStr += apiKey;
getStr +="&field1=";
getStr += String(value1);
getStr +="&field2=";
getStr += String(value2);
getStr +="&field3=";
getStr += String(value3);
// ...
getStr += "\r\n\r\n\r\n";
// send data length
cmd = "AT+CIPSEND=";
cmd += String(getStr.length());
espSerial.println(cmd);
if (DEBUG) Serial.println(cmd);
delay(100);
if(espSerial.find(">")){
espSerial.print(getStr);
if (DEBUG) Serial.print(getStr);
}
else{
espSerial.println("AT+CIPCLOSE");
// alert user
if (DEBUG) Serial.println("AT+CIPCLOSE");
return false;
}
return true;
}
//================================================================================ setup
void setup() {
DEBUG=true; // enable debug serial
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
//pinMode(Temp_pin, INPUT);
pinMode(pinDHT11, INPUT);
//pinMode(Relay_Pin, OUTPUT);
espSerial.begin(9600); // enable software serial
// Your esp8266 module's speed is probably at 115200.
// For this reason the first time set the speed to 115200 or to your esp8266 configured speed
// and upload. Then change to 9600 and upload again
espSerial.println("AT+RST"); // Enable this line to reset the module;
showResponse(1000);
//espSerial.println("AT+UART_CUR=9600,8,1,0,0"); // Enable this line to set esp8266 serial speed to 9600 bps
//showResponse(1000);
espSerial.println("AT+CWMODE=1"); // set esp8266 as client
showResponse(1000);
espSerial.println("AT+CWJAP=\""+ssid+"\",\""+password+"\""); // set your home router SSID and password
showResponse(5000);
if (DEBUG) Serial.println("Setup completed");
}
// ====================================================================== loop
void loop() {
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT11 failed, err="); Serial.println(err);delay(1000);
return;
}
Serial.print((int)temperature);
Serial.println("Degree Centrigrade");
delay(1000);
Serial.print((int)humidity);
Serial.println("% Humidity");
delay(1000);
if (radio.available()){
radio.read(&value, sizeof(value));
}
Serial.print(value);
Serial.println("% Soil Moisture");
delay(1000);
thingSpeakWrite((int)temperature,(int)humidity,value);
// thingspeak needs 15 sec delay between updates,
delay(16000);
Program for Node 3 (Nodemcu+ Relay Module)
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <BlynkSimpleEsp8266.h>
#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
//Replace your wifi credentials here
char auth[] = "DcosB4cnDVf5Kiuli1_v9dj6tgrrU5Ta";
const char* ssid = "Nahu55";//Replace with your Wifi Name
const char* password = "123456789";// Replace with your wifi Password
//change your channel number here
unsigned long channel = 1090610;//Replace with your own ThingSpeak Account Channle ID
//1,2 and 3 are channel fields. You don't need to change if you are following this tutorial. However, you can modify it according to your application
unsigned int Temperature = 1;
unsigned int Humidity = 2;
unsigned int Soil = 3;
unsigned int Relay = 4;
WiFiClient client;
void setup() {
Serial.begin(9600);
delay(100);
pinMode(D8, OUTPUT);
//digitalWrite(D0, 0);
Blynk.begin(auth, ssid, password);
// We start by connecting to a 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");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Netmask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway: ");
Serial.println(WiFi.gatewayIP());
ThingSpeak.begin(client);
}
void loop() {
//get the last data of the fields
int Temperature_1 = ThingSpeak.readFloatField(channel, Temperature);
int Humidity_2 = ThingSpeak.readFloatField(channel, Humidity);
int Soil_3 = ThingSpeak.readFloatField(channel, Soil);
int Relay_4 = ThingSpeak.readFloatField(channel, Relay);
if(Soil_3 <= 60){
digitalWrite(D8, 1);
Serial.println("Motor Is On");
}
else if(Soil_3 >= 90){
digitalWrite(D8, 0);
Serial.println("Motor is Off");
}
Serial.println ("Temperature:");
Serial.println(Temperature_1);
Serial.println("Humidity:");
Serial.println(Humidity_2);
Serial.println ("Soil Moisture Percentage");
Serial.println(Soil_3);
Serial.println("Relay situation");
Serial.println(Relay_4);
delay(2000);
Blynk.virtualWrite(V1, Temperature_1);
Blynk.virtualWrite(V2, Humidity_2);
Blynk.virtualWrite(V3, Soil_3);
Blynk.run();
- Author’s Contribution:
In this Paper, The first Author, Mohammad Shamiur Rahman Al Nahian did the main things of the project. All the wiring, coding, testing, ,circuit desiging and finally data collection all the job have been done by him. The second Author, Arnab Piush Biswas works as research assistant with the first author. During data collection there was some problem and also having some coding problem, there the second author had some contribution. During circuit designing the second author had some electrical issue solved.
- Acknowledgement:
All the praises and the supreme thanks belong to Allah, “Lord of All the Worlds, Most Beneficent and Ever-Merciful”.
The authors wish to express their sincerest appreciation and heartiest gratitude to their supervisor, Prof. Dr. Md. Rokunuzzaman, for his valuable advice, guidance and assistance during the completion of this thesis. Without his advice and support, it would not be possible for us to prepare this report. We wish to thank some senior brothers and sisters of our department who helped us in preparing the report. We also want to mention some of our classmates who also have contributions to our report. In preparing of this report, we have got help from others as they wished to remain anonymous. We owe them with all gratitude.
Authors also like to thank the head of the department Prof. Dr. Mhia Md Zaglul Shahadat
and honorable professors of the Department for their valuable suggestion. We would be thankful if this report comes to any benefit of our teacher as well as any other students of our department.