analogReference()

Hi
I'm trying to imply button matrix with 1 wire method, so each button sends different voltage to shared analog input, my button matrix does work, but after a while, after my circuit turn on some instruments there is small voltage drop and voltages isn't correct. I was wondering about using analogReference() before reading the voltage, but I have two question:

  1. where I put the analogReference() function? in the setup() or in the loop() before using the analogRead().
  2. if at first for example the analogReference() is reading let's say 5V, but after a while the voltage drop to 4.8V, does the analogReference() auto update or should I call this function again?

What you really need to do is supply your button matrix with a voltage that remains constant. Why is your voltage dropping so much? Please post a schematic, and also what you are using for power.
S.

after my circuit turn on some instruments there is small voltage drop

Are you using your microcontroller board as a power supply for the 'instuments'? If you are, then DON'T. :slight_smile:

There should be no problem with default Aref if the button matrix is powered from the Arduino supply (5volt pin).
Because the Arduino A/D does not measure 'voltage', it measures ratio.
Using a fixed reference voltage could make things worse.

Note that a simple button matrix could be unreliable over time, when the switches start to oxidize.
Leo..

the button matrix I used is something looking like that:

now for VCC I can use either the Arduino Vout, or regulate power supply (the end product would be battery), my problem is that after a while the reading change because there is powered drop, the Arduino ratio is analogread() to 5V (or Vout) but not always, the resistor ratio is constant, but since there is voltage drop in the VCC, the reading doesn't remain constant, therefore I'm asking about analogReference().

I'm adding a note here: I'm planning to implys my progrem in attiny85, so Vout won't be available.

Wawa is right.
Keep the default voltage reference. It is set by default to the VCC of the ATmega or ATtiny. I assume that AVCC is the same as VCC.
Power the matrix with that same VCC pin.
The analogRead() returns the ratio, which will be always the same, regardless of the actual voltage of VCC.

The voltage drop over the diode causes extra trouble, because then the forward voltage drop makes the circuit a little sensitive for the voltage. It is no longer pure ratio.

Wawa is also right about bad contacts after a while. Your circuit is the most sensitive circuit for bad switches that I have ever seen. If you buy switches with gold plated contacts, then it might work. If you have the cheapest buttons you can find, then it might work for a year, or even fail the first time.

I had an apparatus once, that had bad contacts, and sometimes it did something else by pressing a button. That is why I never use a analog input with a resistor-ladder. Your resistor-matrix is even worse. A lot worse. You can make it for fun or for school, but don’t use it in a project that you actually will be using.
There are I2C I/O expanders, that can read a button matrix over the I2C bus.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.