Tag Archives: #Arduino

Week 4: Button Combination Lock

The button combination lock assignment commissioned us to make a electric lock that could be “unlocked” when a predetermined combination was input into the Arduino processor.  I attempted this assignment in two different ways.

The first was engendered by an Instructables page, HOW TO: MULTIPLE BUTTONS ON 1 ANALOG PIN – ARDUINO TUTORIAL, through this way I gained a better understanding of how to set up the breadboard circuitry. However, the method failed as I was not getting a consistent return on data from each button.


As seen in the pictures I set up the breadboard as the tutorial had indicated, using a resistor ladder, so that all the input could be sent through a single connection (0A). Unlike the tutorial, my return when each button was pressed was not a single identifying number, but a series of randomly repeating numbers. For example, the green button when pushed would show a random compilation string of the numbers 2,3, and 4. Thusly, I was unsure of how to proceed to associated the series to a variable.

Also unlike the tutorial, I found that the resistors they recommended, 1x 1K, 2K, 3K and 10K resistors, were too strong, resulting in more inconsistent returned numbers from the buttons. When I changed the resistors to those of a weaker level the series of numbers returned had less 0s and a more unique set (if you will). In the image below of the Arduino monitor screen you can see a set of 4 randomly occurring numbers. Starting from the left; blue button was 1, 9, 8, 2, and 0, yellow button was 1, 2, and 3, green button was 2, 3, and 4, and lastly red button was 6, 5, and 1.


  • Arduino uno
  • Breadboard
  • 4x button sw
  • 4x leds (yellow,red,blue,green)
  • 4x 330 Ohm (or 220Ohm) resistors
  • 1x 1K, 2K, 3K and 10K resistors

How it works/ Issues:

According to the Instructable, “for every time a button is pressed, the Arduino receives an analog value from 0 to 1023. ” Depending resistance to each button this value changes, which is what I saw when I changed the resistance to a lower value. The architect of this assembly found that they would recognize which button was pressed by the analoged value from the resistor (1st button: 1013
2nd button:1004, 3rd button: 995, 4th button: 871), however like previously state, mine did not have a consistent return value.


void setup() {
int buttonvalue;
const int ledPin = 13; //Pin 13 will have the LED light
void loop() {
  int sensorValue = analogRead(A0);

Since I don’t have much experience with code, nonetheless Arduino circuitry, I turned to a classmate for help. Together we recoded part of the arduino and changed the board to where there was no longer a single connection transporting the data, but one direct connection per button. The coding was mostly his doing and its subsequent dissection allowed me to see the synatx of his method.


  1. Using a bread board and two jumper wires connect the ground to GND on the Arduino and the power to 5V on the Arduino.
  2. Take out the four buttons and place them abreast one another and in the center of the board.
  3. On the ground side take out the 4x resistors (800ohm to 1,400 ohm) and per button, connect the ground to the button leg (leave space for the jumper wire).
  4. Using 4x jumper wire, place the wire in between the button and resistor and connect to a subsequent digital pin (13-10).
  5. Connect another 4x jumper wires from the other side of the button to the power.
  6. The 220 ohm resistors will connect into ground and orient them towards the center of the board.
  7. Place the LED (negative side) along side the resistor.
  8. One the positive side of the LED place the remaining two jumper wires and connect them to digital pins (8 & 9).


  • Arduino uno
  • Breadboard
  • 4x button sw
  • 12x jumpers
  • 4x resistors ranging from 800ohm to 1,500ohm
  • 2x 220 ohm resistors
  • 2x LED (green and red)

How it works/ Issues:

In comparison to the Arduino code the physical circuitry was relatively easy to put together. Nevertheless it still doesn’t work, so I can’t for certain say my composition is functional. Each button is connected to it’s own jumper cable which is then connected to an individual pin on the Arduino. Using const int I associated the pin number (13-10) to a correlating button (green, red, blue, yellow). The resistor were connected into ground while the end cable was connected to power to complete the circuit. Since each isolated pin could relay data directly to the board, in theory, it made identifying the buttonpush easier, from this point the Boolean code and conditionals would determine a combination and process the data. This part was out of my depth, but my classmate’s help and contributions have allowed me to gain a better understanding of how the Arduino processes information.

Button Combination Lock

I will include the code with my dissection.

Chyelle’s Dissection of Arduino Code Syntax