Monday, June 27, 2022

Arduino and DS18B20 Temperature Controlling Example

 A temperature controller can be found anywhere in the market at low cost. However we can create it one using an analog circuit, or even a programmable device. Here I create an Arduino-based temperature controller using some components:

  1. An Arduino Uno board
  2. A DS18B20 temperature sensor
  3. A 5V relay module
  4. A character LCD with some other components and accessary.
Arduino and DS18B20 Temperature Controlling Example
Circuit prototyping on breadboard

The controller request and get temperature data from DS18B20 in degree Celsius. The display show either Celsius and degree Fahrenheit. It updates the data for every 5 seconds. I set in program for a condition for the temperature above 30 degree Celsius. Whenever it's true an output relay connects to pin 13 will turn on.

Arduino and DS18B20 Temperature Controlling Example
Schematic Diagram

I use DallasTemperature.h file due to its simplicity. 

  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. #include <LiquidCrystal.h>
  4.  
  5. //LCD Connection RS EN D4...D7
  6. LiquidCrystal lcd(7,8,9,10,11,12);
  7.  
  8. OneWire oneWire(4);
  9.  
  10. DallasTemperature sensors(&oneWire);
  11.  
  12. //Relay Output Pin
  13. const int relay=13;
  14.  
  15. void setup(){
  16. pinMode(relay,OUTPUT);
  17. //Start up the 1-Wire Library
  18. sensors.begin();
  19. lcd.begin(16,2);
  20. lcd.print("ds18B20 Example");
  21. delay(3000);
  22. lcd.clear();
  23. }
  24.  
  25. float getC,getF;
  26.  
  27. void loop(){
  28. //Send the command to get Temperature
  29. sensors.requestTemperatures();
  30. getC=sensors.getTempCByIndex(0);
  31. getF=DallasTemperature::toFahrenheit(getC);
  32.  
  33. if(int(getC)>=30) digitalWrite(relay,HIGH);
  34. else digitalWrite(relay,LOW);
  35.  
  36. lcd.home();
  37. lcd.print("Temperature: ");
  38. lcd.setCursor(0,1);
  39. lcd.print(String(getC,1)+char(223)+"C"+" "+String(getF,1)+char(223)+"F");
  40. delay(5000);
  41. }

Click here to download its source file.


No comments:

Post a Comment

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)