Silícios LabPCBWay
Published © GPL3+

Fault Detection System for DS18B20 Sensor | Big Utility

Learn how to implement a code to verify the operation of the DS18B20 temperature sensor and inform in real time through the 16x2 LCD.

BeginnerFull instructions provided30 minutes4,102
Fault Detection System for DS18B20 Sensor | Big Utility

Things used in this project

Hardware components

PCBWay Custom PCB
PCBWay Custom PCB
×1
Arduino UNO R3 - UTSOURCE
×1
LCD 16x2 Display - UTSOURCE
×1
DS18B20 Temperature Sensor - UTSOURCE
×1
Power Supply 9V/2A - UTSOURCE
×1
Jumper Wires - UTSOURCE
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Story

Read more

Schematics

Schematic of the Circuit

Code

Fault Detection System for DS18B20

Arduino
#include <OneWire.h> //OneWire Library for DS18B20 Sensor
#include <DallasTemperature.h> //Library with all function of DS18B20 Sensor
#include <LiquidCrystal.h> //Library for LCD 16 x 2
 
#define ONE_WIRE_BUS 8 //Digital Pin to connect the DS18B20 Sensor
 
//Define uma instancia do oneWire para comunicacao com o sensor
OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);
DeviceAddress sensor1;

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

bool ControlAccess = 0;

void setup(void)
{
  Serial.begin(9600);
  sensors.begin();
  lcd.begin(16, 2);
  
  // Localiza e mostra enderecos dos sensores
  Serial.println("Localizando sensores DS18B20...");
  Serial.print("Sensor Localization successfully!");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" Sensor");
  
      do
      {
        if (!sensors.getAddress(sensor1, 0))
        {               
            
            if(ControlAccess == 0)
            {
              lcd.clear();
              lcd.setCursor(3,0);
              lcd.print("Sensor not");
              lcd.setCursor(5,1);
              lcd.print("found!");
              ControlAccess = 1;
            }
            
          Serial.println("Sensor not found!");
        }
      }while(!sensors.getAddress(sensor1, 0));
          ControlAccess = 0;
}

void loop()
{
  //Request sensor data
  sensors.requestTemperatures();
  float tempC = sensors.getTempC(sensor1); //Read temperature of DS18B20 Sensor
   
  //Show the temperature on the LCD 16x2
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("Temperature");
  
  lcd.setCursor(4,1);
  lcd.print(tempC);
  lcd.write(223);
  lcd.print("C");
  
  delay(3000);

  //Verificação do Funcionamento do Sensor de Temperatura
  Serial.print("Sensor Localization successfully!");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" Sensor");

      do
      {
        if (!sensors.getAddress(sensor1, 0))
        {               
            
            if(ControlAccess == 0)
            {
              lcd.clear();
              lcd.setCursor(3,0);
              lcd.print("Sensor not");
              lcd.setCursor(5,1);
              lcd.print("found!");
              ControlAccess = 1;
            }
            
          Serial.println("Sensor not found!");
        }
      }while(!sensors.getAddress(sensor1, 0));
          ControlAccess = 0;
}

Credits

Silícios Lab

Silícios Lab

73 projects • 173 followers
Hello, I love program microcontrollers and works with electronic projects.
PCBWay

PCBWay

91 projects • 146 followers
We are a PCB and assembly manufacturer, As low as $5/10pcs and 24 hours delivery time. We are committed to helping creators build project.

Comments