If I add LCD screen I2C 20x4 to my Arduino when I turn on water pump get stuck

I want to send data from sensor DHT11 to my LCD screen but when I add LCD to my Arduino y I hit button to turn on relay + water pump my screen lcd get turn off and I don't understand it and sometimes the water pump get stuck and I don't can turn off. If I remove LCD screen from my Arduino if I hit push button turn on relay + water pump and work correctly. I use a power supply 12 V which I reduced it to 5V through the LM7805 regulator voltage. What is the problem

// Include DHT Library
#include <DHT.h>
#include <DHT_U.h>

// Including Libraries for I2C LCD

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Sensor definitions

#define DHTPIN 5 //DHT data pin connected to Arduino pin 5
#define DHTTYPE DHT11 // DHT 11

// Actuators: Buttons and LEDS

#define PUMP_ON 11 //push-button
#define PUMP_PIN 13
#define PUMP 7 //water pump
// Variables to be used by Sensor
int tempDHT; 
int humDHT;

// Variables to be used by Actuators
boolean pumpStatus = 0;
boolean LastStatus = LOW;
boolean InitStatus = LOW;

// Variables to be used with timers
long sampleTimingSeconds = 0; // ==> Define Sample time in seconds to read sensores
long startTiming = 0;
long elapsedTime = 0;
const int timeDebounce = 10;
int cont=0;

// Initialize the DHT sensor

DHT dht(DHTPIN, DHTTYPE);

// Initialize LCD

LiquidCrystal_I2C lcd(0x3F, 20, 4);

int cuenta = 0;
int statusButton;
int statusButtonLast;



void setup()
{
  pinMode(PUMP_PIN, OUTPUT);
  pinMode(PUMP_ON, INPUT_PULLUP); //Button
  pinMode(PUMP, OUTPUT);
  Serial.begin(9600);
  Serial.println("ArduFarmBot Local Station Test");
  dht.begin();
  lcd.begin();
  readSensors(); //innitial reading
  startTiming = millis(); // starting the "program clock"
}

void loop()
{

  //Start timer for measurements
  elapsedTime = millis() - startTiming;

  
  readLocalCmd(); //Read local button status
  showDataLCD();
  if(elapsedTime > (sampleTimingSeconds * 1000))
  {
    readSensors();
    printData();
    startTiming = millis();
  }
}

/***************************************************
* Read data from Sensors
****************************************************/
void readSensors()
{
  tempDHT = dht.readTemperature();   //Read temperature and humidity values from DHT sensor:
  humDHT = dht.readHumidity();
}


 /****************************************************************
* Read local commands (Pump and Lamp buttons are normally "HIGH"):
****************************************************************/

void readLocalCmd()
{
  InitStatus = debounce(LastStatus); //leemos el estado del 
  if(LastStatus == LOW && InitStatus == HIGH)
  {
    pumpStatus = !pumpStatus;
    cont++;
    
  }
  LastStatus = InitStatus;
  showDataLCD();
  aplyCmd();
  
}

/***************************************************
* Receive Commands and act on actuators
****************************************************/

void aplyCmd()
{
  if(pumpStatus == 1)
  {
    digitalWrite(PUMP_PIN, HIGH);
    digitalWrite(PUMP, LOW);
  }
  if(pumpStatus == 0)
  {
    digitalWrite(PUMP_PIN, LOW);
    digitalWrite(PUMP,HIGH);
  }
}

/***************************************************
* Showing capured data at Serial Monitor
****************************************************/
void printData(void)
{
  Serial.print(" Temp DHT ==> ");
  Serial.print(tempDHT);
  Serial.print("oC Hum DHT ==> ");
  Serial.print(humDHT);
}

/***************************************************
* Showing capured data at LCD
****************************************************/
void showDataLCD(void)
{
  lcd.setCursor(0,0);
  lcd.print("ArduFarmBot Ctrl St.");
  lcd.setCursor (0,1);
  lcd.print("Temp: ");
  lcd.print(tempDHT);
  lcd.print("oC  Hum: ");
  lcd.print(humDHT);
  lcd.print("%  ");
  lcd.setCursor (0,2);
  lcd.print("Pump: ");
  lcd.print(pumpStatus);
  lcd.setCursor(0,0);
  
}


/***************************************************
* Debouncing a key
****************************************************/
boolean debounce(boolean eLast)
{
   boolean eInit = digitalRead(PUMP_ON);
  if (eLast != eInit)
  {
    delay(5);
    eInit = digitalRead(PUMP_ON);
  }
  return eInit;
}

Here this video issue

Video

Code in github => github code

Mini water pump which I use

t's a mini water pump which I use.

This is
item minibomba

What kind of surge / spike suppression do you have on the pump motor wires?
Can you post a wiring diagram?
HowToPost

Yes I upload the diagram. It's a mini water pump which I use.

This is
http://www.ebay.es/itm/Mini-Bomba-Sumergible-de-Agua-DC-3V-120L-H-Arduino-Motor-Water-Pump-M0040/172813706545?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2060353.m2749.l2649

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

As I asked in reply #1, if you don't have a spike suppressor across the motor, try this and see if it helps, install the diode with cathode (end with stripe) to the + (relay) wire of the motor. Also, a 100nF ceramic capacitor in parallel might help with higher frequency noise.
suppressor2.png
Does your power supply have enough current for the Arduino, LCD and 75 mA relay coil?

1 Like

yes I use a power supply. This is

Captura de pantalla 2017-09-11 00.08.58.png

Captura de pantalla 2017-09-11 00.08.58.png

Ardufarmbot.fzz.zip (355 KB)

Thank you Edgemore! work correctly

Hi,
Do you have a DMM?

Measure the voltage from your power supply and see what it does when you get the fault.
Also do the same for the 5V pin on the UNO.

The fact that the display back light goes out and the relay buzzes, sounds like a power supply failure.

Tom.... :slight_smile:

Also posted at https://stackoverflow.com/q/46423017

Hi,
Please post your final schematic, just posting a fritzy file is useless, it assume everybody else has the fritzy program and it is loaded with the components you have used.
As an example, I downloaded your zip from https://stackoverflow.com/q/46423017 and extracted it and got this.

If you want to use fritzty, PLEASE use its attempt at a schematic CAD, not this picture method.
To properly post this "picture" you should have "EXPORTED" the picture.

Tom.... :slight_smile: :o

He may still be working on it. :slight_smile: