Hello! I am creating a project for Arduino Uno with connected sensors:
-
Temperature Sensor - Waterproof (DS18B20)
-
Gravity: Analog pH Sensor/Meter Kit V2
The aim of the project is to collect data from the environment (pH value and Temperature). The project was also enriched with the Bluetooth HC-05 module.
I would like to collect data by the sensors, and next send to the "Serial Bluetooth Terminal" app and display automatically (devices pair easily; Smartphone + HC-05). How should I modify my code to make it works.
Additionally, I can say, that the data is displayed correctly in the "Serial Monitor" of the Arduino IDE on my computer.
I would be very grateful for all the tips.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SoftwareSerial.h> //Bluetooth
SoftwareSerial BluetoothSerial(0, 1); // RX | TX
#define BT_SERIAL_TX 1
#define BT_SERIAL_RX 0
#define SensorPin 1 //pH meter Analog output to Arduino Analog Input 1
#define ONE_WIRE_BUS 2 // Data wire is plugged into digital pin 2 on the Arduino
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire device
DallasTemperature sensors(&oneWire); // Pass oneWire reference to DallasTemperature library
unsigned long int avgValue; //Store the average value of the sensor feedback
float b;
int buf[10],temp;
void setup()
{
BluetoothSerial.begin(9600); //BT baud rate
delay(1000);
//Temperature Sensor
sensors.begin(); // Start up the library
Serial.begin(9600);
//pH Sensor
pinMode(13,OUTPUT);
Serial.begin(9600);
}
void loop()
{
{// Send the command to get temperatures
sensors.requestTemperatures();
//print the temperature in Celsius
Serial.print("T: ");
Serial.print(sensors.getTempCByIndex(0));
Serial.println(" C ");
//print Temp. in BT
BluetoothSerial.print("T: ");
BluetoothSerial.print(sensors.getTempCByIndex(0));
BluetoothSerial.println(" C ");
}
//pH loop
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(SensorPin);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
phValue=3.5*phValue; //convert the millivolt into pH value
Serial.print("pH:");
Serial.print(phValue,2);
Serial.println(" ");
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
//delay(500); //od temp.
BluetoothSerial.print("pH:");
BluetoothSerial.print(phValue,2);
BluetoothSerial.println(" ");
}