我有 arduino uno r3、温度传感器 lm335z 和 2 个 LED。我在互联网上找到了这段代码
float celsius = 0, kelvin=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
kelvin = analogRead(0) * 0.004882812 * 100;
celsius = kelvin - 273.15;
Serial.print("Celsius: ");
Serial.println(celsius);
//Serial.print("Kelvin: ");
//Serial.println(kelvin);
Serial.println();
delay(10000);
}
并且适用于此架构
我用这段代码添加了两个led:
float celsius = 0, kelvin=0;
int led_green = 13;
int led_red = 12;
void setup()
{
Serial.begin(9600);
pinMode(led_green, OUTPUT);
pinMode(led_red, OUTPUT);
}
void loop()
{
kelvin = analogRead(0) * 0.004882812 * 100;
celsius = kelvin - 273.15;
Serial.print("Celsius: ");
Serial.println(celsius);
//Serial.print("Kelvin: ");
//Serial.println(kelvin);
Serial.println();
if (celsius <= 25.00)
{
digitalWrite(led_green, HIGH);
digitalWrite(led_red, LOW);
}
else
{
digitalWrite(led_green, LOW);
digitalWrite(led_red, HIGH);
}
delay(10000);
}
这个架构:
温度比正常温度高 1,2 或 3 度,我想念什么?