This circuit utilizes an ESP32 microcontroller to interface with various sensors and LEDs. The ESP32 reads data from a TCS3200 color sensor, a TDS sensor, and a pH sensor. It also controls three LEDs (red, green, and yellow) to indicate different statuses. The data collected from the sensors is sent to ThingSpeak for remote monitoring.
ESP32 (30 pin)
TCS3200
Resistor (200 Ohms)
LED: Two Pin (red)
LED: Two Pin (green)
LED: Two Pin (yellow)
TDS Sensor 2
pH Sensor (ph4502c)
7.4v Battery
/*
ESP32 TCS3200 Color sensor
http:://www.electronicwings.com
*/
#include <WiFi.h>
#include "ThingSpeak.h"
#define S0 5
#define S1 21
#define S2 18 /*Define S2 Pin Number of ESP32*/
#define S3 19 /*Define S3 Pin Number of ESP32*/
#define sensorOut 14 /*Define Sensor Output Pin Number of ESP32*/
#define LED_PIN 13
#define LED_PIN_1 12
#define TdsSensorPin 34 // Analog pin for the TDS sensor (use a valid ADC pin on ESP32)
#define VREF 3.3 // Analog reference voltage (Volt) of the ESP32 ADC
#define SCOUNT 30 // Number of samples for averaging
const char* ssid = "Neero3110"; // your network SSID (name)
const char* password = "123123123"; // your network password
WiFiClient client;
unsigned long myChannelNumber = 1;
const char * myWriteAPIKey = "P8Q9DC7AFSFYNZX9";
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;
int analogBuffer[SCOUNT]; // Store the analog values in an array
int analogBufferTemp[SCOUNT]; // Temporary buffer for median filtering
int analogBufferIndex = 0, copyIndex = 0;
float averageVoltage = 0, tdsValue = 0, temperature = 25.0; // Set default temperature
/*Enter the Minimum and Maximum Values which getting from Calibration Code*/
int R_Min = 111; /*Red minimum value*/
int R_Max = 359; /*Red maximum value*/
int G_Min = 108; /*Green minimum value white*/
int G_Max = 351; /*Green maximum value black*/
int B_Min = 104; /*Blue minimum value*/
int B_Max = 310; /*Blue maximum value*/
int color_health = 0;
/*Define int variables*/
int Red = 0;
int Green = 0;
int Blue = 0;
int redValue;
int greenValue;
int blueValue;
int pulseWidth;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT); /*Define S2 Pin as a OUTPUT*/
pinMode(S3, OUTPUT);
pinMode(TdsSensorPin, INPUT); // Set TDS pin as input
pinMode(LED_PIN, OUTPUT);
pinMode(sensorOut, INPUT); /*Define Sensor Output Pin as a INPUT*/
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW); //20%
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
Serial.begin(115200); /*Set the baudrate to 115200*/
//delay(1000); /*Wait for 1000mS*/
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect");
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, password);
delay(5000);
}
Serial.println