Lisleapex Blog
Published

Arduino+DS18B20 Temperature Sensor (buzzer Alarm)

Features: Adaptable to a wide voltage range, 3.0~5.5v, single-wire data transmission, multiple temperature sensors can be connected on three

BeginnerWork in progress2 hours33
Arduino+DS18B20 Temperature Sensor (buzzer Alarm)

Things used in this project

Hardware components

arduino mega2560
×1
ds18b20
×1
lcd1602A
×1
Dupont lines
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

circuit_UUEgcm4a3v.jpg

Code

Untitled file

Arduino
#include <OneWire.h>

#include <LiquidCrystal_I2C.h> //4-pin pcf8574 driver lcd1602 library

#include <DallasTemperature.h> //ds18b20 library

#define buzzpin 6 //Define buzzer pin 6

#define Onewire_bus 7 //ds18b20 connects to pin 7

OneWire oneWire(Onewire_bus);

DallasTemperature sensors(&oneWire);

LiquidCrystal_I2C lcd(0x27,16,2); //The I2C address of LCD1602 is 0x27. LCD1602 is a two-line, 16-character LCD display.

void setup() {

  // put your setup code here, to run once:

  Serial.begin(9600);

  lcd.init(); // Execute LCD I2C communication initialization twice

  delay(20);

  lcd.init();

  delay(20);

  lcd.backlight();//Light up the LCD backlight

}



void loop() {

  // put your main code here, to run repeatedly:

  delay(50);

  Serial.print("Get temperature:"); // Send a few words

  sensors.requestTemperatures(); //Get the temperature

  Serial.println(sensors.getTempCByIndex(0));

  lcd.setCursor(0, 0); // Move the LCD cursor to the first position 0, 0 (column, row)

  lcd.print("temp:");

  lcd.print(sensors.getTempCByIndex(0)); // Sensor temperature value

  lcd.print(" C"); // Continue writing the previous statement

  if(sensors.getTempCByIndex(0)>40) //Alarm when temperature is greater than 40

  {

   digitalWrite(buzzpin,HIGH);

  }

  else

  {

   digitalWrite(buzzpin,LOW);

   }

   delay(10);

}

Credits

Lisleapex Blog

Lisleapex Blog

15 projects β€’ 0 followers
Fast Delivery of High-Quality Electronic Components

Comments