Commit 6aaa0202 authored by pramod_a's avatar pramod_a

Merge branch 'master' into Pramod_dev

parents 647f11f2 29f65964
......@@ -12,28 +12,26 @@
#### Main Objective
##### Develop an integrated platform for identification of suitable lands and soil conditions for growing remunerative crops in Sri Lanka and ultimately contribute to the economy
#### Research Questions
1. Can an intergrated system be designed for identification of land, soil conditions and selection of the most suitable crop?
2. Can Sri lanka focus on growing remunerative crops utlizing bare lands?
3. Can this integrated platform contribute to economic growth of the country?
4. Can we implement a system that focuses on accurately identifying diseases and also provide treatment recommendations?
#### Components
<li> Monitor and maintain
healthy growth of crops by
plant disease detection.
</li>
<li> Prediction and analysis to
determine whether the
selected can be grown in
given soil condition.
</li>
<li> Soil testing and identification
of soil conditions using IOT
device.
</li>
<li> Identification of bare lands
using GIS map and remote
sensing approach.
</li>
* Monitor and maintain healthy growth of crops by plant disease detection and treatment recommendation.
* Prediction and analysis to determine whether the selected can be grown in given soil condition.
* Soil testing and identification of soil conditions using IOT device.
* Identification of bare lands using GIS map and remote sensing approach.
<br>
<img src = " Screenshot_2023-04-07_155951.png ">
<br>
......
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <TinyGPS++.h>
HardwareSerial Sender(1);
const char* ssid = "Chamith rulz";
const char* password = "Chamith17321";
String serverName1 = "http://192.168.8.128:8002/api/water-prediction/create";
String serverName2 = "http://192.168.8.128:8002/api/main-device-prediction/create";
unsigned long lastTime1 = 0;
unsigned long timerDelay1 = 15000;
unsigned long lastTime2 = 0;
unsigned long timerDelay2 = 20000;
#define TdsSensorPin 39
#define oneWireBus 15
#define soil 34
#define turbidity 35
#define RXD2 16
#define TXD2 17
#define trigPin1 18
#define echoPin1 19
#define VREF 3.3
#define SCOUNT 30
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define SOUND_SPEED 0.034
int analogBuffer[SCOUNT];
int analogBufferTemp[SCOUNT];
int analogBufferIndex = 0;
int copyIndex = 0;
float averageVoltage = 0;
float tdsValue = 0;
float temperature = 25;
String Latitude, Longitude;
long duration1;
float temperatureC, soildata, turbiditydata, water_temp, distanceCm1,distanceCm;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
TinyGPSPlus gps;
DeviceAddress sensor1 = { 0x28, 0x5C, 0x88, 0x81, 0xE3, 0xF6, 0x3C, 0xE3 };
DeviceAddress sensor2 = { 0x28, 0x76, 0xD6, 0x81, 0xE3, 0x3D, 0x3C, 0x3A };
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
Sender.begin(9600, SERIAL_8N1, RXD2, TXD2);
sensors.begin();
pinMode(TdsSensorPin, INPUT);
pinMode(soil, INPUT);
pinMode(turbidity, INPUT);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
WiFi.begin(ssid, password);
Serial.println("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
}
void loop() {
tdsRead();
probe18b20Read();
probe18b20Read2();
soilRead();
turbidityRead();
displayData();
ultRead1();
if ((millis() - lastTime1) > timerDelay1) {
water_data_send();
lastTime1 = millis();
}
if ((millis() - lastTime2) > timerDelay2) {
device_data_send();
lastTime2 = millis();
}
while (Sender.available() > 0)
if (gps.encode(Sender.read()))
displayInfo();
}
void tdsRead() {
static unsigned long analogSampleTimepoint = millis();
if (millis() - analogSampleTimepoint > 40U) {
analogSampleTimepoint = millis();
analogBuffer[analogBufferIndex] = analogRead(TdsSensorPin);
analogBufferIndex++;
if (analogBufferIndex == SCOUNT) {
analogBufferIndex = 0;
}
}
static unsigned long printTimepoint = millis();
if (millis() - printTimepoint > 800U) {
printTimepoint = millis();
for (copyIndex = 0; copyIndex < SCOUNT; copyIndex++) {
analogBufferTemp[copyIndex] = analogBuffer[copyIndex];
averageVoltage = getMedianNum(analogBufferTemp, SCOUNT) * (float)VREF / 4096.0;
float compensationCoefficient = 1.0 + 0.02 * (temperature - 25.0);
float compensationVoltage = averageVoltage / compensationCoefficient;
tdsValue = (133.42 * compensationVoltage * compensationVoltage * compensationVoltage - 255.86 * compensationVoltage * compensationVoltage + 857.39 * compensationVoltage) * 0.5;
Serial.print("TDS Value: ");
Serial.print(tdsValue, 2);
Serial.println("ppm");
}
}
}
int getMedianNum(int bArray[], int iFilterLen) {
int bTab[iFilterLen];
for (byte i = 0; i < iFilterLen; i++)
bTab[i] = bArray[i];
int i, j, bTemp;
for (j = 0; j < iFilterLen - 1; j++) {
for (i = 0; i < iFilterLen - j - 1; i++) {
if (bTab[i] > bTab[i + 1]) {
bTemp = bTab[i];
bTab[i] = bTab[i + 1];
bTab[i + 1] = bTemp;
}
}
}
if ((iFilterLen & 1) > 0) {
bTemp = bTab[(iFilterLen - 1) / 2];
}
else {
bTemp = (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 - 1]) / 2;
}
return bTemp;
}
void probe18b20Read() {
sensors.requestTemperatures();
temperatureC = sensors.getTempC(sensor1);
Serial.print("Soil temperature : ");
Serial.print(temperatureC);
Serial.println("ºC");
}
void probe18b20Read2() {
sensors.requestTemperatures();
water_temp = sensors.getTempC(sensor2);
Serial.print("water_temp : ");
Serial.print(water_temp);
Serial.println("ºC");
}
void soilRead() {
soildata = analogRead(soil);
soildata=map(soildata,0,4095,0,100);
Serial.print("Soil Data : ");
Serial.println(soildata);
}
void turbidityRead() {
turbiditydata = analogRead(turbidity);
turbiditydata=map(turbiditydata,0,4095,0,100);
Serial.print("Turbidity Data : ");
Serial.println(turbiditydata);
}
void displayData() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(16, 0);
display.println("Welcome to Soil");
display.setCursor(40, 10);
display.println("Analyzer");
display.setCursor(0, 30);
display.print("TDS Value : ");
display.println(tdsValue);
display.print("Soil temp : ");
display.println(temperatureC);
display.print("Soil Data : ");
display.println(soildata);
display.print("Turbidity : ");
display.print(turbiditydata);
display.display();
}
void displayInfo() {
if (gps.location.isValid()) {
Latitude = gps.location.lat();
Longitude = gps.location.lng();
Serial.print(F("Latitude: "));
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(F("Longitude: "));
Serial.println(gps.location.lng(), 6);
} else {
Serial.print(F("INVALID"));
}
Serial.println();
}
void ultRead1() {
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distanceCm1 = duration1 * SOUND_SPEED / 2;
distanceCm=map(distanceCm1,0,50,100,0);
Serial.print("Distance 1 (cm): ");
Serial.println(distanceCm);
}
void water_data_send(){
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
WiFiClient client;
String serverPath = serverName1+"?land=1&temprature="+water_temp+"&tds="+tdsValue+"&turbidity="+turbiditydata+"&ph=15&tanklevel="+distanceCm+"";
Serial.println(serverPath);
http.begin(client, serverPath.c_str());
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
}
void device_data_send(){
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
WiFiClient client;
String serverPath = serverName2+"?land=1&soil_moisture="+soildata+"&temperature="+temperatureC+"&nitrogen=48&phosphorus=12&potassium=124&ph_level=50&lat="+Latitude+"&long="+Longitude+"";
Serial.println(serverPath);
http.begin(client, serverPath.c_str());
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
}
#include <SoftwareSerial.h>
#define RE 2
#define DE 0
//const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
const byte nitro[] = {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01,0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01,0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
byte values[11];
SoftwareSerial mod(14,12);
void setup() {
Serial.begin(9600);
mod.begin(4800);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
Serial.print("Initializing");
delay(3000);
}
void loop() {
byte val1,val2,val3;
val1 = nitrogen();
delay(250);
val2 = phosphorous();
delay(250);
val3 = potassium();
delay(250);
Serial.print("Nitrogen: ");
Serial.print(val1);
Serial.println(" mg/kg");
Serial.print("Phosphorous: ");
Serial.print(val2);
Serial.println(" mg/kg");
Serial.print("Potassium: ");
Serial.print(val3);
Serial.println(" mg/kg");
delay(2000);
}
byte nitrogen(){
digitalWrite(DE,HIGH);
digitalWrite(RE,HIGH);
delay(10);
if(mod.write(nitro,sizeof(nitro))==8){
digitalWrite(DE,LOW);
digitalWrite(RE,LOW);
for(byte i=0;i<7;i++){
//Serial.print(mod.read(),HEX);
values[i] = mod.read();
//Serial.print(values[i],HEX);
}
//Serial.println();
}
return values[4];
}
byte phosphorous(){
digitalWrite(DE,HIGH);
digitalWrite(RE,HIGH);
delay(10);
if(mod.write(phos,sizeof(phos))==8){
digitalWrite(DE,LOW);
digitalWrite(RE,LOW);
for(byte i=0;i<7;i++){
//Serial.print(mod.read(),HEX);
values[i] = mod.read();
//Serial.print(values[i],HEX);
}
//Serial.println();
}
return values[4];
}
byte potassium(){
digitalWrite(DE,HIGH);
digitalWrite(RE,HIGH);
delay(10);
if(mod.write(pota,sizeof(pota))==8){
digitalWrite(DE,LOW);
digitalWrite(RE,LOW);
for(byte i=0;i<7;i++){
//Serial.print(mod.read(),HEX);
values[i] = mod.read();
//Serial.print(values[i],HEX);
}
Serial.println();
}
return values[4];
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment