Using multiple voltage dividers to measure multiple resistances at once.

Hello,
I am currently working on a project that requires me to measure multiple resistances at once, resistors being velostat based sensors, that change their resistance depending on the force that affects them. My idea was to use voltage dividers and measure the voltage using analog inputs. While having only one sensor connected, everything works as expected. However using two sensors results in none of them working. I will post the circuit and testing code below. Hope you can help me somehow, perhaps I'm not seeing something clearly and making a rookie mistake.
Thank you in advance.

Code:

void setup() {
  Serial.begin(9600);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
}

void loop() {
      int sensorValue1 = analogRead(A0);
      float voltage1 = sensorValue1 * (5.0 / 1023.0);
      int sensorValue2 = analogRead(A1);
      float voltage2 = sensorValue2 * (5.0 / 1023.0);
      
Serial.print(voltage1);
Serial.print(",");
Serial.println(voltage2);
delay(100); //add a delay
}

Circuit:

Best regards.

voltage_divider.png

Code looks sound, schematic is correct.

Check your wiring.

  pinMode(A0, INPUT);
  pinMode(A1, INPUT);

Analog pins are INPUT only. There is no need to set the mode of analog pins. With this code, you are setting the mode of the digital pin that shares space with the analog pin. Not a good idea, generally.

     int sensorValue1 = analogRead(A0);
      float voltage1 = sensorValue1 * (5.0 / 1023.0);
      int sensorValue2 = analogRead(A1);
      float voltage2 = sensorValue2 * (5.0 / 1023.0);

Depending on the impedence of the device being measured, the value returned by analogRead() may, or may not, be any good, when reading from a different pin. The usual solution is to read the pin twice, and throw away the first value.

      int junk1 = analogRead(A0);
      int sensorValue1 = analogRead(A0);
      float voltage1 = sensorValue1 * (5.0 / 1023.0);
      int junk2 = analogRead(A1);
      int sensorValue2 = analogRead(A1);
      float voltage2 = sensorValue2 * (5.0 / 1023.0);

PaulS:
Depending on the impedence of the device being measured, the value returned by analogRead() may, or may not, be any good, when reading from a different pin. The usual solution is to read the pin twice, and throw away the first value.

That is normally only an issue if the input impedance is >>10k, and the OPs schematic shows 220Ω resistors.

Actually, I read the diagram as 22 Ohm resistors.

This makes me wonder whether kczan is attempting to power the Arduino via the "Vin" ("raw") or "Barrel jack". That is always a bad idea given that the on-board regulator is essentially not capable of powering anything other than the chips on the Arduino itself and a couple of indicator LEDs.

An as a practical matter, it would be preferable to connect the sensors to ground and have the resistors as pull-ups.

What is the resistance span of the sensors?
Then we can determine whether the 220/10K values are appropriate.

An as a practical matter, it would be preferable to connect the sensors to ground and have the resistors as pull-ups.

But then, the voltage would go DOWN when the force went UP. That's against the laws of the noobies' universe, like putting your button between input and GND. ;D

Indeed.

And it all goes pear-shaped if you swap hemispheres.

You mean, cerebral hemispheres?

Touché

Hello, thank you so much for all your responses! I will try to answer your questions now.

Wiring looks good to me, but I will check it 5 more times just to be sure. As for measuring analog inputs twice, it helped me get an output like that:

5.00,0.00
5.00,0.00
5.00,0.04
5.00,0.12
5.00,0.01
5.00,0.02
5.00,0.02
5.00,0.00
5.00,0.00

One of the sensors seems to be immune to my applied force and just shows max voltage, but the second one shows some single signs of life. The output I showed is a result of applying a static force on the sensor, so it should go something like 0.04->0.09->0.15 for example and just stay there. But it immidiately goes down. Using the simplest thinking I can, I think it does that because the current just "wants to take the easier way" and goes through the other sensor.
As for the resistance of the sensors, I used Velostat from Adafruit. They say that one square centemeter of the material has the resistance of about 31,000 ohms. However while testing only one sensor, I got to the point where 22 Ohm resistor was perfect for the voltage divider, as I was able to get outputs in range 0.5-4V.

I am powering Arduino through the USB port right now, my workplace doesn't have much "microcontroller stuff", as this is one of the first projects using them. I will definitely try to get a better current source right now.
Thank you so much for all the responses once again, you really gave me hope!

EDIT: Unfortunately external source didn't help.

JCA34F:
But then, the voltage would go DOWN when the force went UP. That's against the laws of the noobies' universe, like putting your button between input and GND. ;D

The solution is simple to subtract the reading from 1024 to get it the right way up.

I actually managed to get proper readings now! Turns out re-wiring everything once again and using external power source helped a lot. Same goes with the tip to read analog input twice. Thank you so much everyone for help!