#include "LiquidCrystal.h"

const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 
LiquidCrystal lcd(rs, en, d4, d5, d6, d7)

void setup() {
  lcd.begin(16, 2);
  pinMode(22, INPUT_PULLUP); // Reed switch - Row1
  pinMode(24, INPUT_PULLUP); // Reed switch - Row2
  pinMode(26, INPUT_PULLUP); // Reed switch - Row3
  pinMode(28, INPUT_PULLUP); // Reed switch - Row4
  pinMode(32, OUTPUT);
  digitalWrite(32, HIGH);
  lcd.setCursor(0, 0);

When I run the above code I get weird characters in my LCD. I removed all the connections to the pins` defined in pinMode and left only the lcd connections but kept the pinMode and digitalWrite statements in the code, but am still getting weird characters. But when I remove the pinMode and digitalWrite statements from my code the lcd works fine. Can anyone help me out.

Another weird thing happened, I removed all the pinMode and digitalWrite statements do my setup() had only Serial.begin() and lcd.begin() and I only had the lcd connections. Now I put this code to print into an function called lcdprintMove() and there were other functions too which were performing other tasks when I ran it as such I got weird characters in the LCD but when I removed all of the other functions,the lcd printed fine. From this I was able to conclude that this problem can't be because of the supply but has to be something else. But I still can't figure it out.

Problem Solved

Today I commented all the digitalWrite statements and uploaded the program and it worked! So, I am going to connect the lcd onto a separate arduino and communicate serially. Someone suggested the solution of putting a cap to ground and buff the power of 5 v pin can you explain this in more detail.

Circuit diagram Note: Rs is connected to pin 7 and E to 6

enter image description here

  • 2
    How is your LCD connected? Please show a schematic.
    – JRobert
    Jun 30, 2018 at 21:43
  • 2
    What is connected to pin 32?
    – Majenko
    Jun 30, 2018 at 22:45
  • all the pins defined in pinMode are connected to reed switches.
    – roaibrain
    Jul 1, 2018 at 11:31
  • What are the reed switches connected to? Try disconnecting them, then run the program both ways again. If it works better this time, one or some of the reed switch circuits' current draw, combined with that of the LCD, may exceed the pin-drivers' capacity and drag down a voltage such that the LCD can't respond properly.
    – JRobert
    Jul 1, 2018 at 12:36
  • 1
    Is the LCD module's +5v supplied directly from the power supply, or off one of the Arduino's +5v pins? If the latter, try powering it directly.
    – JRobert
    Jul 1, 2018 at 23:25

1 Answer 1


The capacitor between 5V and GND effectively acts as a small battery. When a sudden demand in a current relatively large occurs, the system can get that extra small amount from the cap and not experience a voltage drop.

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.