Arduino window comparitor

Scenario:

Heater needs to turn on until boiler reaches maximum temperature, then turns off until a lower temperature is reached, then turns on until maximum, then off until minimum… and so on.

Imagine hysteresis at set upper and lower limits, for the heater to run at.

Arduino connected to thermistor to measure temperature, with SSR connected to heater mains circuit to turn on/off heater.

 

A simple comparitor code for arduino allows us to set the max and min limits of temperature (mapped to values 0-100) (temperature in celcius is not required for this task, tho could be usefull – may add later)

LED provides visual feedback of SSR on (the SSR on could have LED on expensive units)

CIRCUIT DIAGRAM TO COME – as is code formatting in wordpress \o/

CODE:
/*
thermistor Input
Measures temperature of thermistor and turns on heater SSR when temperature is in window
turning on and off a light emitting diode(LED) and SSR to maintain temperature.
The SSR heater will be turned on if below heaterHighVal and off when passes window to heaterLowVal.
These values are analogue values obtained by analogRead().

The circuit:
* Thermistor attached to analog input 0
* heaterPin connected to input of SSR – SSR through Live to heater
* LED anode (long leg) attached to digital output 13
* LED cathode (short leg) attached to ground

* Note: because most Arduinos have a built-in LED attached
to pin 13 on the board, the LED is optional.

Created by Nathaniel Poate
30 May 2013
*/

int sensorPin = A0;        // select the input pin for the thermistor
int ledPin = 13;           // select the pin for the LED
int heaterPin = 10;        // select the pin for the heater SSR
int heaterLowVal = 20;    // select the value for low temperature cutoff window
int heaterHighVal = 50;   // select the value for high temperature cutoff window
int sensorValue = 0;       // variable to store the value coming from the thermistor

void setup() {
// declare the ledPin and heaterPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
pinMode(heaterPin, OUTPUT);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
int temp0to100 = map(sensorValue, 0, 1056, 0, 100);

if (temp0to100 >= heaterLowVal && temp0to100 <= heaterHighVal)
{
heaterOn;// turn Turn on heater
}
else if (temp0to100 <= heaterLowVal && temp0to100 <=heaterHighVal)
{
heaterOn;
// turn Turn on heater
}
else if (temp0to100 > heaterHighVal)
{
while (temp0to100 >= heaterLowVal)
{
heaterOff;
// turn Turn off heater
}
}
}

void heaterOn() {
digitalWrite(heaterPin, HIGH);
digitalWrite(ledPin, HIGH);
// turn on heater and LED
}

void heaterOff() {
digitalWrite(heaterPin, LOW);
digitalWrite(ledPin, LOW);
// turn on heater and LED
}