I have seen multiple threads on DS18B20 sensor data, but can't figure out what the issue is in my code.
I want to use the serial plotter to display the temperature data as a function of time. I am using the following piece of code that I modified:
//Include libraries
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup(void)
{
Serial.begin(9600); //Begin serial communication
// Serial.println("Arduino Digital Temperature // Serial Monitor Version"); //Print a message
sensors.begin();
}
void loop(void)
{
// Send the command to get temperatures
sensors.requestTemperatures();
// Serial.print("Temperature is: ");
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(" ");
//Update value every 1 sec.
delay(1000);
}
In the serial monitor, I have the following type of output:
The first step to the solution is that you do not post screenshots of the serial monitor.
You should post the characters of the serial monitor by
mark with pressing ctrl-a
copy to characters to the clipboard with pressing ctrl-c
create a code-section with the < code > -button
paste the clipboard-content by pressing ctrl-v inside the code-section
If you don't know how to do that read here
and as a general advice for all your future questions:
I'm pretty sure that you agree and will follow the way how to solve your problem mimimum 200 minutes faster.
This requires to invest 20 minutes of your precious time to read how to speedup solving your problems.
Directly after registering you got presented informations how to speed up solving your problem.
You should really read it.
if you look at the output of the serial monitor (not plotter) what does it show (upload as text not a screen shot)
may be worth replacing
Serial.print(" ");
with a new line
Serial.println();
EDIT: looking again you only have a delay of a second in loop() - temperature does not change fast therefore you may end up plotting a flat line - suggest 15 second delay