How to find right code?

I'm going to use TMP36 for meassuring temperature with my Arduino Uno, and i also have relay like the one attached as image.

I want the relay to turn on my AC heater when temperature decreases under 15 degree celcius.

Can someone help med how find that code?

Here's OP's pic:

You probably won't "find" the right code; here's how to read the temperature sensor. Then just do an if / else based on the temperature and digitalWrite the relay control pin.

Thanks.

Bu where do i plase the "if/else digitalwrite" code inside TMP36 code?

Sorry... i'm really noob at this...

add to the tmp36 example code with an if statement. Post your code so it is easier to help

Okay. Can do that later to day.

I just meant where in TMP36 code i should place the code for if statement and the relay. Is there a specific order?

Bjerknez:
Bu where do i plase the "if/else digitalwrite" code inside TMP36 code?

Have you had a dive into the linked code to try to follow it? (It's quite well commented...)

Where do you think it should go?

Bjerknez:
Is there a specific order?

(Hint: You need to have got to the stage where you know what the Celsius temperature is.)

(We were all noobs once: how long you stay a noob depends on how much you try to do it yourself :wink: )

What do you guys think about this code?

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 5

int sensorPin=1
int relayPin=9

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float Celcius=0;
float Fahrenheit=0;
void setup(void)
{

Serial.begin(9600);
sensors.begin();
pinMode(9, OUTPUT)
pinMode(1, INPUT)
}

void loop(void)
{
sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);
Serial.print(" C ");
Serial.print(Celcius);
Serial.print(" F ");
Serial.println(Fahrenheit);
delay(1000);

if (sensorPin > 18) {
digitalWrite(relayPin, LOW)
}

else (sensorPin < 14) {
digitalWrite(relayPin, HIGH)
}

I think you failed to read the instructions on how to post code and you are missing a closing } and the indentation is wrong but other than that it looks good.

if (sensorPin > 18) { You gave "sensorPin" the value 1.
How is it ever going to be greater than 18?

Wow!! I can't believe i did that with so little errors. Thanks :slight_smile:

And i'm really sorry i forgot to read the code guidelines.

Bjerknez:
I'm going to use TMP36 for meassuring temperature

But according to the link I gave, that sensor is just a simple analog sensor:

int reading = analogRead(sensorPin);

.... not a:

#include <OneWire.h>
#include <DallasTemperature.h>

... one.

I know. I changed the sensor to tmp36 and after a good our in my basement, i get it to work :slight_smile:

I got an led light up when temperature got to 18 degrees. I now understand how to merge the code with other codes. :slight_smile: