Arduino Leonardo code question Buttons and Restistors

Hi all, I need your help again with one of my boards I`m building.

I have 5 push buttons in a Cruise Control Handle. They are 2 wire. Each button carries a specific resistance.

I have two questions:

1# Is this wired correctly? I`m not sure if I need 5v, A0, D1 or gnd at all (sorry).

2# I need code for my Leonardo Rev3, who can help me?

I want:

When button 1 is pressed (15k ohm on the multimeter) Keyboard.print(“7”);
When button 2 is pressed (6.8k ohm on the multimeter) Keyboard.print(“c”);
When button 3 is pressed (330 ohm on the multimeter) Keyboard.print(“c”);
When button 4 is pressed (150 ohm on the multimeter) Keyboard.print(“0”);
When button 5 is pressed (68 ohm on the multimeter) Keyboard.print(“9”);

I'm sorry, but it is not okay. The Arduino analog pins can read a voltage. As soon as you press a button, the voltage is 0V.

Why would you get into trouble anyway ? Why not use 5 pins for 5 buttons ?

I think the first scheme is wrong

Koepel:
I'm sorry, but it is not okay. The Arduino analog pins can read a voltage. As soon as you press a button, the voltage is 0V.

Why would you get into trouble anyway ? Why not use 5 pins for 5 buttons ?

Cause my buttons are in this handle and I only have 2 wires to connect:

If the analogs can read voltage, wouldnt I be able to wire it like this?
Since all resistors will output a different voltage?

LINK TO TECH DETAILS

No, sorry. The only thing that happens is when a button is pressed the voltage at A0 is pulled down to GND with a resistor.

Is it possible to combine other pins, and still create 5 pins for the buttons ?

jeroenV1982, please remove your links with mega.nz
You can scroll back and select more/modify and remove those links.
I'm not going to click on such hidden links.

If you want to point where Fritzing can be downloaded, do it like this : Fritzing
That is far more obvious that something with: "#!yQ1QBYbJ!ycpnIktRn7nmYdjjPFcU4IJKrGB0bbG6yFQRs6Lrmdk" (that is what you use in your link).

Koepel:
No, sorry. The only thing that happens is when a button is pressed the voltage at A0 is pulled down to GND with a resistor.

Is it possible to combine other pins, and still create 5 pins for the buttons ?

jeroenV1982, please remove your links with mega.nz
You can scroll back and select more/modify and remove those links.
I'm not going to click on such hidden links.

If you want to point where Fritzing can be downloaded, do it like this : Fritzing
That is far more obvious that something with: "#!yQ1QBYbJ!ycpnIktRn7nmYdjjPFcU4IJKrGB0bbG6yFQRs6Lrmdk" (that is what you use in your link).

Thats my techsheet 5.3mb (picture) with all details and wiring scheme. The large number in the link is the decode link everyone needs to open files from MEGA. This is how MEGA works, the story is that all stuff on their server is encrypted so they cant be blamed (remember megaupload?!?) because without link (large c ode) they dont now what their hosting).

I cant upload 5.3mb files here can I?

Anyway, here is the sheet shrinked:

jeroenV1982:
1# Is this wired correctly? I`m not sure if I need 5v, A0, D1 or gnd at all (sorry).

No, you need to create a voltage divider against 5V, then you can measure different ADC values by using an analog pin, perhaps A0.

A working circuit schematics with 5 buttons and different resistor values is shown here:

That’s used with the “LCD Keypad Shield”, look at the part of the schematics where you see the 5 buttons.

The divider resistor value can be the sum of the three lowest resistor values, in your case perhaps:
68 + 150 + 330 = ca. 680 Ohm to connect against VCC (where the Keypad Shield uses a R2= 2K resistor).

I think I misunderstood you (twice).
The resistors are inside the Cruise Control Handle ? and you want to test if it would work with a few resistors on the breadboard that are just like the Cruise Control Handle ?

The values are weird, are you sure you measured them correct ?
Every value is more than twice the previous value. But 68 ohm is low, and there is a jump of more than 20 times instead of more than 2 times.

resistors:  68   150   330   6800   15000
increase :  -    2.2   2.2   20.6   2.2

The schematic of the how the buttons and resistors are connected inside the Cruise Control Handle confuses me. I see only 4 buttons and 5 resistors.

