Hi i am working on school project and i need to use Arduino uno and connect 4 buttons to arduino interrupt pin (2,3) and to their own digital pins. But my connection didnt work and i dont know how to do it.
Before you asked, i can not use different type of arduino to have for every button their own interrupt pin. I need to connect them all to 1 pin and every button solo pin.
Later i need to do some method to filter which button or combination of buttons were pressed. But it will be second problem.
This is my connection (only in painting) i hope u will understand it. This is half working when every button can use interrupt pin, but i dont know how to connect them correctly to digital pin.
OK.
Here is the logic, but you must write the code for yourself. Thanks for being honest and advising this is a school project, in this regard the forum is just an extension of your research.
Think of one button connected to D4 and another to D5. The other side of the buttons are connected to GND.
D4 and D5 are configured as digital inputs and the internal pull-up is active, thus a small current will flow through the switch when closed and the pin will go from high (open) to low (ground) on switch closure.
The problem is asking how to use an interrupt to detect switch closure rather than polling the D4 and D5 lines. In we assume D2 is the interrupt pin we wish to use, how can we detect that either D4 or D5 has been pressed? Remember D4 and D5 are at a 5V potential due to the internal bias resistor (pull-up) that we turn on in the setup() part of our code.
Think about using a resistor(s) from the top of each switch (connection to D4, D5 ...) all to the interrupt pin. The value chosen must cause the voltage on the int0 or int1 pins to drop from logic high to logic low when any switch is closed.
You will need to draw the schematic, do some math on the voltage drop at the interrupt pin, select the correct resistor values, write the code for interrupt and the code to rapidly inspect D4, D5, D6, D7 to determine which was pressed ... write as functions to fulfill the "methods" requirement.
There are 20K pullup resistors built into the Atmega chip that can be accessed from software. These built-in pullup resistors are accessed by setting the pinMode() as INPUT_PULLUP. This effectively inverts the behavior of the INPUT mode, where HIGH means the sensor is off, and LOW means the sensor is on.
...
The value of this pullup depends on the microcontroller used. On most AVR-based boards, the value is guaranteed to be between 20kΩ and 50kΩ. On the Arduino Due, it is between 50kΩ and 150kΩ. For the exact value, consult the datasheet of the microcontroller on your board.