Please help! Circuit with LCD screen and piezo

Hi everyone!
I'm a pretty new user of Arduino and I'm working on a clock and alarm project.
I'm using the Arduino UNO starter kit and the 2x16 LCD screen found in there.

My problem is that whenever the piezo starts ringing, the LCD display start showing white blocks and/or random characters.
Executing the code without calling the function alarmBeep() result in the LCD screen functioning perfectly, therefore I think that the problem is not in the electronics themselves. The code should also work fine, so I'm quite lost...

My conclusion is that in some way the signal sent to the piezo interferes with those sent to the LCD but it's not clear to me why this happens...

Here is the code I'm using.

#include <LiquidCrystal.h>
LiquidCrystal lcd(A5, A4, A3, A2, A1, A0);

#define BUZZER 9
int i;

void setup() {
  
  pinMode(BUZZER, OUTPUT);
  // Setup LCD
  lcd.begin(16, 2);
  lcd.noAutoscroll();
  lcd.display();
  
}
void loop() {
  checkprint();
  delay(150);
}

void checkprint(){
  i = 0;
  int ItoPrint[] = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8};
  char CtoPrint[] = {"abcdefghilmnopqr"};
  lcd.setCursor(0, 0);
  while(i<16){
    lcd.print(ItoPrint[i]);
    delay(200);
    i++;
  }

  alarmBeep();

  i=0;
  lcd.setCursor(0, 1);
  while(i<16){
    lcd.print(CtoPrint[i]);
    delay(200);
    i++;
  }
  
}

void alarmBeep() {
  tone(BUZZER, 2000);
  delay(200);
  noTone(BUZZER);
}

Here is the electronics diagram.

As I'm a new user I unfortunately cannot add more pictures.

This are the characters displayed after the activation of the piezo.

If the piezo is not activated, the screen works fine, displaying correctly the message.

Long wires are very often a problem: they pick up electromagnetic interference. Route signal wires away from outputs like buzzers.

It might help to add an 0.1 uF (100 nF) decoupling capacitor at the LCD power and GND connections.

Thanks for the prompt answer jremington!
I've tried your fix today, rerouting the piezo to pin A5 and the LCD to pins 10-13. I also used cables as short as possible but unfortunately the random characters still appear.
As I've already wasted a lot of time on this project and I'm pretty frustrated about it not working I think I'm just going to switch to another, thanks again for your answer!

100 µF or larger capacitor directly between pins 1 and 2 of the LCD.

Hi,
You have provided good information, drawings etc. But - I cannot see exactly - but can you check the wiring between pin 9 and the piezo. It looks like a wiring snag (but I cannot see too clearly, sorry)
If not, then check the GND wiring.

This topic was automatically closed after 120 days. New replies are no longer allowed.