admin管理员组文章数量:1431172
I'm making an automatic watering system with an LCD that shows moisture level from 0 to 100. Whenever the pump turns on the output on the serial monitor turns into ��� and other random characters. This also happens on the LCD. Any advice on how I can fix this?
I've already tried adding delay in the baud and ensuring that its at 9600.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int soilAnalog = A0;
int soilVal;
int outputVal;
const int pump = 2;
void setup() {
Serial.begin(9600); // Ensure Serial Monitor is set to 9600 baud
delay(500);
lcd.init();
lcd.backlight();
pinMode(pump, OUTPUT);
}
void loop() {
soilVal = analogRead(soilAnalog);
Serial.print("Analog Output: ");
Serial.println(soilVal);
lcd.setCursor(0, 0);
lcd.print("Moisture Level:");
// Map soilVal to a percentage (0-100)
outputVal = map(soilVal, 0, 1023, 100, 0);
lcd.setCursor(0, 1);
lcd.print(outputVal);
lcd.print(" ");
if (soilVal >= 700) {
Serial.println("Status: Dry");
digitalWrite(pump, HIGH);
}
else if (soilVal >= 400 && soilVal < 700) {
Serial.println("Status: Moist");
}
else {
Serial.println("Status: Wet");
digitalWrite(pump, LOW);
}
Serial.println();
delay(1500);
}
本文标签: arduinoCharacters ��� appears when load turns onStack Overflow
版权声明:本文标题:arduino - Characters ��� appears when load turns on - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745571566a2664078.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论