According to the description:
OFF : 1580 - 1610
ON : 660 - 670
ON+RET : 330 - 340
ON+RES : 150 - 155
ON+ACC : 60-61

Koepel:
I think I misunderstood you (twice).
The resistors are inside the Cruise Control Handle ? and you want to test if it would work with a few resistors on the breadboard that are just like the Cruise Control Handle ?

The values are weird, are you sure you measured them correct ?
Every value is more than twice the previous value. But 68 ohm is low, and there is a jump of more than 20 times instead of more than 2 times.

resistors:  68   150   330   6800   15000

increase :  -    2.2   2.2   20.6   2.2




The schematic of the how the buttons and resistors are connected inside the Cruise Control Handle confuses me. I see only 4 buttons and 5 resistors.

According to the description:
OFF : 1580 - 1610
ON : 660 - 670
ON+RET : 330 - 340
ON+RES : 150 - 155
ON+ACC : 60-61

From the workshop manual:

Please remember because its a game simulator there is only one toggle key for ACC ON/OFF which is "c" so I need a Keyboard.print("c"); for this little baby in my code.

The values that you measured of 68, 150, 330, 6k8, 15k are wrong ?

Koepel:
The values that you measured of 68, 150, 330, 6k8, 15k are wrong ?

No sorry, Fritzing wont allow custom Values so I had to pick the closest to real. It doesnt mather, I can adjust the values anyway.

I don't understand. How can you adjust the values if they are inside the Handle ?

Of course it matters, how can we pick a good resistor (see Reply #6) and a sketch if we don't know the values.

Koepel:
I don't understand. How can you adjust the values if they are inside the Handle ?

Of course it matters, how can we pick a good resistor (see Reply #6) and a sketch if we don't know the values.

Ok. To clarify things:

The Fritzing scheme above is made by me. I was in doubt I wired it correctly so without looking close to the values I posted it for peoples opinion.

The problem for the slightly wrong values is because I could not select the correct Resistor Values from the drop-down menu in the Fritzing Program. What I did was picking the closest values for my handle.

My Handles Resistors according to the Scania Workshop manual:

OFF R1= 1580-1610 ohm (Fritzing has no resistor of 1600 ohm so I took 15k ohm.
ON R2= 660-670 ohm (Fritzing has no resistor of 665 ohm so I took 6.8K ohm.
ON+RET R3= 330-340 ohm (Fritzing has no resistor of 335 ohm so I took 330 ohm.
ON+RES R4= 150-155 ohm (Fritzing has no resistor of 157 ohm so I took 150 ohm.
ON+ACC R5= 60-61 ohm (Fritzing has no resistor of 60.5 ohm so I took 68 ohm.

And that's why we hate Fritzing here. 6.8k is more than 100 times bigger than your desired 665

From that workshop manual schematic it looks like R5 should be connected to +5V. Possibly at that symbol at the top of the diagram. Then the whole thing will function as a voltage divider although not a very good one. Keep trying.

Don’t you need to use a voltage divider to drive an analog pin off a variable resistance?

PaulMurrayCbr:
Don’t you need to use a voltage divider to drive an analog pin off a variable resistance?

I can get it to work like this:

I can use a 10k ohm resistor as the known resistor. With this tutorial and code we can get the value, store it in the Arduino and then build an if/else to output the right character. I need your help to build that code.

Yes. Basically you don’t need to know the value of the resistors. You need to have distinct analogRead() values for each switch position.

Use the simple AnalogReadSerial example to print out the analog values for each switch. You will see noise or jitter so you need to allow for a range. For example you may find that analog values between 998 and 1011 mean there is no switch pressed.

Then write your ‘real’ program to use these values.

MorganS:
Yes. Basically you don't need to know the value of the resistors. You need to have distinct analogRead() values for each switch position.

Use the simple AnalogSerial example to print out the analog values for each switch. You will see noise or jitter so you need to allow for a range. For example you may find that analog values between 998 and 1011 mean there is no switch pressed.

Then write your 'real' program to use these values.

I guess your right, problem is I dont know how to write that code so I was hoping someone could help me with the code.

I guess your right, problem is I dont know how to write that code so I was hoping someone could help me with the code.

Do you mean the code to test the values, the actual code or both ?

UKHeliBob:
Do you mean the code to test the values, the actual code or both ?

Both