LCD Display and Red Light Blink and Green Light based on Temperature with Arduino

Code:

#include<LiquidCrystal.h>
int icpin1 = 9;
int icpin2 = 8;
int icpin7 = 7;
int green = 10;
int red = 13;
LiquidCrystal lcd(12,11,5,4,3,2);

float tempC;
int tempPin = A0; //Temp sensor plugged into analog pin 0
void setup() {
  // put your setup code here, to run once:
  pinMode(icpin1, OUTPUT);
  pinMode(icpin2, OUTPUT);
  pinMode(icpin7, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(tempPin, INPUT);
  Serial.begin(9600);
  digitalWrite(icpin1, HIGH);

lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Temperature:");
lcd.setCursor(6,1);
lcd.print("C");
}

void loop() {

  tempC = analogRead(tempPin); //Taking the temp pin reading and setting it equal to the tempC variable;
  float value = (tempC * 0.488);
  delay(100);
  Serial.println(value);
  // put your main code here, to run repeatedly:
  //digitalWrite(icpin2,LOW);
  if (value >= 38) {
    digitalWrite(icpin7, HIGH);
    digitalWrite(red, HIGH);
    digitalWrite(green, LOW);
  } else{
    digitalWrite(green, HIGH);
    digitalWrite(red, LOW);
    digitalWrite(icpin7, LOW);
  }
  delay(1000);
  lcd.setCursor(0,1);
  lcd.print(value);

}

Reference: https://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *