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