Project 07 Keyboard Instrument

There is no mistake in this code. The first 2 lines:

int buttons[6];
int buttons[0] = 2;

are EXAMPLE lines, to show how it works. You can identify them because they have no number. The code always starts at
1.
2.

etc.
anything before that is 'code' to explain things.

Hello, I am a newcomer to arduino and I too have been having a problem with this project. The first key (notes[0]) is the only one not working and this is after I made the change to the code suggested by mikeucfl.

void setup() {
  buttons[0] = 2;
  Serial.begin(9600);
}

Furthermore when I tried changing the ranges for the first two keys to see if I could get a wider range for the first key to play (1000-1023 for first key and 990-1000 for second), the second key instead played the note the first key was supposed to play and the first key was still silent (I got this idea from the fact that since the last key was near the highest value and had a small range of values to read the actual note would have a slight stutter when played, so I tried tweaking the range values). My breadboard is the same as the one in the manual. Does anyone have any suggestions for me? Thanks.

Had same problems w/ '0' being returned; turned out I had (at least) 2 bad buttons in my kit. IMHO, they should have put a little less emphasis on making the book look pretty (got to love the 10 point font for readability too!), and more(?) on better components at this price...

Either way, still enjoying it immensely :slight_smile:

Just wanted to report that I had similar issues on this project. The first issue I've had really since starting with the book.

It was kind of weird though and after getting it to work I can't really explain what was wrong.

Looking at the diagram in the book it was the top push button that was not activating the piezo and reading zero in the serial monitor. Removing the push button and replacing with a normal wire instead made the circuit work as intended, giving me 1023 in the serial monitor, so the breadboard seemed fine.

I then got my multimeter and set it to resistance and measured across the push button noticing it change to zero resistance when I depressed the button. This seemed to suggest the button was working.

Then, not sure what was going on, I read this forum and decided to move the button one row down on the breadboard. It worked. I then swapped the button over for one of the other ones and they both worked.

So not sure what the problem is to be honest. Anyway, thanks for the tip, hope it doesn't catch me out again.

My problem with the buttons not working is that the pins don't reach all the way down into the breadboard.

I was able to fix by bending a set of pins outward and inserting the other deeper into the breadboard. After that it worked.

mikeucfl:
I think that may be a typo in the book (I see it in mine as well). AWOL's suggestion would fix it, or you could move 'int buttons[0] = 2' into the setup method and drop the int declaration.

e.g.:

void setup() {

buttons[0] = 2;
  Serial.begin(9600);
}

THANKS!!

Those two lines aren't actually for the code. They are only an explanation of how arrays are written.
The actual code starts at "int notes []= ..."

You can see that on the right side line 1 only starts there

The buttons part is NOT part of the code. It was just an example.

my last 2 buttons don't do anything. help?

SOLVED IT

SORRY FOR MY ENGLISH, I AM FROM COSTA RICA, ONLY SPEAK SPANISH
CHANGE THE TWO FIRST LINES FOR THIS.. WORK IT

int buttons[6] = {2,0,0,0,0,0};
/*int buttons[0] = 2;
*/

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);
}
}

Hello Everybody,
I am also having the same problem on this project. The last switch, the one connected to the 10 Kilohm resistor, only reads 0.

The problem is not the switch. If I switch it with one of those that work, it makes the sound. Instead, the one that was working, when put as 4th switch, doesn't work anymore.

Also, I tried to change the position on the breadbord, and the result is still the same. Any idea? =(

This is what the wiring looks like:

Is anything connected to the leg in row 27? It looks empty to me.

Sorry, I had moved a couple of things around and forgot to put it back in the right place.

This should be like it is explained in the book.

Plus, I don't understand one thing: the last resistance. In the book, it says "connect tall the switches' output in one junction. Connect this junction to ground with a 10 kilohm resistor". I don't understand the function of this last resistance, considering that every single switch has got his own resistance....

Thank you in advance...

Just started doing this and had the same problem.
Then after looking here realised in the book the 2 lines

int buttons[6];
int buttons[0] 0 = 2;

don't have line numbers at the start

Then the following line is:

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

I guess those first 2 lines aren't in the program, you're right though confusing, although i guess they are there for a reason of tutorial but as of yet i don't understand what it is trying to teach.

I had all these same problems. I tried everything that everyone suggested. The solution for me was adjusting the keyVal ranges...

if (keyVal >= 1011 && keyVal <=1023) {
tone(8, notes[0]);
} else if (keyVal >= 990 && keyVal <= 1010) {
tone(8, notes[1]);
} else if (keyVal >= 400 && keyVal <= 515) {
tone(8, notes[2]);
} else if (keyVal >= 5 && keyVal <= 10) {
tone(8, notes[3]);
} else {
noTone(8);

I had the same problem. Circuitry was fine, but it turned out I had the wrong resistor. Triple-check your colors!

How do you determine the keyVal ranges? Are the ones in the book determined by calculation or empirically? I can't find any information on where they come from, and I would love to be able to expand this project to add other notes, but am not sure where to find the keyVal ranges.

For instance, the book has keyVal == 1023, keyVal >=990 && keyVal <= 1010. I recognize 1023 from the maximum value the ADC can report back. Are the other values just guesses that are honed in with experimentation?

Thank you!

rshohet:
How do you determine the keyVal ranges? Are the ones in the book determined by calculation or empirically? I can't find any information on where they come from, and I would love to be able to expand this project to add other notes, but am not sure where to find the keyVal ranges.

For instance, the book has keyVal == 1023, keyVal >=990 && keyVal <= 1010. I recognize 1023 from the maximum value the ADC can report back. Are the other values just guesses that are honed in with experimentation?

Thank you!

Hello,

I just bought my Arduino Started Kit a couple of days ago and have started working with the examples. I am completely new to this so please tell me if I am incorrect in some way!

I have an answer to you regarding the keyVal ranges. They can be calculated quite easily if you know how to use Ohms Law and what the total resistance is for a circuit in series. In the case for button 1 being pressed then none of the voltage has been dropped before the analoge data reading. Thus resulting in a data signal from A0 of 1023 (5V). In the case for the second button being pushed then we will have a potential drop over the resistance before the button of V2 = 220*5/(220+10000)=0.108 V which is roughly 2.2% of 5 V. This should result in a reading of A0 to be 1000 and that is why the range for that button is set to be keyVal >=990 && keyVal <= 1010.

This process can be done to calculate the ranges for the other buttons as well. Hopefully this explanation helps. I can try to explain it more carefully if you need.

Can anybody enlighten me about why is piezo connected to pin8 since it is not PWM pin? Can it still output other than digital signal?

//Lex