Components and supplies
Resistor 4.75k ohm
Arduino UNO
Standard LCD - 16x2 White on Blue
Breadboard (generic)
Jumper wires (generic)
Single Turn Potentiometer- 10k ohms
DS18B20 Programmable Resolution 1-Wire Digital Thermometer
Apps and platforms
Arduino IDE
Project description
Code
Display on LCD Temperature from DS1820 (max.8)
arduino
1// 03.02.2018 - Writen by Robiuri 2 3#include <LiquidCrystal.h> 4#include <OneWire.h> 5#include <DallasTemperature.h> 6 7LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Initialize the LCD and tell it which pins is 8 // to be used for communicating 9#define ONE_WIRE_BUS 8 // Data wire is plugged into port 8 on the Arduino 10#define precision 9 // OneWire precision Dallas Sensor 11#define contrast 9 // Define the pin that controls the contrast of the screen 12#define bright 10 // Define the pin the controls the brightness of the screen 13#define rows 2 // Define the rows in display LCD 14#define columns 16 // Define the columns in display LCD 15int licznik = 0; // Counter of Dallas sensors 16 17// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) 18OneWire oneWire(ONE_WIRE_BUS); 19 20DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. 21 22DeviceAddress t1, t2, t3, t4, t5, t6, t7, t8; // arrays to hold device addresses 23 24void setup(void) 25{ 26 27 lcd.begin(columns, rows); //Tell the LCD that it is a Columns x Rows LCD 28 pinMode(contrast, OUTPUT); //set pin contrast to OUTPUT 29 pinMode(bright, OUTPUT); //Set pin brightness to OUTPUT 30 digitalWrite(bright, HIGH); //LOW and HIGH <- digitalWrite OR analogWrite value 0-255 240 31 analogWrite(contrast, 50); //LOW and HIGH <- digitalWrite OR analogWrite value 0-255 54 32 lcd.noCursor(); //Disable cursor on LCD 33 lcd.clear(); //Clear Screen on LCD 34 Serial.begin(9600); //Start serial port 35 36 37 Serial.println("Dallas Temperature IC Control Library"); 38 39 // Start up the library 40 sensors.begin(); 41 42 // locate devices on the bus 43 Serial.print("Found: "); 44 Serial.print(sensors.getDeviceCount(), DEC); 45 Serial.println(" Devices."); 46 47 // report parasite power requirements 48 Serial.print("Parasite power is: "); 49 if (sensors.isParasitePowerMode()) Serial.println("ON"); 50 else Serial.println("OFF"); 51 52 // Search for devices on the bus and assign based on an index. Ideally, 53 // you would do this to initially discover addresses on the bus and then 54 // use those addresses and manually assign them (see above) once you know 55 // the devices on your bus (and assuming they don't change). 56 // 57 if (!sensors.getAddress(t1, 0)) Serial.println("No Found Sensor 1"); 58 if (!sensors.getAddress(t2, 1)) Serial.println("No Found Sensor 2"); 59 if (!sensors.getAddress(t3, 2)) Serial.println("No Found Sensor 3"); 60 if (!sensors.getAddress(t4, 3)) Serial.println("No Found Sensor 4"); 61 if (!sensors.getAddress(t5, 4)) Serial.println("No Found Sensor 5"); 62 if (!sensors.getAddress(t6, 5)) Serial.println("No Found Sensor 6"); 63 if (!sensors.getAddress(t7, 6)) Serial.println("No Found Sensor 7"); 64 if (!sensors.getAddress(t8, 7)) Serial.println("No Found Sensor 8"); 65 66 // show the addresses we found on the bus 67 68for (int ilosc =0; ilosc < sensors.getDeviceCount(); ilosc++) { 69 Serial.print("Sensor "); Serial.print(ilosc+1); 70 Serial.print(" Address: "); 71 72 if (ilosc == 0) { printAddress(t1); Serial.println(); 73 } else if (ilosc == 1) { printAddress(t2); Serial.println(); 74 } else if (ilosc == 2) { printAddress(t3); Serial.println(); 75 } else if (ilosc == 3) { printAddress(t4); Serial.println(); 76 } else if (ilosc == 4) { printAddress(t5); Serial.println(); 77 } else if (ilosc == 5) { printAddress(t6); Serial.println(); 78 } else if (ilosc == 6) { printAddress(t7); Serial.println(); 79 } else if (ilosc == 7) { printAddress(t8); Serial.println(); 80 } 81 } 82 83// set the resolution to 9 bit per device 84 85 sensors.setResolution(t1, precision); 86 sensors.setResolution(t2, precision); 87 sensors.setResolution(t3, precision); 88 sensors.setResolution(t4, precision); 89 sensors.setResolution(t5, precision); 90 sensors.setResolution(t6, precision); 91 sensors.setResolution(t7, precision); 92 sensors.setResolution(t8, precision); 93 94 95for (int ilosc =0; ilosc < sensors.getDeviceCount(); ilosc++) { 96 Serial.print("Sensor "); Serial.print(ilosc+1); 97 Serial.print(" Resolution: "); 98 99 if (ilosc == 0) { Serial.print(sensors.getResolution(t1), DEC); Serial.println(); 100 } else if (ilosc == 1) { Serial.print(sensors.getResolution(t2), DEC); Serial.println(); 101 } else if (ilosc == 2) { Serial.print(sensors.getResolution(t3), DEC); Serial.println(); 102 } else if (ilosc == 3) { Serial.print(sensors.getResolution(t4), DEC); Serial.println(); 103 } else if (ilosc == 4) { Serial.print(sensors.getResolution(t5), DEC); Serial.println(); 104 } else if (ilosc == 5) { Serial.print(sensors.getResolution(t6), DEC); Serial.println(); 105 } else if (ilosc == 6) { Serial.print(sensors.getResolution(t7), DEC); Serial.println(); 106 } else if (ilosc == 7) { Serial.print(sensors.getResolution(t8), DEC); Serial.println(); 107 } 108 } 109} 110 111 112// function to print a device address 113void printAddress(DeviceAddress deviceAddress) 114{ 115 for (uint8_t i = 0; i < 8; i++) 116 { 117 // zero pad the address if necessary 118 if (deviceAddress[i] < 16) Serial.print("0"); 119 Serial.print(deviceAddress[i], HEX); 120 } 121} 122 123// function to print the temperature for a device 124void printTemperature(DeviceAddress deviceAddress) 125{ 126 float tempC = sensors.getTempC(deviceAddress); 127 Serial.print("Temp : "); 128 Serial.print(tempC); 129 Serial.print(" Celcius degres "); 130// Serial.print(" Temp F: "); 131// Serial.print(DallasTemperature::toFahrenheit(tempC)); 132} 133 134// function to print a device's resolution 135void printResolution(DeviceAddress deviceAddress) 136{ 137// Serial.print("Resolution: "); 138// Serial.print(sensors.getResolution(deviceAddress)); 139// Serial.println(); 140} 141 142// main function to print information about a device 143void printData(DeviceAddress deviceAddress) 144{ 145 Serial.print("Device Address: "); 146 printAddress(deviceAddress); 147 Serial.print(" "); 148 printTemperature(deviceAddress); 149 Serial.println(); 150} 151 152/* 153 Main function, calls the temperatures in a loop. 154*/ 155void loop(void) 156{ 157 // call sensors.requestTemperatures() to issue a global temperature request to all devices on the bus 158 Serial.print("Reading DATA..."); sensors.requestTemperatures(); Serial.println("DONE"); 159 160 161 // print the device information 162 163for (int ilosc =0; ilosc < sensors.getDeviceCount(); ilosc++) { 164 Serial.print("Sensor "); Serial.print(ilosc+1); Serial.print(" "); 165 166 if (ilosc == 0) { printData(t1); 167 } else if (ilosc == 1) { printData(t2); 168 } else if (ilosc == 2) { printData(t3); 169 } else if (ilosc == 3) { printData(t4); 170 } else if (ilosc == 4) { printData(t5); 171 } else if (ilosc == 5) { printData(t6); 172 } else if (ilosc == 6) { printData(t7); 173 } else if (ilosc == 7) { printData(t8); 174 } 175 } 176 177 if (licznik == sensors.getDeviceCount()) { 178 licznik = 0; // reset counter 179// lcd.clear(); // clear screen on LCD 180 } 181 182 lcd.setCursor(0,0); 183 lcd.print("Sensor Number "); lcd.print(licznik+1); 184 lcd.setCursor(0,1); 185 lcd.print(" Temp: "); 186 if (licznik == 0) { lcd.print(sensors.getTempC(t1)); lcd.write((char)223); lcd.print("C "); 187 } else if (licznik == 1) { lcd.print(sensors.getTempC(t2)); lcd.write((char)223); lcd.print("C "); 188 } else if (licznik == 2) { lcd.print(sensors.getTempC(t3)); lcd.write((char)223); lcd.print("C "); 189 } else if (licznik == 3) { lcd.print(sensors.getTempC(t4)); lcd.write((char)223); lcd.print("C "); 190 } else if (licznik == 4) { lcd.print(sensors.getTempC(t5)); lcd.write((char)223); lcd.print("C "); 191 } else if (licznik == 5) { lcd.print(sensors.getTempC(t6)); lcd.write((char)223); lcd.print("C "); 192 } else if (licznik == 6) { lcd.print(sensors.getTempC(t7)); lcd.write((char)223); lcd.print("C "); 193 } else if (licznik == 7) { lcd.print(sensors.getTempC(t8)); lcd.write((char)223); lcd.print("C "); 194 } 195Serial.print("Licznik="); Serial.println(licznik); 196 197 delay(1750); 198 licznik++ ; 199 200}
Display on LCD Temperature from DS1820 (max.8)
arduino
1// 03.02.2018 - Writen by Robiuri 2 3#include <LiquidCrystal.h> 4#include 5 <OneWire.h> 6#include <DallasTemperature.h> 7 8LiquidCrystal lcd(12, 11, 9 5, 4, 3, 2); // Initialize the LCD and tell it which pins is 10 // 11 to be used for communicating 12#define ONE_WIRE_BUS 8 // Data wire is plugged 13 into port 8 on the Arduino 14#define precision 9 // OneWire precision Dallas 15 Sensor 16#define contrast 9 // Define the pin that controls the contrast of 17 the screen 18#define bright 10 // Define the pin the controls the brightness 19 of the screen 20#define rows 2 // Define the rows in display LCD 21#define 22 columns 16 // Define the columns in display LCD 23int licznik = 0; // 24 Counter of Dallas sensors 25 26// Setup a oneWire instance to communicate with 27 any OneWire devices (not just Maxim/Dallas temperature ICs) 28OneWire oneWire(ONE_WIRE_BUS); 29 30DallasTemperature 31 sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. 32 33DeviceAddress 34 t1, t2, t3, t4, t5, t6, t7, t8; // arrays to hold device addresses 35 36void setup(void) 37{ 38 39 40 lcd.begin(columns, rows); //Tell the LCD that it is a Columns x Rows 41 LCD 42 pinMode(contrast, OUTPUT); //set pin contrast to OUTPUT 43 pinMode(bright, 44 OUTPUT); //Set pin brightness to OUTPUT 45 digitalWrite(bright, HIGH); //LOW 46 and HIGH <- digitalWrite OR analogWrite value 0-255 240 47 analogWrite(contrast, 48 50); //LOW and HIGH <- digitalWrite OR analogWrite value 0-255 54 49 lcd.noCursor(); 50 //Disable cursor on LCD 51 lcd.clear(); //Clear 52 Screen on LCD 53 Serial.begin(9600); //Start serial port 54 55 56 57 Serial.println("Dallas Temperature IC Control Library"); 58 59 // Start 60 up the library 61 sensors.begin(); 62 63 // locate devices on the bus 64 65 Serial.print("Found: "); 66 Serial.print(sensors.getDeviceCount(), DEC); 67 68 Serial.println(" Devices."); 69 70 // report parasite power requirements 71 72 Serial.print("Parasite power is: "); 73 if (sensors.isParasitePowerMode()) 74 Serial.println("ON"); 75 else Serial.println("OFF"); 76 77 // Search for 78 devices on the bus and assign based on an index. Ideally, 79 // you would do this 80 to initially discover addresses on the bus and then 81 // use those addresses 82 and manually assign them (see above) once you know 83 // the devices on your bus 84 (and assuming they don't change). 85 // 86 if (!sensors.getAddress(t1, 0)) Serial.println("No 87 Found Sensor 1"); 88 if (!sensors.getAddress(t2, 1)) Serial.println("No Found 89 Sensor 2"); 90 if (!sensors.getAddress(t3, 2)) Serial.println("No Found Sensor 91 3"); 92 if (!sensors.getAddress(t4, 3)) Serial.println("No Found Sensor 4"); 93 94 if (!sensors.getAddress(t5, 4)) Serial.println("No Found Sensor 5"); 95 if 96 (!sensors.getAddress(t6, 5)) Serial.println("No Found Sensor 6"); 97 if (!sensors.getAddress(t7, 98 6)) Serial.println("No Found Sensor 7"); 99 if (!sensors.getAddress(t8, 7)) 100 Serial.println("No Found Sensor 8"); 101 102 // show the addresses we found 103 on the bus 104 105for (int ilosc =0; ilosc < sensors.getDeviceCount(); ilosc++) 106 { 107 Serial.print("Sensor "); Serial.print(ilosc+1); 108 Serial.print(" 109 Address: "); 110 111 if (ilosc == 0) { printAddress(t1); Serial.println(); 112 113 } else if (ilosc == 1) { printAddress(t2); Serial.println(); 114 } else if (ilosc 115 == 2) { printAddress(t3); Serial.println(); 116 } else if (ilosc == 3) { printAddress(t4); 117 Serial.println(); 118 } else if (ilosc == 4) { printAddress(t5); Serial.println(); 119 120 } else if (ilosc == 5) { printAddress(t6); Serial.println(); 121 } else 122 if (ilosc == 6) { printAddress(t7); Serial.println(); 123 } else if (ilosc 124 == 7) { printAddress(t8); Serial.println(); 125 } 126 } 127 128// set the resolution 129 to 9 bit per device 130 131 sensors.setResolution(t1, precision); 132 sensors.setResolution(t2, 133 precision); 134 sensors.setResolution(t3, precision); 135 sensors.setResolution(t4, 136 precision); 137 sensors.setResolution(t5, precision); 138 sensors.setResolution(t6, 139 precision); 140 sensors.setResolution(t7, precision); 141 sensors.setResolution(t8, 142 precision); 143 144 145for (int ilosc =0; ilosc < sensors.getDeviceCount(); ilosc++) 146 { 147 Serial.print("Sensor "); Serial.print(ilosc+1); 148 Serial.print(" 149 Resolution: "); 150 151 if (ilosc == 0) { Serial.print(sensors.getResolution(t1), 152 DEC); Serial.println(); 153 } else if (ilosc == 1) { Serial.print(sensors.getResolution(t2), 154 DEC); Serial.println(); 155 } else if (ilosc == 2) { Serial.print(sensors.getResolution(t3), 156 DEC); Serial.println(); 157 } else if (ilosc == 3) { Serial.print(sensors.getResolution(t4), 158 DEC); Serial.println(); 159 } else if (ilosc == 4) { Serial.print(sensors.getResolution(t5), 160 DEC); Serial.println(); 161 } else if (ilosc == 5) { Serial.print(sensors.getResolution(t6), 162 DEC); Serial.println(); 163 } else if (ilosc == 6) { Serial.print(sensors.getResolution(t7), 164 DEC); Serial.println(); 165 } else if (ilosc == 7) { Serial.print(sensors.getResolution(t8), 166 DEC); Serial.println(); 167 } 168 } 169} 170 171 172// function to print a device 173 address 174void printAddress(DeviceAddress deviceAddress) 175{ 176 for (uint8_t 177 i = 0; i < 8; i++) 178 { 179 // zero pad the address if necessary 180 if 181 (deviceAddress[i] < 16) Serial.print("0"); 182 Serial.print(deviceAddress[i], 183 HEX); 184 } 185} 186 187// function to print the temperature for a device 188void 189 printTemperature(DeviceAddress deviceAddress) 190{ 191 float tempC = sensors.getTempC(deviceAddress); 192 193 Serial.print("Temp : "); 194 Serial.print(tempC); 195 Serial.print(" Celcius 196 degres "); 197// Serial.print(" Temp F: "); 198// Serial.print(DallasTemperature::toFahrenheit(tempC)); 199} 200 201 202// function to print a device's resolution 203void printResolution(DeviceAddress 204 deviceAddress) 205{ 206// Serial.print("Resolution: "); 207// Serial.print(sensors.getResolution(deviceAddress)); 208// 209 Serial.println(); 210} 211 212// main function to print information about a device 213void 214 printData(DeviceAddress deviceAddress) 215{ 216 Serial.print("Device Address: 217 "); 218 printAddress(deviceAddress); 219 Serial.print(" "); 220 printTemperature(deviceAddress); 221 222 Serial.println(); 223} 224 225/* 226 Main function, calls the temperatures in 227 a loop. 228*/ 229void loop(void) 230{ 231 // call sensors.requestTemperatures() 232 to issue a global temperature request to all devices on the bus 233 Serial.print("Reading 234 DATA..."); sensors.requestTemperatures(); Serial.println("DONE"); 235 236 237 238 // print the device information 239 240for (int ilosc =0; ilosc < sensors.getDeviceCount(); 241 ilosc++) { 242 Serial.print("Sensor "); Serial.print(ilosc+1); Serial.print(" 243 "); 244 245 if (ilosc == 0) { printData(t1); 246 } else if (ilosc == 1) { 247 printData(t2); 248 } else if (ilosc == 2) { printData(t3); 249 } else if (ilosc 250 == 3) { printData(t4); 251 } else if (ilosc == 4) { printData(t5); 252 } 253 else if (ilosc == 5) { printData(t6); 254 } else if (ilosc == 6) { printData(t7); 255 256 } else if (ilosc == 7) { printData(t8); 257 } 258 } 259 260 if (licznik 261 == sensors.getDeviceCount()) { 262 licznik = 0; // reset counter 263// 264 lcd.clear(); // clear screen on LCD 265 } 266 267 lcd.setCursor(0,0); 268 269 lcd.print("Sensor Number "); lcd.print(licznik+1); 270 lcd.setCursor(0,1); 271 272 lcd.print(" Temp: "); 273 if (licznik == 0) { lcd.print(sensors.getTempC(t1)); 274 lcd.write((char)223); lcd.print("C "); 275 } else if (licznik == 1) { lcd.print(sensors.getTempC(t2)); 276 lcd.write((char)223); lcd.print("C "); 277 } else if (licznik == 2) { lcd.print(sensors.getTempC(t3)); 278 lcd.write((char)223); lcd.print("C "); 279 } else if (licznik == 3) { lcd.print(sensors.getTempC(t4)); 280 lcd.write((char)223); lcd.print("C "); 281 } else if (licznik == 4) { lcd.print(sensors.getTempC(t5)); 282 lcd.write((char)223); lcd.print("C "); 283 } else if (licznik == 5) { lcd.print(sensors.getTempC(t6)); 284 lcd.write((char)223); lcd.print("C "); 285 } else if (licznik == 6) { lcd.print(sensors.getTempC(t7)); 286 lcd.write((char)223); lcd.print("C "); 287 } else if (licznik == 7) { 288 lcd.print(sensors.getTempC(t8)); lcd.write((char)223); lcd.print("C "); 289 } 290Serial.print("Licznik="); 291 Serial.println(licznik); 292 293 delay(1750); 294 licznik++ ; 295 296}
Downloadable files
Schematics
Schematics
DS1802 Temperature Display on LCD
DS1802 Temperature Display on LCD
Schematics
Schematics
Comments
Only logged in users can leave comments
Robiuri
0 Followers
•0 Projects
Table of contents
Intro
20
0