Combining

Hi

I have tried to merging two sketches but with no success.With this sketch I would also like
to control a relay.For example to get high at 20 degrees celcius.Can somebody tell what I have to add
to this file to get it work.Sorry about my english.Hope you understand.
One alternative is of course to use two Arduino board but would like try this way first.

Thanks
Jan

sketch_feb26h.ino (1.35 KB)

Can you please post your code in code tags (the </> button), so its easy to read?

Try this, in line 10 change relay pin to whatever you want.

#include <OneWire.h>
#include <LiquidCrystal.h>
int DS18S20_Pin = 10; 
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//Temperature chip i/o
OneWire ds(DS18S20_Pin);
///////////////////////////////////
byte relay = 13;
byte setpoint = 20;
/////////////////////////////////// 

void setup() {
Serial.begin(9600);
///////////////////////////////////
pinMode(relay,OUTPUT);
///////////////////////////////////
  lcd.begin(16, 2);
   Print a message to the LCD.
  lcd.print(" ");
}

void loop() {
float temperature = getTemp();
Serial.println(temperature);
//////////////////////////////////
if(temperature >= setpoint)
  digitalWrite(relay,HIGH);
  else if(temperature < setpoint -1)
    digitalWrite(relay,LOW);
//////////////////////////////////    
  lcd.setCursor(0, 1);
    lcd.print("Temp : ");
    lcd.print(temperature);
    lcd.print(" *C");
delay(200); //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
delay(800); /////////////////
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;

}

This Simple Merge Demo may be helpful.

...R

outsider:

Great!It works!Thanks a lot.Now I will study the code and try to understand it as well :slight_smile:

Regards

Jan

Thanks to you guys for reply.Have a nice weekend!