Arduino+DS18B20 Temperature Sensor (buzzer Alarm)

by Lisleapex Blog in Circuits > Arduino

137 Views, 0 Favorites, 0 Comments

Arduino+DS18B20 Temperature Sensor (buzzer Alarm)

Arduino+DS18B20 temperature sensor .png
ds18b20.png

ds18b20

Features: Adaptable to a wide voltage range, 3.0~5.5v, single-wire data transmission, multiple temperature sensors can be connected on three wires, and temperature can be measured at multiple points. When the positive and negative poles are reversed in a short period of time, the chip will not be burned, but it will not work properly.

Measuring temperature range: -55℃~+125℃

Programmable resolution, 9 to 12 bits, respectively 0.5℃, 0.25℃, 0.125℃, 0.0625℃. Default 12-bit precision

Supplies

  • arduino mega2560 (same as uno and other series)


  • ds18b20 temperature sensor (waterproof package)


  • lcd1602A (save io port, external pcf8574, four-wire driver)


  • Some Dupont lines

Circuit

circuit.jpg

ds18b20, an external terminal adapter is connected here. If there is no terminal adapter, just connect an external pull-up resistor of about 1k ohms at the data end (the chip resistor on the module only uses 472 ohms)

Dallas Temperature

Dallas Temperature.png

Call the library and simply implement the function program as follows:

Coding

#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);

}

Testing

Arduino+DS18B20 temperature sensor .png

There is no water put here, just touch the temperature test

Problem1

If the lcd1602IIC address is not 0x27, you can find it through the following program. The serial port sending address

#include <Wire.h> 


void setup() {

  Serial.begin (115200);  

  while (!Serial) { } 

  Serial.println (); 

  Serial.println ("I2C scanner.Scanning ..."); 

  byte count = 0; 

  Wire.begin(); 

  for (byte i = 8; i < 120; i++) {

    Wire.beginTransmission (i);

    if (Wire.endTransmission () == 0) {

      Serial.print ("Found address: ");

      Serial.print (i, DEC); Serial.print (" (0x");

      Serial.print (i, HEX); Serial.println (")");

      count++; delay (1); // maybe unneeded?

    } // end of good response

  } // end of for loop 

  Serial.println ("Done."); 

  Serial.print ("Found "); 

  Serial.print (count, DEC); 

  Serial.println (" device(s)."); 

} // end of setup 


void loop() {}


Problem2

IIC address error.png

IIC address error

There is a potentiometer behind the welded pcf8574 adapter board. If the serial port displays the value normally but the LCD does not display the value, you can adjust the potentiometer and the LCD brightness will be displayed after adjustment.