Skip to content

Instantly share code, notes, and snippets.

@stq
Created April 16, 2020 20:42
Show Gist options
  • Save stq/d2a6f697719219f6411ec5e34effb127 to your computer and use it in GitHub Desktop.
Save stq/d2a6f697719219f6411ec5e34effb127 to your computer and use it in GitHub Desktop.
Arduino Nano termostat
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
float temp;
int needtemp;
float ratio;
float shift;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
Serial.begin(9600);
}
char line1[17];
char line2[17];
void loop() {
ratio = (analogRead(A5)-512.0)/100.0;
shift = (analogRead(A6)-512.0)/80.0;
temp = shift + analogRead(A3) * (5.0/10.24) * (1.0 + ratio/100.0);
needtemp = analogRead(A4) / 6.80;
sprintf (line1, "%s:%03d.%1dC>%03dC", (temp >= needtemp ? "Cool" : "Heat") , (int)temp, abs((int)(temp*10)%10), needtemp);
sprintf (line2, "Corr:%c%d.%1d%%C%c%1d.%1dC", (ratio < 0 ? '-' : '+'),abs((int)ratio), abs((int)(ratio*10)%10), (shift < 0 ? '-' : '+'), abs((int)shift), abs((int)(shift*10)%10));
//sprintf (line2, "Corr:%d.%1d%%C%1d.%1dC", (int)ratio, abs((int)(ratio*10)%10), (int)shift, abs((int)(shift*10)%10));
if( temp >= needtemp ) {
analogWrite(A2, 0);
} else {
analogWrite(A2, 1023);
}
Serial.println("Analog data(Temp, TempGoal, CorrRatio, CorrShift)");
Serial.println(analogRead(A3));
Serial.println(analogRead(A4));
Serial.println(analogRead(A5));
Serial.println(analogRead(A6));
lcd.setCursor(0, 0);
lcd.print(line1);
lcd.setCursor(0, 1);
lcd.print(line2);
delay(1000);
}
@stq
Copy link
Author

stq commented Apr 16, 2020

Termostat for 3d printer enclosure or incubator or growbox.
Parts:
Arduino Nano
3 Adj. Resistors 0-50k or 0-10k or anything between (sets LCD contrast, Temp Sensor correction ration and shift)
1 Potentiometer (sets goal temperature)
Arduino Relay
Arduino-ready LM35 temperature sensor
4 100n capacitors (to remove resistors dribble)
220 ohm resistor for display light
16x2 LCD display
Any heater (i'm using 300 w 220 v incubator heater with integrated fan).
5 volt power source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment