0% found this document useful (0 votes)
30 views5 pages

Wastewater pH and TDS Monitoring Code

The document is a code for an Arduino-based wastewater monitoring system that measures pH, turbidity, and temperature. It utilizes various sensors and displays the readings on an LCD while controlling solenoids based on pH levels. The system also includes communication with a Virtuino app for remote monitoring and control.

Uploaded by

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

Wastewater pH and TDS Monitoring Code

The document is a code for an Arduino-based wastewater monitoring system that measures pH, turbidity, and temperature. It utilizes various sensors and displays the readings on an LCD while controlling solenoids based on pH levels. The system also includes communication with a Virtuino app for remote monitoring and control.

Uploaded by

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

#include <Wire.

h>
#include "CQRobotTDS.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include "VirtuinoCM.h"
#define espSerial Serial1
VirtuinoCM virtuino;
#define V_memory_count 128
float V[V_memory_count];
boolean debug = false;

#include "DTH_Turbidity.h"

#define TURBIDITY_SENSOR_PIN A2

DTH_Turbidity turbSensor(TURBIDITY_SENSOR_PIN);
float ntu_val = 0;
float volt = 0;

#include "MAX6675.h"
const int dataPin = 16;
const int clockPin = 6;
const int selectPin = 7;
MAX6675 thermoCouple;
uint32_t start, stop;

int phanalog = 0;
CQRobotTDS tds(A1);

void setup() {
// Default I2C pins on Pico: SDA = GP4, SCL = GP5
pinMode(14,OUTPUT);
pinMode(15,OUTPUT);
digitalWrite(14,LOW);
digitalWrite(15,LOW);
[Link](); // No pin arguments needed for default pins
[Link](); // Initialize LCD
[Link](); // Turn on backlight
[Link]();
if (debug) {
[Link](9600); // USB debug monitor
while (!Serial) continue;
}
[Link](clockPin, selectPin, dataPin);
[Link](4000000);
[Link](9600);
[Link](50);
[Link](onReceived,onRequested,256);

[Link](0, 0);
[Link]("WasteWater PH");
delay(1000);

[Link](0, 1);
[Link]("Control Ready");
delay(2000);
[Link]();
}

