我正在使用带有土壤湿度传感器的液晶显示器,似乎使用以下内容会在第一行返回一组奇怪的字符。
LCD.print("Soil Moisture"); //Print Message on First Row
虽然使用以下内容,但效果很好
LCD.print("Water level"); //Print Message on First Row
还值得注意的是,它正确打印到 SerialMonitor
作为学习 Arduino 的新手,这对我来说感觉像是一个错误,但我不能确定。
整个代码如下:
// This sketch will use the soil moisture sensor and display the result on the LCD
#include <LiquidCrystal.h>
// include the LCD library
LiquidCrystal LCD(10, 9, 7, 6, 5, 4);
// Set pins as 10,9,7,6,5,4. It might be different for your LCD, check the producer catalog
int potPin = A0; //input pin
int soil = 0;
int percent = 0;
void setup() {
Serial.begin(9600);
LCD.begin(16,2); //Tell Arduino to start your 16 column 2 row LCD
LCD.setCursor(0,0); //Set LCD cursor to upper left corner, column 0, row 0
LCD.print("Soil Moisture"); //Print Message on First Row
delay(1000);
}
void loop() {
// map the values
int soil = analogRead(potPin) ;
soil = constrain(soil, 600, 1023);
soil = map(soil, 600, 1023, 0, 100);
LCD.setCursor(0,1);
//display final numbers
LCD.print(soil);
//print the percent symbol at the end
LCD.print("%");
//wait 0.1 seconds
delay(75);
//wipe the extra characters
LCD.print(" ");
Serial.print("Water level:");
Serial.print(soil);
Serial.println("%");
delay(1000);
}
可能电线已断开。尝试看看是否有任何东西断开连接。如果是这样,请将其重新插入并按下微控制器上的重置按钮。