Measure resistance using a matrix configuration with Arduino

I have prepared a resistance array with two columns and two rows. (Same way as in the image.) The columns are connected to digital pins 8 and 9 on the Arduino, while the rows are connected to analog pins A0 and A1. I’m using two 1 MΩ reference resistors, each connected between ground and the analog pins (A0 and A1). I tried writing Arduino code to measure the resistance values, but the readings are incorrect. Help me to solve. Image is attached as an exsample.

const int rowPins[] = {A0, A1};        // Analog pins connected to rows
const int colPins[] = {8, 9};          // Digital pins connected to columns
const float referenceResistance = 1000000.0; // 1 MΩ reference resistor

void setup() {
  Serial.begin(9600);
  for (int col = 0; col < 2; col++) {
    pinMode(colPins[col], OUTPUT);
    digitalWrite(colPins[col], LOW);
  }
}

void loop() {
  for (int col = 0; col < 2; col++) {
    digitalWrite(colPins[col], HIGH); // Activate current column

    for (int row = 0; row < 2; row++) {
      int analogValue = analogRead(rowPins[row]);
      float voltage = analogValue * (5.0 / 1023.0);
      float resistance = (5.0 - voltage) * referenceResistance / voltage;

      Serial.print("R");
      Serial.print(row);
      Serial.print(col);
      Serial.print(": ");
      Serial.println(resistance);
    }

    digitalWrite(colPins[col], LOW); // Deactivate current column
    delay(200);
  }

  delay(500); // Delay for readability
}

The best that configuration will get you is a reading of 0 or thereabouts. You'dhave no voltage on the analog inputs. And even if you constructed a voltage divider, 1M is about 100x bigger than you ought to use. Quoting from the 328P datasheet:

The ADC is optimized for analog signals with an output impedance of approximately 10 kΩ or less. If such a source is used, the sampling time will be negligible. If a source with higher impedance is used, the sampling time will depend on how long time the source needs to charge the S/H capacitor, with can vary widely. The user is recommended to only use low impedance sources with slowly varying signals, since this minimizes the required charge transfer to the S/H capacitor.

But ignoring all that for a moment, since it seems to have no relation to the code or diagram you've shown, could you explain why your text and code uses 2 columns and 2 rows, but your diagram shows 3 of each?

In the image you show 3 columns and 3 rows (as seen in your code). Bus you state that you are using 2 columns andn 2 rows. What are you really using? We can't check what is how setup, its really confusing and a waste of time just trying to figure out what you want to say.

Also, you know your code doesnt work with this configuration, why not try 1 column 2 rows or something like that?

Start with the smallest possible setup.

pd. where did you get that 1 mohm would work?

1 Like

You have several parallel paths of resistance here that there is no way you would be estimating anything like 1Mohm. I drew 3 colored lines out of just one path (see attached picture with red, green, and blue paths through the top left most resistor) and if every resistor in the matrix is a 1Mohm resistor, the total resistance of the three paths that I drew would be about 0.66 Mohm. There are other resistance paths available that I didn't draw, each of which relates to the total value of the measurement for the top left resistor, so the actual effective resistance would be much less than 0.66Mohm.

Try measuring the resistance of a 'single' resistor with a meter. Connect a multimeter between D8 and A1 and see what your meter reads; I bet it will be less than 500Kohm.

To be clear, I'm not sure your code is messed up, but I am sure your series/parallel resistance isn't going to allow you to measure any of those resistors accurately.

2 Likes

https://www.electronics-tutorials.ws/resistor/res_5.html

Hi, @KavinduLPSL
Welcome to the forum.

Do you have a DMM to measure your circuit parameters.

Have you calculated, using OHMs law what voltages you should have on the analog inputs for each resistor?

I agree, when you turn any of the digital outputs from HIGH, say 5V or there about, to LOW, which is gnd == 0V so the array you have turn LOW are still in your measuring circuit.

Have you tried to measure just one resistor with one analog input to prove your basic circuit and code?

Tom.... :smiley: :+1: :coffee: :australia:

Are you aware that when a MCU output pin is LOW, it is not an open circuit, it is connected to GND?

As Wallis would say :-
"No diodes grommet"

3 Likes

Could not resist that last one, because adding diodes would only save you if you had a switch matrix.

Fundamentally you can't put resistors for measurement in a matrix.

The real solution is to route each resistor, and balancing high value resistor, through a multiplexer, or a series of multi layer multiplexers. Like this:-

Note here that your resistor to measure and the balance resistor are defined by the voltage at the wiper of the pot. Replace these with fixed resistors.

1 Like

I need a Complete guide to measure resistors 3x3 array from PCA9548A 1-to-8 I2C Multiplexer Module and Arduino uno using known resistors.

I have merged your two similar topics.

The PCA9548A is an I2C multiplexer and not suitable for what you want to do.

What is it that you want to achieve?

  • Do some resistor measurements in a real project?
  • Just experimenting to learn?
  • Something else that I've not guessed?

Why a matrix?

  • Is it your solution to some other problem that you haven't mentioned yet?
  • Is it because you want to measure the resistance of a lot of resistors and don't have enough analog inputs?
  • Something else that I've not guessed?

Is it your college assignment?

2 Likes

And given the "give me a complete guide to setting up the hardware and the code" tone of the CO's two other cross posts on the same subject, my suspicions about possible AI origins of the odd code and wiring diagrams are intensifying.

What part of:-

Are you not understanding?

The OP has yet to respond to a single question, so there's no evidence that they're even reading the replies. They seem to have moved on to "just gimme a complete solution".

I am working on developing a pressure sensor array where the resistance changes in response to applied pressure. I have designed a row-column electrode array, with sensor material placed at each intersection point.

However, I have not been able to find a proper guide on how to construct and program the array using an Arduino Uno. Could you provide assistance with the hardware setup and coding?

Hello KavinduLPSL

For sure.

Post the sketch, a connection and wiring diagram, the data sheets as well.

1 Like

I have merged your cross-posts @KavinduLPSL.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

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