hello all ! newbie help sorry if this is in the wrong section please move if so .
so im trying to make an accurete digital tempreture sensor
i have a arduino uno and DS18B20 sensor output connected to digital 2 i can get the following sketch working correctly in serial window my question is i also have a serial lcd i would like to display this data with the degrees c symbol in my lcd .
my lcd is a ywrobot 1602 serial lcd module connected as follows SDA to analog 4, SCL to analog 5 ,
i am using the following 2 sketches at the moment. i can get both working independently . i guess i want to combine them ?
temp part
#include <OneWire.h>
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
float temperature = getTemp();
Serial.println(temperature);
delay(100); //just here to slow down the output so it is easier to read
}
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data = ds.read();
-
}*
-
ds.reset_search();*
-
byte MSB = data[1];*
-
byte LSB = data[0];*
-
float tempRead = ((MSB << 8) | LSB); //using two's compliment*
-
float TemperatureSum = tempRead / 16;*
-
return TemperatureSum;*
}
--------------------------------lcd sketch example----------------------------------------------
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
/* Initialise the LiquidCrystal library. The default address is 0x27 and this is a 16x2 line display */
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
_ /* Initialise the LCD */_
- lcd.init();*
- lcd.init();*
}
/* Main program loop */
void loop()
{
_ /* Make sure the backlight is turned on */_ - lcd.backlight();*
_ /* Output the test message to the LCD */_
- lcd.setCursor(0,0); lcd.print("HOBBY COMPONENTS");*
_ lcd.setCursor(0,1); lcd.print("HELLO WORLD");_
_ /* Do nothing */_
- while(1);*
}