arduino-experiments

Introduction

This experiment uses the DS18B20 temperature sensor to measure the ambient temperature and display it on the serial monitor. The DS18B20 is a digital thermometer with a wide temperature range and high accuracy.

Components Needed

No Ads Available.

Circuit Setup

  1. Connect the VCC pin of the DS18B20 to the 5V pin on the Arduino.
  2. Connect the GND pin to GND on the Arduino.
  3. Connect the DATA pin to pin 2 on the Arduino.
  4. Place a 4.7kΩ resistor between the DATA and VCC pins to act as a pull-up resistor.

Ensure that the sensor is correctly connected and powered before starting the experiment.

Code for Digital Thermometer

Upload the following code to your Arduino to read temperature data:


#include 
#include 

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(9600);
  sensors.begin();
}

void loop() {
  sensors.requestTemperatures();
  Serial.print("Temperature: ");
  Serial.print(sensors.getTempCByIndex(0));
  Serial.println(" C");
  delay(1000);
}
            

Explanation

This code reads the temperature data from the DS18B20 sensor and displays it on the serial monitor. Here's a breakdown of the code:

Troubleshooting

Contact Us

If you have any questions or inquiries, feel free to reach out to us at Microautomation.no@icloud.com .

Follow our Socials for the newest updates!