Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(9, 8, 6, 5, 4, 3);
- //Temperature chip i/o
- OneWire ds(2); // on digital pin 2
- void setup(void) {
- lcd.begin(16, 2);
- }
- void loop(void) {
- float temperature = getTemp();
- lcd.setCursor(0, 0);
- lcd.print("Temp.: ");
- lcd.setCursor(7, 0);
- lcd.print(temperature);
- lcd.setCursor(0, 1);
- if (temperature < 20) {
- lcd.print("Zebeeee :(");
- } else if (temperature > 25) {
- lcd.print("Vroceee :(");
- } else {
- lcd.print("Milina! :)");
- }
- delay(2000); //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]={0x28, 0x79, 0x02, 0xB9, 0x04, 0x00, 0x00, 0x0F};
- 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[i] = 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement