#include "CQRobotTDS.h"
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include "LiquidCrystal_I2C.h"
#include <SoftwareSerial.h>
//IAM USING HC-05 AND THE APPLICATION IS BLUETERM+ AVELABLE ON GOGLE PLAY FOR FREE
#include <Wire.h>
CQRobotTDS tds(A0);
Adafruit_MPU6050 mpu;
SoftwareSerial bluetoothSerial(10, 11); // RX, TX pins for HC-05
LiquidCrystal_I2C lcd(0x27, 20, 4);
unsigned long timeout = 0;
float BETA = 3950;
void setup() {
Serial.begin(9600);
bluetoothSerial.begin(9600);
lcd.init();
lcd.backlight();
while (!mpu.begin()) {
Serial.println("MPU6050 not connected!");
delay(1000);
}
Serial.println("MPU6050 ready!");
}
sensors_event_t event;
void loop() {
int analogValue = analogRead(A2);
float celsius = 1 / (log(1 / (1023.0 / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
float tdsValue = tds.update(celsius);
mpu.getAccelerometerSensor()->getEvent(&event);
mpu.getGyroSensor()->getEvent(&event);
if (timeout < millis()) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(celsius);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("TDS: ");
lcd.print(tdsValue, 0);
lcd.print(" ppm");
lcd.setCursor(0, 2);
lcd.print("x: ");
lcd.print(event.acceleration.x * 57.33944954128);
lcd.print(" y: ");
lcd.print(event.acceleration.y * 57.33944954128);
lcd.setCursor(0, 3);
lcd.print("z: ");
lcd.print(event.acceleration.z * 57.33944954128);
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" C");
Serial.print("TDS value: ");
Serial.print(tdsValue, 0);
Serial.println(" ppm");
Serial.print("Accelerometer x: ");
Serial.print(event.acceleration.x * 57.33944954128);
Serial.print(" y: ");
Serial.print(event.acceleration.y * 57.33944954128);
Serial.print(" z: ");
Serial.println(event.acceleration.z * 57.33944954128);
Serial.println("");
if (bluetoothSerial.available()) {
char receivedChar = bluetoothSerial.read();
if (receivedChar == 'D') {
bluetoothSerial.println("Program started!");
bluetoothSerial.print("Temperature: ");
bluetoothSerial.print(celsius);
bluetoothSerial.println(" C");
bluetoothSerial.print("TDS value: ");
bluetoothSerial.print(tdsValue, 0);
bluetoothSerial.println(" ppm");
bluetoothSerial.print("Accelerometer x: ");
bluetoothSerial.print(event.acceleration.x * 57.33944954128);
bluetoothSerial.print(" y: ");
bluetoothSerial.print(event.acceleration.y * 57.33944954128);
bluetoothSerial.print(" z: ");
bluetoothSerial.println(event.acceleration.z * 57.33944954128);
bluetoothSerial.println("");
}
if (receivedChar == 'C')
{
Serial.println(bluetoothSerial.read());
}
if (Serial.available()){
bluetoothSerial.write(Serial.read());
}
}
timeout = millis() + 1000;
}
}