Hallo Everyone,
I am collecting temperature sensors data ,but whenever I start my serial monitor ,I get some initial value(garbage or previous values) and afterward i get values as per program ...
I have connected temperature sensor with one wire bus ..
Looking forward to help from you ..
/* Multiple DS18B20 1-Wire digital temperature sensors with Arduino example code. More info: https://www.makerguides.com */
// Include the required Arduino libraries:
#include <OneWire.h>
#include <DallasTemperature.h>
// Define to which pin of the Arduino the 1-Wire bus is connected:
#define ONE_WIRE_BUS 4
// Create a new instance of the oneWire class to communicate with any OneWire device:
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to DallasTemperature library:
DallasTemperature sensors(&oneWire);
int deviceCount = 0;
float tempC;
float tempF;
bool label = true;
void setup() {
// Begin serial communication at a baud rate of 9600:
sensors.begin();
Serial.begin(19200);
// Start up the library:
// Locate the devices on the bus:
deviceCount = sensors.getDeviceCount();
}
void loop() {
// Send the command for all devices on the bus to perform a temperature conversion:
String sensor_name="sensor";
while(label){
for (int i = 0; i < deviceCount; i++) {
String Sensor_Label= String(sensor_name + String(i));
Serial.print(Sensor_Label);
Serial.print(",");
}
Serial.println();
label = false;
}
sensors.requestTemperatures();
// Display temperature from each sensor
for (int i = 0; i < deviceCount; i++) {
tempC = sensors.getTempCByIndex(i);
Serial.print(tempC);
Serial.print(",");
}
Serial.println();
delay(1);
}
and output on serial monitor look like below:



