0

enter image description hereI am making a water pump system for plants and I am running into trouble with displaying my Temperature and Humidity values. I am using a 20x4 LCD, Arduino board uno, Capacitive soil moisture sensor, 5v DC water pump, DHT22, and a single relay. When the motor is on, the display first shows the values as expected. Then, all of a sudden random characters fill and move across my screen. When I don't connect my motor to the Arduino, the values show up on the LCD as expected. Please do leave comments so that I am able to improve my code. Thanks.

//Libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"

//Pins Used
#define DHTpin 2
#define DHTtype DHT22

//Initialization
DHT dht(DHTpin, DHTtype);
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);





int sensor_pin = 0; // Soil Sensor input at Analog PIN A0
int pinValue;
int output_value ;
void setup() {
  // put your setup code here, to run once:
  pinMode(3,OUTPUT);
     Serial.begin(9600);
   Serial.println("Reading From the Sensor ...");

  lcd.begin(20, 4);
  delay(4000);
}


  // put your main code here, to run repeatedly:

  void loop() {
  lcd.clear();
  dht.begin();

  float humid = dht.readHumidity();
  float temp = dht.readTemperature();

  lcd.setCursor(0, 2);
  lcd.print("Temperature: ");
  lcd.print(temp);
  lcd.print("C");

  lcd.setCursor(0, 3);
  lcd.print("Humidity: ");
  lcd.print(humid);
  lcd.print("%");



 pinValue = analogRead(sensor_pin);
 output_value = map(pinValue,700, 300,0,100);

  Serial.print("Mositure : ");
  Serial.print(output_value);
  Serial.println("%");
   if(output_value> 0 && output_value <= 51){
    digitalWrite(3,LOW);
    lcd.setCursor(0,0);
    lcd.print("ON");
    lcd.setCursor(0,1);
    lcd.print("MOISTURE VAL: ");
    lcd.print(output_value);
    lcd.print("%");



    delay(1000);

     }else if(output_value > 51 && output_value <= 100){
      digitalWrite(3,HIGH);
      lcd.setCursor(0,0);
      lcd.print("OFF");
      lcd.setCursor(0,1);
      lcd.print("MOISTURE VAL: ");
      lcd.print(output_value);
      lcd.print("%");



      delay(1000);

     }
     delay(1000);
}

EDIT (1)

Here are some pics of the circuitry and the LCD message. If you find these pictures to not be helpful, I can sketch this circuit. Thank You.

enter image description hereenter image description here

  • 1
    Try to display some static string (not DHT/moisture sensor value) on the LCD and switch on the motor. If the problem still occurs, it is probably caused by EMI from the water pump motor. – JSC May 24 at 20:55
  • Please add a wiring diagram into your question, showing how the components are connected to each other. A photograph of the layout would help, too. – JRobert May 24 at 21:10
  • How a project is wired can make a difference. Two people could wire up the same schematic and they could have very different results. Schematics will show if lines are connected but do not show how well the overall implementation is executed. Motors can be electrically very noisy. Proper routing of the currents involved is a must for stable operation. It is difficult to go into all the factors that must be considered. In your case it would help if you could post pictures of the way you wired your project. – Rudy May 25 at 1:37
  • I have added pictures to my question now – Varun Poondi May 26 at 18:07
  • @ JSC, I printed some static strings, and I am still getting these random characters. How do I eliminate the EMI from my system? – Varun Poondi May 26 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.