Tag

Buttons

Browsing

Here are some ideas of what you can do with the humble voltage divider. This elementary circuit has a few inventive uses. To be upfront, one of these uses is NOT as a voltage regulator. If you need a voltage regulated, get a voltage regulator! At some point or another, I’ve built all five of these voltage divider circuits. For me, the voltage level shifter is the most common.

  1. Measure Battery Voltage
  2. Signal Level Shifter
  3. Reference Voltage
  4. R-2R Ladder
  5. One Analog Input with Many Buttons

To detect a short and long button press using millis can give your project more functionality without adding more buttons. In this line-by-line example, I show how to react to a user pressing a button for a short period (100ms) or a long period (over 500ms). My example changes the blink rate of an LED on short presses. A long button press turns off the LED.

In the code, I make use of a struct so that a single variable can be used to track multiple parameters. The benefit of this method is that adding multiple buttons is easy. You could create an array of these tyepdef’d variables.

When hooking up switches or buttons to an Arduino I/O pin, sometimes the results might appear completely random. Sometimes it will appear as though there is a delay from when the button is pressed until the state of the pin actually changes. Other times the pin’s value will seem to randomly fluctuate from HIGH to LOW. Even more maddening might be as your finger gets closer to the switch, the pin’s state changes! The fix to these problems is simple: use the Arduino Internal Pull-up Resistor. Here’s how they can fix this problem and how you can use them with an Arduino board.