LCD I2C doesn’t display words

Hi all, I’m new to addition. Recently I’ve been trying to create something that’s like: a button controls the LED, the fsr controls the lightness of LED, and if the force is more than 60, then LCD display shows “close”. If the force is less than 60, then LCD display shows “far”. I had my code and tested on tinkercad and everything works well. However, when I built the real circuit on breadboard, the LCD just didn’t show anything. It did light up, but without a word. The LED, button and fsr work well. Could you please help me to see what’s the problem?

This is my code:

//
#include <Adafruit_LiquidCrystal.h>

Adafruit_LiquidCrystal lcd_1(0);

void setup()
{
  lcd_1.begin(16, 2);
  pinMode(A0, INPUT);
  Serial.begin(9600);
  pinMode(3, OUTPUT);
}

void loop()
{
  Serial.println(analogRead(A0));
  analogWrite(3, map(analogRead(A0), 0, 1023, 0, 255));
  if (analogRead(A0) < 230) {
    lcd_1.setCursor(0, 0);
    lcd_1.print("you are far away");
  } else {
    lcd_1.setCursor(0, 0);
    lcd_1.print("you are close   ");
  }
  delay(10); // Delay a little bit to improve simulation performance
}

This is what I built on tinkercad:

This is what I built on breadboard:

The LCD is just like this all the time:

So what’s the problem?

your LCD contrast might be too high there is a potentiometer at the back of the LCD that you could adjust

You forgot the current limiting resistor for your LED. you should add a 220Ω/330Ω resistor in series with the LED to ensure you don't draw too much current out of your pin.

(I've not looked at the code)


EDIT

I had a quick look and the code does

this would mean your LCD has a 0x20 I2C address which might not be the case. Typical addresses for the LCD1602 with a I2C backpack are 0x27 or 0x3F ➜ if the contrast is not the issue, try with

Adafruit_LiquidCrystal lcd_1(0x27);

or

Adafruit_LiquidCrystal lcd_1(0x3F);

Ohhhh thank you so much! I added a resistor, adjusted the potentiometer, and changed the code to Adafruit_LiquidCrystal lcd_1(0x27); but now it is like this:

you said

try 0x3F

Tinkercad seems to have the "Adafruit Liquidcrystal" library for a I2C LCD display.
It is this library: https://github.com/adafruit/Adafruit_LiquidCrystal

It works in Tinkercad:

I suppose that it also works in real life with Adafruit I2C LCD displays.
However, when I try it in the Wokwi simulation, then it no longer works. The Adafruit library does not seem to work with the common displays.

You need the (old and no longer maintained) "LiquidCrystal I2C" library or the (new and well maintained) "hd44780" library. The "hd44780" library is written to be compatible with as many displays as possible.
You might even have to move away from Tinkercad and start using Wokwi.

My test in Wokwi simulation for the Adafruit library: Testing the Adafruit LiquidCrystal library. - Wokwi ESP32, STM32, Arduino Simulator

Will try wokiwi! Look fun! I installed hd44780 but nothing changed

Did the display come with the I2C board pre-installed, or did you solder it on yourself?

It’s pre-installed

Try running the example sketch File > Examples > hd44780 > ioClass > hd44780I2Cexp > I2CexpDiag


I tested it and I don’t think there’s any problem with it. I’m so confused :confused:

please, please never ever again post pictures of text... Not only they are not readable nor usable directly for copy&paste but they use up lots of storage and internet bandwidth which contributes to polluting the planet.

➜ do your part and do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

Tried 0x3F, and it’s not even showing anything

try this code

// LCD MANAGEMENT WITH https://github.com/duinoWitchery/hd44780/tree/master
#include <Wire.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
hd44780_I2Cexp lcd;

const int LCD_COLS = 16;
const int LCD_ROWS = 2;


void setup()
{
  pinMode(A0, INPUT);
  pinMode(3, OUTPUT);
  Serial.begin(9600);

  int result = lcd.begin(LCD_COLS, LCD_ROWS);
  if (result) {
    Serial.print("LCD initialization failed: ");
    Serial.println(result);
    hd44780::fatalError(result);
  }

}

void loop()
{
  int a0Value = analogRead(A0);
  Serial.println(a0Value);
  analogWrite(3, map(a0Value, 0, 1023, 0, 255));
  
  if (a0Value < 230) {
    lcd.setCursor(0, 0);
    lcd.print("you are far away");
  } else {
    lcd.setCursor(0, 0);
    lcd.print("you are close   ");
  }
  delay(10); // Delay a little bit to improve simulation performance
}

the major mistake that you did is you did not declare lcd dimension (0*27 , 16,2) something like this

OMG it’s working!! Thank you so much!! You really save my life!!!

that's basically your code with the other library (and stored the analogRead into a variable because it does not make sense to read it all over the place in the loop)
you could improve it by not rewriting constantly the same message if it has not changed

Ohhhh! I think this is the problem. Thank you so much for your help!

Can you explain which library you use now ? Is the Adafruit library working after all ?

Looks good to me. Just need to adjust the contrast pot.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.