Skip to content

Instantly share code, notes, and snippets.

@VincentK16
Last active December 19, 2015 21:19
Show Gist options
  • Save VincentK16/6019752 to your computer and use it in GitHub Desktop.
Save VincentK16/6019752 to your computer and use it in GitHub Desktop.
This is a very simple coding to make an temperature-controlled automatic fan. It will display the temperature at the 16 X 2 LCD screen. When the temperature is more than 35 degree celcius, it will trigger the relay and get the DC fan to ON.
#include <LiquidCrystal.h>
int reading = 0;
int sensorPin = A0;
int relay =7;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
pinMode(relay,OUTPUT);
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
reading = analogRead(sensorPin);
int celsius = reading/2;
lcd.setCursor(0, 0);
lcd.print("Temperature: ");
// print the number of seconds since reset:
lcd.setCursor(0,1);
lcd.print(celsius, DEC);
lcd.print((char)223);
lcd.print("C");
if (celcius >35)
{
digitalWrite(7,HIGH);
}
else
{digitalWrite(7,LOW);
}
delay(500);
lcd.clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment