Arduino Uno Project 7 | Keyboard Instrument

Hi, I am currently doing project 7, my code is perfectly fine (I think). However, only the bottom two buttons work and the top two don't. I'm terribly sorry if I come of as rude or have a bad question formatting, this is my first post ever! So any feedback would be appreciated :slight_smile:

(I'm not sure how to post code, but I think it's like this?)


int notes[] = {262, 294, 330, 349};

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  int keyVal = analogRead(A0);
  Serial.println(keyVal);
  
  if(keyVal == 1023) 
  {
    tone(8, notes[0]);
  }
  
  else if(keyVal >= 990 && keyVal <= 1010) {
    tone(8, notes[1]);
  }
  
  else if(keyVal >= 505 && keyVal <= 515) {
    tone(8, notes[2]);
  }
  
  else if(keyVal >= 5 && keyVal <= 10) {
    tone(8, notes[3]);
  }
  
  else {
    noTone(8);
  }
}

Check serial monitor. What value do you see printed when you press the buttons that don't work?

Going from left to right:

Button 1: 6-10
Button 2: 510-511
Button 3: 0
Button 4: 0

Thanks for reaching out PaulRB!

Swap the pushbuttons around. Any difference?

No, there was no difference I checked with a multi meter and all the push buttons were in working order, I did fix it, it seems there was something wrong with the bread board because when I was checking connections with a multimeter, it was not making a sound so I moved the pushbuttons and wires and bit and it was working!

Thank you for your help and support PaulRB!

1 Like

This type of 4-pin pushbutton can have problems in breadboards. Their pins are very short, and depending on the internal design of the breadboard, you may not always get a good connection.

1 Like

Some style push buttons don't have long enough / straight enough leads to fit a breadboard properly, so they can be a problem - the leads are bent to grip a 1.6mm thick PCB so it doesn't fall out when the PCB in inverted.

1 Like

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