0% found this document useful (0 votes)
21 views3 pages

GT 16 Source Code

The document contains an Arduino sketch for an ESP32 microcontroller that reads temperature and electrical conductivity (EC) values using various sensors and displays the data on an OLED screen. It connects to WiFi and sends the readings to ThingSpeak using an API key. The code includes setup and loop functions for initializing the display, reading sensor data, and posting the data to a remote server.

Uploaded by

KOUASHIK SARAF
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

GT 16 Source Code

The document contains an Arduino sketch for an ESP32 microcontroller that reads temperature and electrical conductivity (EC) values using various sensors and displays the data on an OLED screen. It connects to WiFi and sends the readings to ThingSpeak using an API key. The code includes setup and loop functions for initializing the display, reading sensor data, and posting the data to a remote server.

Uploaded by

KOUASHIK SARAF
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include <Arduino.

h>
#include <Wire.h>
#include <EEPROM.h>
#include <WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_ADS1015.h>
#include <DFRobot_ESP_EC.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels


#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)


Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

#define ONE_WIRE_BUS 14 // this is the gpio pin 13 on esp32.


OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DFRobot_ESP_EC ec;
Adafruit_ADS1115 ads;

float voltage, ecValue, temperature = 25;

String apiKey = "**************"; // Enter your Write API key from ThingSpeak

const char *ssid = "**************"; // replace with your wifi ssid and wpa2 key
const char *pass = "**************";
const char* server = "[Link]";

WiFiClient client;

void setup()
{
[Link](115200);
[Link](32);//needed [Link] to store calibration k in eeprom
[Link]();
[Link]();
if (![Link](SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
[Link](F("SSD1306 allocation failed"));
for (;;);
}
delay(2000);
[Link]();
[Link]("Connecting to ");
[Link](ssid);vgy

[Link](ssid, pass);

while ([Link]() != WL_CONNECTED)


{
delay(500);
[Link](".");
}
[Link]("");
[Link]("WiFi connected");
}

void loop()
{
voltage = analogRead(A0); // A0 is the gpio 36
[Link]();
temperature = [Link](0); // read your temperature sensor to execute
temperature compensation
ecValue = [Link](voltage, temperature); // convert voltage to EC with temperature
compensation

[Link]("Temperature:");
[Link](temperature, 2);
[Link]("ºC");

[Link]("EC:");
[Link](ecValue, 2);

[Link](2);
[Link](WHITE);

[Link](0, 10);
[Link]("T:");
[Link](temperature, 2);
[Link](85, 10, 2, WHITE); // put degree symbol ( ° )
[Link](90, 10);
[Link]("C");

[Link](0, 40);
[Link]("EC:");
[Link](ecValue, 2);
[Link]();
delay(1500);
[Link]();
[Link](voltage, temperature); // calibration process by Serail CMD

if ([Link](server, 80)) // "[Link]" or [Link]


{

String postStr = apiKey;


postStr += "&field1=";
postStr += String(temperature, 2);
postStr += "&field2=";
postStr += String(ecValue, 2);
postStr += "\r\n\r\n";
delay(500);

[Link]("POST /update HTTP/1.1\n");


[Link]("Host: [Link]\n");
[Link]("Connection: close\n");
[Link]("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
[Link]("Content-Type: application/x-www-form-urlencoded\n");
[Link]("Content-Length: ");
[Link]([Link]());
[Link]("\n\n");
[Link](postStr);
delay(500);
}
[Link]();
}

You might also like