void loop() {
virtuinoRun();

start = micros();
int status = [Link]();
stop = micros();
float temp = [Link]();

V[1] = temp;
//vDelay(20);
[Link](0,0);
[Link]("T=");
[Link](temp,2);
[Link]("C");

//float temp2 = 30.0; //Calibration at this temperature


float tdsValue = [Link](temp);
[Link](9,1);
[Link]("TDS=");
[Link](tdsValue);
V[3] = tdsValue;
vDelay(1000);

ntu_val = [Link]();
volt = [Link]();
float turb = (100 - (volt*20));
[Link](0,1);
[Link]("t=");
[Link](turb);
V[4] = turb;
vDelay(1000);
phanalog = analogRead(A0);
vDelay(1000);
float voltagePH = phanalog * (3.3 / 1023.0);
float pH1 = 7 + ((2.5 - voltagePH) / 0.55); //0.18 Approx
calibrattion factor
float pH = 14 - pH1;
[Link](9,0);
[Link]("PH=");
[Link](pH);
V[2] = pH;
vDelay(2000);
[Link]();
if(pH < 6)
{
V[5] = 1;
}

if(pH > 8)
{
V[5] = 1;
}
if(pH > 6)
{
if(pH < 8)
{
V[5] = 0;
}
}

if(pH < 6)
{
[Link]();
[Link](0,0);
[Link]("Solenoid 1 0N");

digitalWrite(14,HIGH);
V[6] = 1;
vDelay(2000);
digitalWrite(14,LOW);
V[6] = 0;
vDelay(1000);
}
if(pH > 8)
{
[Link]();
[Link](0,0);
[Link]("Solenoid 2 0N");
digitalWrite(15,HIGH);
V[7] = 1;
vDelay(2000);
digitalWrite(15,LOW);
V[7] = 0;
vDelay(2000);
}
[Link]();

void onReceived(char variableType, uint8_t variableIndex, String


valueAsText){
if (variableType=='V'){
float value = [Link]();
if (variableIndex<V_memory_count) V[variableIndex]=value;
}
}

String onRequested(char variableType, uint8_t variableIndex){


if (variableType=='V') {
if (variableIndex<V_memory_count) return String(V[variableIndex]);
}
return "";
}

void virtuinoRun(){
while ([Link]()) {
char tempChar=[Link]();
if (tempChar==CM_START_CHAR) {
[Link] = String(CM_START_CHAR);
[Link] += [Link](CM_END_CHAR);
[Link] += CM_END_CHAR;
if (debug) [Link]("\nCommand= "+[Link]);
String* response= [Link]();
if (debug) [Link]("Response : "+*response);
[Link](*response);
break;
}
}
}

void vDelay(int delayInMillis){


long t=millis()+delayInMillis;
while (millis()<t) virtuinoRun();
}

Common questions

Powered by AI

The program uses different serial communication strategies for debugging and external device communication. Serial.begin is used for USB debugging via the default Serial port, while espSerial, defined as Serial1, is used for communication with an ESP module handling commands and responses. This dual usage allows for development phase debugging, ensuring accurate data transmission and command processing through different channels .

The ADC (Analog-to-Digital Converter) reading from the pH sensor is converted into a voltage level using the formula: voltagePH = phanalog * (3.3 / 1023.0). Subsequently, the pH value is calculated using the equation: pH = 14 - (7 + ((2.5 - voltagePH) / 0.55)). This transformation assumes a linear relationship between voltage and pH with calibration factors applied to match the sensor's characteristics to standard pH values .

The setup function initializes hardware by setting up the I2C for communication with the LCD, beginning the serial communication, and configuring the MAX6675 thermocouple sensor. It also configures GPIO pins for solenoid control. Initial LCD messages indicate system readiness. Sensor-specific initializations, like setting the SPI speed for the MAX6675, ensure the devices operate reliably according to their respective communication protocols .

Debugging mode is enabled if the 'debug' boolean flag is set to true, which prompts initialization of USB serial communication for debug logging. This mode provides real-time feedback on command processing by outputting logs to the console, aiding in traceability and troubleshooting. When enabled, it can impact program execution by adding overhead to processing and potentially introduce delays, which is why it is optional .

The virtuinoRun function manages incoming serial data from the espSerial object, looking for specific start and end characters to process incoming Virtuino commands. Upon detection, it reads the command, executes Virtuino-specific actions, and sends responses back through the ESP module. This ensures the main loop can handle incoming requests efficiently without interruption, maintaining device control and interactivity .

The program checks if the pH of the wastewater is below 6 or above 8. If below 6, it activates Solenoid 1 to adjust the pH by turning the solenoid ON, signaling through the digitalWrite command. Similarly, if the pH is above 8, Solenoid 2 is activated to correct the pH level. The components involved in this process include the pH sensor and solenoids connected to pins 14 and 15, which are controlled with the digitalWrite function when certain conditions are met .

The program employs if statements to evaluate pH conditions. If the pH is less than 6, it activates solenoid 1 (acid adjustment) by writing HIGH to its GPIO pin, and similarly, if the pH exceeds 8, it activates solenoid 2 (base adjustment). These checks ensure corrective actions are executed only when necessary, showing a clear relation between monitored pH levels and hardware response .

Turbidity is calculated by reading a voltage value from the turbidity sensor, which is converted to a turbidity value using the formula: turbidity = 100 - (volt * 20). This conversion assumes a linear relationship between voltage and turbidity, implying that when voltage varies, the turbidity linearly decreases or increases based on this function. This approach simplifies complex turbidity calculations by assuming a consistent sensor output behavior .

The floating-point array 'V' acts as a memory mechanism to store various sensor values and control signals, indexed correspondingly to represent different states or measurements like temperature, turbidity, and pH. This approach allows different parts of the program to track, update, and react to these stored values dynamically, facilitating a cohesive control and monitoring system across the code's functions .

The setup uses a MAX6675 thermocouple to measure temperature. It initializes the thermocouple with specified data, clock, and select pins, and retrieves the temperature using the getTemperature method. The temperature reading is then stored in an array V and displayed on an LCD screen with a formatted output that includes 'T=' followed by the temperature in Celsius .

You might also like