Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This sketch is use the DS18B20 Liquid Temperature sensor taking readings at 1 second intervals and printing them to the serial monitor
- #include <OneWire.h> //Includes OneWire Library
- #include <DallasTemperature.h> //Includes DallasTemperature Library
- #define ONE_WIRE_BUS 8 //Yellow DS18B20 Signal Wire Connected to Arduino Pin 8
- OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices
- // (not just Maxim/Dallas temperature ICs)
- DallasTemperature sensors(&oneWire); //Pass our oneWire reference to Dallas Temperature.
- float Celsius = 0; //Creates a float variable (decimal) to store the Celsius Temperature Readings and Initializes it to 0
- float Fahrenheit = 0; //Creates a float variable (decimal) to store the Fahrenheit Temperature Readings and Initializes it to 0
- void setup() {
- sensors.begin(); //Starts the sensor working
- Serial.begin(9600); //Starts the serial monitor for someone where view the readings and debug code
- }
- void loop() {
- sensors.requestTemperatures(); //Send the command to get temperature readings
- Celsius = sensors.getTempCByIndex(0); //Stores Celsius Reading to Celsius Variable
- Fahrenheit = sensors.toFahrenheit(Celsius); //Stores Fahrenheit Reading to Celsius Variable
- Serial.print(Celsius); //Prints Celsius Variable Value to Serial Monitor
- Serial.print("°C "); //Prints C Symbol to Serial Monitor - Note: To get degree symbol hold down Alt while pressing 248
- Serial.print(Fahrenheit); //Prints Fahrenheit Variable Value to Serial Monitor
- Serial.println("°F"); //Prints F Symbol to Serial Monitor - Note: To get degree symbol hold down Alt while pressing 248
- delay(1000); //Delays 1000 ms = 1 second between readings - i.e. the frequency of readings
- }
- //Reference: https://create.arduino.cc/projecthub/TheGadgetBoy/ds18b20-digital-temperature-sensor-and-arduino-9cc806
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement