Keep receiving signal without pressing push button [HELP]

Hello!

now im doing some project using lcd and arduino mega.
i want to make sequence, when i press the push button it will display on the lcd.

the problem is the signal from push button 4 and 5 keep receiving signal without pressing them.So the lcd keep displaying the output that should be display only when push button is press.

here is my program and it will great that u guys help me out. i really appreciate that.

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
  
  pinMode(34,OUTPUT);  // LED 1
  pinMode(35,OUTPUT);  // LED 2
  pinMode(27,OUTPUT); // LED 3
  pinMode(40,INPUT);  // Push button 1
  pinMode(41,INPUT);  // Push button 2
  pinMode(42,INPUT);  // Push button 3
  pinMode(22,INPUT);  // Push button 4
  pinMode(23,INPUT);  // Push button 5
  lcd.begin(16, 2);
  lcd.print("SELAMAT DATANG");
} 
void loop(){
  
  if(digitalRead(22)==HIGH); // when push button 4 pressed
  {
  lcd.clear();
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("RM 1.00");
  lcd.setCursor(0,1);
  lcd.print("DITERIMA");
  digitalWrite(34,HIGH); // LED 1
  delay(1500);
  digitalWrite(34,LOW); // LED 1
  delay(3000);
  lcd.clear();
  lcd.print("TERIMA KASIH");
  }  
{
  
  if(digitalRead(23)==LOW);  // when push button 5 pressed
  {
  lcd.clear();
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("RM 5.00");
  lcd.setCursor(0,1);
  lcd.print("DITERIMA");
  digitalWrite(35,HIGH); // LED2
  delay(1500);
  digitalWrite(35,LOW); //LED2
  delay(3000);
  lcd.clear();
  lcd.print("TERIMA KASIH");
  }
{
  
  if(digitalRead(40)==HIGH) // when push button 1 pressed
  digitalWrite(27,HIGH);
   else 
   digitalWrite(27,LOW);
}
{
  if(digitalRead(41)==HIGH) // when push button 2 pressed
  {
  digitalWrite(27,LOW);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("HAD TUKARAN");
  lcd.setCursor(0,1);
  lcd.print("HANYA RM1.00");}
} 
{
  if(digitalRead(42)==HIGH); // // when push button 3 pressed
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("MESIN KEHABISAN");
  lcd.setCursor(0,1);
  lcd.print("DUIT SYILING");
}} }

you should look into switch debouncing

http://www.arduino.cc/en/tutorial/debounce

Show us the circuit please. I'm guessing the switch simply connects the pin to 5V when pressed? You probably don't have a pull-down transistor, which connects the pin to ground the rest of the time, so it's not accidentally high.

This example shows exactly what to do.

Re: Keep receiving signal without pressing push button [HELP]
#1
Today at 11:14 am
you should look into switch debouncing
http://www.arduino.cc/en/tutorial/debounce
Gammon Forum : Electronics : Microprocessors : Switches tutorial

thankyou i will try

Re: Keep receiving signal without pressing push button [HELP]
#2
Today at 11:16 am
Show us the circuit please. I'm guessing the switch simply connects the pin to 5V when pressed? You probably don't have a pull-down transistor, which connects the pin to ground the rest of the time, so it's not accidentally high.
This example shows exactly what to do.

i had connect my lcd like this http://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay

and push button like this http://www.arduino.cc/en/Tutorial/Button

danialsudirman:
and push button like this http://www.arduino.cc/en/Tutorial/Button

If that pull down is correctly connected there should be a low when the button's not pressed. I think maybe the circuit's not connected properly. Show us a schematic of your actual circuit (not the supposed to be), and maybe a photo. If you're using a breadboard maybe you have the rows mixed up or something?

if(digitalRead(23)==LOW);  // when push button 5 pressed  this should be HIGH

siutoejai:

if(digitalRead(23)==LOW);  // when push button 5 pressed  this should be HIGH

i had try but the the pin 23 and 22 always give the high signal without press the push button