FRED
Published © CC BY-NC-ND

Real Time Water Quality Monitoring System in The Wild

Automated water quality measurement systems provides cheaper, reliable scalable and easier to deploy alternatives to quality monitoring.

BeginnerWork in progress3 days270
Real Time Water Quality Monitoring System in The Wild

Things used in this project

Hardware components

SenseCAP K1100 - The Sensor Prototype Kit with LoRa® and AI
Seeed Studio SenseCAP K1100 - The Sensor Prototype Kit with LoRa® and AI
×1

Software apps and online services

Arduino IDE
Arduino IDE
ThingSpeak API
ThingSpeak API

Hand tools and fabrication machines

Desoldering Braid, Soder-Wick®
Desoldering Braid, Soder-Wick®
Tape, Masking
Tape, Masking

Story

Read more

Schematics

Prototype Schematic

Code

Sessors , TCP connection and WIO Terminal

C/C++
//include libraries
#include "rpcWiFi.h" //Wi-Fi library 
#include "DHT.h" //DHT library
#include "TFT_eSPI.h" //TFT LCD library 
#include "Free_Fonts.h" //free fonts library 
#include "SGP30.h" // coSensor

TFT_eSPI tft; //initialize TFT LCD
TFT_eSprite spr = TFT_eSprite(&tft); //initialize sprite buffer


#define DHTPIN 0 //define Signal Pin of DHT
#define DHTTYPE DHT11 //define DHT Sensor Type
DHT dht(DHTPIN, DHTTYPE); //initialize DHT sensor
#define DHTPIN 1 //define Signal Pin of DHT
#define SGPTYPE SGP30 //define sgp Sensor Type
SGP30 sgp(DHTPIN, DHTTYPE); //initialize sgp sensor
 
const char* ssid = "*****"; //Wi-Fi name    
const char* password =  "******"; //Wi-Fi password 


const char* serverName = "api.thingspeak.com"; //Domain Name for HTTP POST Request
String apiKey = "********"; //"Write API Key" from ThingSpeak

// Use WiFiClient class to create TCP connections
WiFiClient client;
 
void setup() {
  Serial.begin(115200); //start serial communication
  while (!Serial); //wait for Serial to be ready
  delay(100);
 
  WiFi.mode(WIFI_STA); //set WiFi to station mode 
  WiFi.disconnect(); //disconnect from an AP if it was previously connected
 
  Serial.println("Connecting to WiFi.."); //print string 
  WiFi.begin(ssid, password); //connect to Wi-Fi network
 
  // attempt to connect to Wi-Fi network:
  while (WiFi.status() != WL_CONNECTED) {
      Serial.print(".");
      // wait 1 second for re-trying
      delay(1000);
  }
    
  Serial.print("Connected to ");
  Serial.println(ssid); //print Wi-Fi name 
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP()); //print Wio Terminal's IP address
  Serial.println(""); //print empty line

  sgp.begin(); //Start DHT sensor
  
void loop() {
  Serial.print("Connecting to ");
  Serial.println(serverName); //print server IP address

  //check whether Wio Terminal is connected to server
  if (!client.connect(serverName, 80)) {  //80 is default port of HTTP
      Serial.println("Connection failed!");
  } else {
      Serial.println("Connected to server!");
      int t = dht.readTemperature(); //Assign variable to store temperature
  int h = dht.readHumidity(); //Assign variable to store humidity
  int c = SGP30.readCarbondioxide();

  //data needed to send along with API key
  String postStr = apiKey;
  postStr +="&field1=";
  postStr += String(t);
  postStr += "&field2=";
  postStr += String(h);
  postStr += "&field3=";
  postStr += String(c);
  postStr += "\r\n\r\n";

  //make an HTTP POST request
  client.print("POST /update HTTP/1.1\n");
  client.print("Host: api.thingspeak.com\n");
  client.print("Connection: close\n");
  client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
  client.print("Content-Type: application/x-www-form-urlencoded\n");
  client.print("Content-Length: ");
  client.print(postStr.length());
  client.print("\n\n");
  client.print(postStr);

  //display sensor data on serial monitor 
  Serial.print("temperature: "); //print string
  Serial.println(t); //print data stored in t
  Serial.print("Humidity:");
   Serial.println(h);
  Serial.print("Carbondioxide:");
  Serial.println(c);
                             
  Serial.println("Sent to Thingspeak.");

      
  //sprite buffer for temperature
  spr.createSprite(55, 40); //create buffer
  spr.fillSprite(TFT_BLACK); //fill background color of buffer
  spr.setFreeFont(FMB24); //set font type 
  spr.setTextColor(TFT_WHITE); //set text color
  spr.drawNumber(t, 0, 0); //display number 
  spr.pushSprite(200, 70); //push to LCD 
  spr.deleteSprite(); //clear buffer

  //sprite buffer for humidity 
  spr.createSprite(55, 40);
  spr.fillSprite(TFT_BLACK);
  spr.setFreeFont(FMB24);
  spr.setTextColor(TFT_WHITE);
  spr.drawNumber(h, 0, 0); 
  spr.pushSprite(155, 170);
  spr.deleteSprite();
  
  //sprite buffer for carbondioxide 
  spr.createSprite(55, 40);
  spr.fillSprite(TFT_BLACK);
  spr.setFreeFont(FMB24);
  spr.setTextColor(TFT_WHITE);
  spr.drawNumber(h, 0, 0); 
  spr.pushSprite(145, 180);
  spr.deleteSprite();
  
  }
  
  client.stop(); //disconnect from server
  //wait 10 seconds to send the next POST request
  Serial.println("Waiting...");
  delay(10000);
}

Credits

FRED

FRED

1 project • 2 followers

Comments