Step 5: Setting Threshold Fan/Heater Values
In order to read out what the potentiometer tells the Arduino, initialize the variables and code the following...
fanDigit = analogRead(fanAnalog)/4;
heaterDigit = analogRead(heaterAnalog)/4;
This will give the Arduino a number from 0-255 depending on where the potentiometer is twisted.
This can be used to provide a threshold, with an example of code for the application of a threshold below.
fanThreshold = 20 + fanDigit*10/255;
heaterThreshold = 10 + heaterDigit*10/255;
<more code>
//inside void loop()
if(temperature>fanThreshold) {
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
if(temperature<heaterThreshold) {
digitalWrite(4, HIGH);
}
else {
digitalWrite(4, LOW);
}
Remove these ads by
Signing Up

























Not Nice













Visit Our Store »
Go Pro Today »



