码迷,mamicode.com
首页 > 其他好文 > 详细

LCD温度显示报警器

时间:2020-12-14 12:57:39      阅读:3      评论:0      收藏:0      [点我收藏+]

标签:地址   variable   initial   and   png   other   rgb   var   lis   

项目地址:https://www.tinkercad.com/things/9Yv09OZnrXy-temperature-sensor-with-display

技术图片

 

 

//CREATED BY GIOVANNI, LUCAS B, LUCAS F & THIAGO.
//WHEN THE TEMPERATURE IS HIGHER THAN 35oC IT PLAYS ANOTHER SOUND FREQUENCY.

//Include the library code.
#include <LiquidCrystal.h>
//Initialize the library with the numbers of the interface pins.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//This is the Arduino Pin that will read the sensor output.
int sensePin = A0;
//The variable we will use to store the sensor input.
int sensorInput;
//The variable we will use to store temperature in degrees.
double temp;

void setup()
{
  //Pin of the led.
  pinMode(13, OUTPUT);
  
  //Initialize the LCD‘s number of columns and rows.
  lcd.begin(16, 2);
  
  //Start the Serial Port at 9600 baud (default).
  Serial.begin(9600);
}

void loop()
{  
  //Set the cursor to column 0, line 0
  lcd.setCursor(0, 0);
  
  //Read the analog sensor and store it.
  sensorInput = analogRead(A0);
  //Find percentage of input reading.
  temp = (double)sensorInput / 1024;
  //Multiply by 5V to get voltage.
  temp = temp * 5;
  //Subtract the offset.
  temp = temp - 0.5;
  //Convert to degrees.
  temp = temp * 100;
  
  if (temp > 35)
  {
    //INPUT - FREQUENCY - TIME THAT LASTS
    tone(8, 800, 300);
    delay(250);
    
      digitalWrite(13, HIGH);
      delay(500); // Wait for 500 millisecond(s)
      digitalWrite(13, LOW);
      delay(500); // Wait for 500 millisecond(s)
  }
  
  else if (temp > 25)
  {
    //INPUT - FREQUENCY - TIME THAT LASTS
    tone(8, 500, 300);
    delay(500);

    digitalWrite(13, HIGH);
    delay(500); // Wait for 500 millisecond(s)
    digitalWrite(13, LOW);
    delay(500); // Wait for 500 millisecond(s)
  }  

  lcd.print("Temperature: ");
  
  //Set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  lcd.print(temp);
  
  lcd.print(" Celsius");

}

 

LCD温度显示报警器

标签:地址   variable   initial   and   png   other   rgb   var   lis   

原文地址:https://www.cnblogs.com/meetrice/p/14100591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!