#include <Arduino.h>
#define BLYNK_PRINT DebugSerial
#include <SimpleTimer.h>
#include <BlynkSimpleStream.h>
#define BLYNK_TEMPLATE_ID "TMPLrc6TTpKj"
#define BLYNK_TEMPLATE_NAME "DO Meter"
#define BLYNK_AUTH_TOKEN "iInD2cJt0fRj3aRISXPLs68LxjtXvlay"
char auth[] = "iInD2cJt0fRj3aRISXPLs68LxjtXvlay";
float analogValue = 0.0;
SimpleTimer timer;
#include "DFRobot_PH.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define PH_PIN A0
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float voltage, phValue, temperature;
DFRobot_PH ph;
int device = 0;
int calibration_pin = 6;
int led = 13;
//Do data//
const unsigned int MAX_MESSAGE_LENGTH = 16;
// Removed SoftwareSerial mySerial(2, 3);
float Temp;
float DO;
void setup()
{
ph.begin();
pinMode(calibration_pin, INPUT_PULLUP);
pinMode(led, OUTPUT);
DebugSerial.begin(115200);
Serial.begin(9600);
Blynk.begin(Serial, auth);
timer.setInterval(1000L, getSendData);
// Removed mySerial.begin(9600);
}
void loop()
{
if (digitalRead(calibration_pin) == LOW)
{
digitalWrite(led, HIGH);
DebugSerial.println("Calibration Mode");
calibration_mode();
}
else
{
digitalWrite(led, LOW);
timer.run();
Blynk.run();
DOCheck();
devicecheck();
}
}
void getSendData()
{
DebugSerial.println("PH Mode");
voltage = analogRead(PH_PIN) / 1024.0 * 5000;
phValue = ph.readPH(voltage, temperature);
DebugSerial.print("pH:");
DebugSerial.println(phValue, 2);
Blynk.virtualWrite(V5, phValue);
}
void calibration_mode()
{
static unsigned long timepoint = millis();
if (millis() - timepoint > 1000U)
{
voltage = analogRead(PH_PIN) / 1024.0 * 5000;
phValue = ph.readPH(voltage, temperature);
DebugSerial.print("pH:");
DebugSerial.println(phValue, 2);
timepoint = millis();
}
ph.calibration(voltage, temperature);
}
void DOCheck() {
//Check to see if anything is available in the serial receive buffer
while (Serial.available() > 0) { // Adjusted to read from Serial instead of mySerial
//Create a place to hold the incoming message
static char message[MAX_MESSAGE_LENGTH];
static unsigned int message_pos = 0;
//Read the next available byte in the serial receive buffer
char inByte = Serial.read(); // Adjusted to read from Serial instead of mySerial
//Message coming in (check not terminating character) and guard for over message size
if (inByte != '\n' && (message_pos < MAX_MESSAGE_LENGTH - 1)) {
//Add the incoming byte to our message
message[message_pos] = inByte;
message_pos++;
}
//Full message received...
else {
//Add null character to string
message[message_pos] = '\0';
//Parse the data stream
int polarity = (message[1] - '0') & 0x03;
int annunLower = message[4] - '0';
int annunHigher = (message[2] - '0') ;//* 10 + (message[4] - '0');
int dpLower = message[5] - '0';
int dpHigher = message[6] - '0';
int displayLower = (message[7] - '0') * 1000 + (message[8] - '0') * 100 + (message[9] - '0') * 10 + (message[10] - '0');
int displayHigher = (message[11] - '0') * 1000 + (message[12] - '0') * 100 + (message[13] - '0') * 10 + (message[14] - '0');
// Print the temperature and DO values
DebugSerial.print("Temperature: ");
//Serial.print(".");
if (dpLower == 1) {
Temp = (displayLower*0.1);
DebugSerial.print(Temp);
}
if (annunHigher == 1) {
DebugSerial.print(" C");
Blynk.virtualWrite(V3,Temp);
} if (annunHigher == 2) {
DebugSerial.print(" F");
Blynk.virtualWrite(V4,Temp);
}
DebugSerial.print(" DO: ");
if (dpHigher == 1) {
DO = (displayHigher*0.1 );
DebugSerial.print( DO );
}
if(annunLower==7){
DebugSerial.print(" mg/L ");
Blynk.virtualWrite(V0,DO);
}
if(annunLower==6)
{
DebugSerial.print(" %O2 ");
Blynk.virtualWrite(V1,DO);
}
DebugSerial.println();
DebugSerial.println(message);
DebugSerial.println(message [2]);
DebugSerial.println(annunLower);
DebugSerial.println(annunHigher);
//Reset for the next message
message_pos = 0;
}
}
}
void devicecheck()
{
int device = 1;
Blynk.virtualWrite(V6, device);
timer.setTimeout(1000, [](){
int device = 0;
Blynk.virtualWrite(V6, device);
});
}
```
This code should now work without relying on SoftwareSerial. It uses the built-in serial communication (`Serial`) for reading data instead.