我正在将LCD显示器与土壤湿度传感器一起使用,似乎使用以下命令在第一行返回了一组奇怪的字符。
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);
}