-1

I'm working on a project to create an automatic watering system using an Arduino Uno R3 board, a 16x2 LCD display, a water pump, and a soil moisture sensor. However, I've hit a roadblock and could really use some assistance.

The issue I'm facing is that my LCD display isn't lighting up at all. I've double-checked all the connections, made sure the code is correct.

Here's a rundown of my setup:

  1. Arduino Uno R3 board
  2. 16x2 LCD display
  3. Water pump
  4. Soil moisture sensor

I connected:

  • the LCD pin VCC and GND to the breadboard + and -
  • the SCA pin of the LCD to the A4 analog pin of the Arduino
  • the SCL pin of the LCD to the A5 analog pin of the Arduino

I've followed tutorials and guides closely, but I can't seem to figure out what's causing the problem.

If anyone has experienced a similar issue or has any suggestions on how to troubleshoot this problem, I would greatly appreciate your help.

Here's the code I used:

#Include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
 
void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  lcd.clear();
  pinMode(2, OUTPUT);
  digitalWrite(2, HIGH);
  delay(1000);
  lcd.setCursor(0, 0);
  lcd.print("IRRIGATION");
  lcd.setCursor(0, 1);
  lcd.print("SYSTEM IS ON ");
  lcd.print("");
  delay(3000);
  lcd.clear();
}
 
void loop() {
  int value = analogRead(A0);
  Serial.println(value);
  if (value > 950) {
    digitalWrite(2, LOW);
    lcd.setCursor(0, 0);
    lcd.print("Water Pump is ON ");
  } else {
    digitalWrite(2, HIGH);
    lcd.setCursor(0, 0);
    lcd.print("Water Pump is OFF");
  }
 
  if (value < 300) {
    lcd.setCursor(0, 1);
    lcd.print("Moisture : HIGH");
  } else if (value > 300 && value < 950) {
    lcd.setCursor(0, 1);
    lcd.print("Moisture : MID ");
  } else if (value > 950) {
    lcd.setCursor(0, 1);
    lcd.print("Moisture : LOW ");
  }
}
3
  • Describing electrical connections isn't particularly helpful. A schematic diagram (or at worst a Fritzing diagram) would be an improvement. Also which LCD display? What is the pinout? There are many different versions out there. The water pump and the soil sensor seem to be irrelevant to your problem, and just confuse the issue. You should remove anything that isn't directly related to the display issue. Address one module at a time. Commented Apr 13 at 9:26
  • 1
    run the I2CScanner sketch to see if and on what address it detects the LCD
    – Juraj
    Commented Apr 13 at 10:40
  • the LCD pin VCC and GND to the breadboard + and - ... is the breadboard bus connected to the + and -? ... some breadboard buses have a break in the middle, usually indicated by a break in the red line
    – jsotola
    Commented Apr 18 at 19:29

1 Answer 1

1

The LCD address might not be 0x27.

Verify the address of your LCD, by checking the manufacturer of the PCF8574 (on the back of the LCD panel). From Interface an I2C LCD with Arduino:

  • If your LCD has a PCF8574 chip from Texas Instruments, its I2C address is 0x27;
  • If it has a PCF8574 chip from NXP Semiconductors, its I2C address is 0x3F.

Or from 6v6gt's comment:

It is actually the "A" suffix (or lack of) on the chip identifier which distinguishes the I2C address range supported by the chip. NXP PCF8574 and PCF8574A see 7.1 : Remote 8-bit I/O expander for I2C-bus with interrupt TI PCF8574 see 8.4 : PCF8574 Remote 8-Bit I/O Expander for I2C Bus TI PCF8574A see ch. 7 : PCF8574A Remote 8-Bit I/O Expander for I2C Bus. Within that range, the user can of course also alter 3 solder jumpers to fine tune the address.

To quote the relevant sections:

From Remote 8-bit I/O expander for I2C-bus with interrupt

7.1 Device address

Following a START condition, the bus master must send the address of the slave it is accessing and the operation it wants to perform (read or write). The address format of the PCF8574/74A is shown in Figure 6. Slave address pins A2, A1 and A0 are held HIGH or LOW to choose one of eight slave addresses. To conserve power, no internal pull-up resistors are incorporated on A2, A1 or A0, so they must be externally held HIGH or LOW. The address pins (A2, A1, A0) can connect to VDD or VSS directly or through resistors.

enter image description here

The last bit of the first byte defines the operation to be performed. When set to logic 1 a read is selected, while a logic 0 selects a write operation (write operation is shown in Figure 6).

From PCF8574 Remote 8-Bit I/O Expander for I2C Bus, section 8.4, Device Functional Modes, shows the address and timing diagrams for the write and read modes.

From PCF8574A Remote 8-Bit I/O Expander for I2C Bus, section 7, gives the Parameter Measurement Information, with schematics and timing diagrams.


Alternatively, as per Juraj's comment, run I2CScanner:

 // --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
// 
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ ) 
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4) 
    {
      Serial.print("Unknown error at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

from i2c_scanner

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.