Arduino Starter Kit Project 07 - Keyboard Instrument- / R2R Ladder Confusion

Hello everyone,

I am working on making the keyboard instrument (07 in the Arduino Starter Kit Project) and I seem to be having problems with one switch in particular. The first button I push has 5V going right into the 10k ohm resistance. No voltage divider. That gives me 0 volts being read by the analog. In the code below, a note is being played when the analog read is 1023, when will that ever occur? I cannot get a sound out of the first button. I have a schematic of the project attached.

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

void setup() {
    //start serial communication

void loop() {
  // create a local variable to hold the input on pin A0
  int keyVal = analogRead(A0);
  // send the value from A0 to the Serial Monitor
  // play the note corresponding to each value on A0

  if(keyVal == 1023){
    // play the first frequency in the array on pin 8
    tone(8, notes[0]);
  else if(keyVal >= 990 && keyVal <= 1010){
    // play the second frequency in the array on pin 8
    tone(8, notes[1]);
  else if(keyVal >= 505 && keyVal <= 515){
    // play the third frequency in the array on pin 8
    tone(8, notes[2]);
  else if(keyVal >= 5 && keyVal <= 10){
    // play the fourth frequency in the array on pin 8
    tone(8, notes[3]);
    // if the value is out of range, play no tone

Hi blairSharpe!

actually, if you look at the schematic, you see that when the first button is closed, the power line and the input pin A0 are short-cut and therefore you have 5V on A0 (and not zero volts). When converted, this gives you the maximum value of keyVal (= 1023).

However, I notice that this schematic creates quite some of confusion because of the overlapping wires. If they are really supposed to cross, then A0 is always short-cut with GND1, which does not make any sense of course :) Did you find the drawing somewhere or was it self-made? The picture in the project books that comes with the Arduino is much clearer, imho.


If the wire were joind at that point there should be a dot to show it is joined. As there is no dot there is no join. This is just one convention for wiring, I don't like it because it is not clear but it is easy for simple minded software packages to produce.

I much prefer where the wire crossing under an other wire stops just short of the wire and emmerges just after on the other side.

Hi Grumpy Mike,

oh, I see :) I was used to the convention that two wires overlapping but not crossing are represented one on top of the other, but with a small "bump" on the top one. Luckily this is also the conventions used in the Arduino book (which ironically refers to wires drawn as in the above picture as "connected wires"). Quite confusing, I agree...

Yes the small bump is the third way you can signify crossing but not joining. I used to use that a lot but it is difficult to get some genral purpous drawing packages to do that and make it look neat. Also I find this is fine for one or two but with a wire going over many other wires I think it tends to look messy.

If you use the crossing like on the diagram posted you are not supposed to have four wires coming together at a single point.

These three “standards” are used most of the time, as a reader of a schematic you have to cope with all of them, but it is best to stick to one if you draw things and your drawing package lets you choose.

So you guys are saying that the voltage is taking the path of least resistance which is A0? Makes sense. So it wouldn’t even bother to go to the 10k resistor and therefore have full voltage. But, if I press down the rest of the buttons, it will take the path of least resistance which would actually be the 10k resistor because that would then create a voltage divider correct? The problem is that I am not getting in my serial monitor a analog read of 1024. I have attached my arduino setup below and maybe you guys can help me figure out what is wrong with it.

So you guys are saying that the voltage is taking the path of least resistance which is A0?

No. There is a lot wrong with your thinking. First voltage dosn't follow anything, it is current that follows paths. Second this always follows the path of least resistance stuff is nonsense, current flows through all Avaliable paths.

We are saying that the circuit you posted is correct and if you have not got it working it is because you have not wired it up correctly. Your photograph has too many pixels and does not cover enough of your circuit for us to see your wiring.

Hi blairSharpe,

I tried to look at your setup as shown in the picture. So, let me recap and correct me wherever I'm wrong. S_1 (in the schematic) is the button closest to the buzzer, which gets the 5V from the yellow wire. When you push it, you should go down the ladder until line #26 on the breadboard, and from there in pin A0 on the Arduino. This seems to be the case in your wiring, as far as I can see. This one is also the problematic button, correct? Which values do you see on the serial monitor when you press it? A nice test (if you have the possibility to do it) would be to place a multimeter with a continuity test in holes 11c and 26c on the breadboard, and check if they are "connected" when you press the first button. If they are not, go one step before in the ladder and check the connection, until you find the point where the "path" is broken (might be that S_1 is not well fixed in the breadboard holes or even defective)

The problem is that I am not getting in my serial monitor a analog read of 1024

I suspect a typo here. You will never get a value of 1024 in any case: the maximum value returned from a 10-bit ADC would be 210 - 1 = 1023 and this is the value that your code wants to catch


Yes that is exactly how my my Arduino is setup. Apologizes for such a large picture I did not mean for it to be that big! When I press the button I get a value of 0. Wouldn't the 10k ohm resistor that is on #26 pull down the voltage to 0 when it is read by the A0 though? I will do that connection test that you are talking about. good thinking, thank-you.

Wouldn't the 10k ohm resistor that is on #26 pull down the voltage to 0 when it is read by the A0 though?

No it would not it would connect 5V directly to A0. If A0 was at zero volts then the whole circuit would be shorted out.

Try swapping the buttons over physically, it sounds like it is not working. Note with no buttons pressed you will see 0 on the analogue input.