analogRead() with 5 resistance sensors

Hello,
please I have a problems when i connect 5 resistance sensors based on nano-composite ( new type of sensors: when we make pressure of this kind of sensors we cause a resistance variation of the sensor based on carbon nanotubes)
if i connect 2 sensors on arduino mega it's ok but if i connet more than 2 sensors, each analog value was influenced by the others.
so, please can you help me !!!

Not without at the very least a circuit diagram.

bolbol:
but if i connet more than 2 sensors, each analog value was influenced by the others.

The Mega has only one ADC and it gets switched to the different analogue pins. That means that the first reading on a pin may be measuring the residue from the previous pin. A simple solution is to discard the first reading after changing to a new analogue pin.

...R

but if i connet more than 2 sensors, each analog value was influenced by the others.

Which means the impedance of you sensors is too high.
An alternative to Robin's approach would be to use a voltage follower op amp on each sensor output before input to the Maga.

  1. connect the sensors between analogue pin and ground.

  2. add a pull up resistor of about the same value of the sensor in the middle of it's range, between analogue pin and VCC (5volt).

  3. add a 10-100n capacitor between analogue pin and ground.

  4. read the sensor twice, to reduce any ghost charge from the previous pin reading.

All of the above, not just one.
And don't share sensor(s) ground with other grounds, e.g LEDs or LCD displays.
Leo..

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Try post #2 solutuion, it is also good practice with many analog channels being read at a high rate due to multiplexing operation. :slight_smile:

What is the range of resistance values of the sensor?

Thanks.. Tom.... :slight_smile:

Hi here is my solution:

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
}
unsigned int analogReadReference(void) {
  
  /* Elimine toutes charges résiduelles */


  ADCSRB &= ~(1 << MUX5);
  ADMUX = 0x5F;

  delayMicroseconds(5);
  /* Active le convertisseur analogique -> numérique */
  ADCSRA |= (1 << ADEN);
  
  /* Lance une conversion analogique -> numérique */
  ADCSRA |= (1 << ADSC);
  
  /* Attend la fin de la conversion */
  while(ADCSRA & (1 << ADSC));
  
}
void loop() {
  for (int k=0;k<4;k++){
  for (int j=0;j<4;j++){
   for (int i=0; i < 4; i++) {
    (void)analogRead(A15);
  int sv0 = analogRead(A15);
  unsigned int raw_ref = analogReadReference();
  (void)analogRead(A7);
  int sv1 = analogRead(A7);
    raw_ref = analogReadReference();
  (void)analogRead(A0);
  int sv2 = analogRead(A0);
    raw_ref = analogReadReference();
  Serial.print(sv2);Serial.print("              av1=");Serial.print(sv1);Serial.print("              av2=");Serial.println(sv);

my solution is based of the configuration of the ADC of the ATmega 2560 and i got this informations from the datasheet of CPU ATmega 2560, so we can eliminate the residual charge, activate the ADC and beginning new conversion.
yes Grumpy the impedance of sensors is very high, it's responsible of the main problem.
thanks wawa for the solution and i will try it as soon.
thank you very much for your time and your help

(void)analogRead(A15);
int sv0 = analogRead(A15);

Could just be

int sv0 = analogRead(A15); // dummy read
sv0 = analogRead(A15); // da real one

Leo..

What is the range of resistance values of the sensor?

My experience tells me that this is a very important issue: a large value on resistances will lead to wrong ADC (even with another one to Vcc).

Regards.

Not an issue if you apply all the rules mentioned in post#4.
Leo..

bolbol:
my solution is based of the configuration of the ADC of the ATmega 2560 and i got this informations from the datasheet of CPU ATmega 2560, so we can eliminate the residual charge,

Can you post a link to the datasheet from which you got that information. It is not in my datasheet.

I can't help feeling you are just duplicating with registers what is being done when you read the ADC twice using analogRead() and discard the first reading.

...R

Wawa:
Not an issue if you apply all the rules mentioned in post#4.
Leo..

Even with the cap you can have problems with high valued resistors (> 10 kOhm).
Regards

At 10k you don't need to do anything special: that's the recommended limit to input impedance for the analog pins.
With the capacitor you should be able to go to 100k without issues, maybe even higher like towards 1M, but if you get into that kind of values it's time to consider adding a buffer. A cap on the input does slow down reaction so not good for fast changing signals.

wvmarle:
At 10k you don't need to do anything special: that's the recommended limit to input impedance for the analog pins.
With the capacitor you should be able to go to 100k without issues, maybe even higher like towards 1M, but if you get into that kind of values it's time to consider adding a buffer. A cap on the input does slow down reaction so not good for fast changing signals.

I regret insisting: I've made a project involving a pro mini and made many (more than a dozen) tests with different units, either chinese and Sparkfun ("half genuine") ones. Every time I noticed an unstable behaviour with sensors whose impedance is greater than those values, even adding a cap.

As many other characteristics of this microcontroller, this parameter is not well docummented and this behaviour has no apparent reason. I just tell what happens.

Best regards.

If you continue to have problems, the easy solution is adding a buffer (i.e. a unity gain OpAmp circuit) between the sensor output and the input pin.

I don't see how a buffer, or capacitor, or battery (without voltage divider) are any different from each other.
They all provide a solid point for the A/D to sample from. Either drawing or dumping some current.

What is important is that there is no ground difference between the three above sources and analogue ground.
Maybe the tests were flawed there.

A capacitor ofcourse changes ratiometric sampling into voltage sampling.
Something to watch out for if the cap is too big or Aref is too dirty.
Leo..

Wawa:
I don't see how a buffer, or capacitor, or battery (without voltage divider) are any different from each other.
They all provide a solid point for the A/D to sample from. Either drawing or dumping some current.

What is important is that there is no ground difference between the three above sources and analogue ground.
Maybe the tests were flawed there.

A capacitor ofcourse changes ratiometric sampling into voltage sampling.
Something to watch out for if the cap is too big or Aref is too dirty.
Leo..

Many years ago somebody asked me how a deffective transistor behaves. I was quick that time: I answered that I know how a non defective transistor works, not a broken one 8)

I don't know what the problem with the pro mini ADC is, but I can assure that it exists (and I can reproduce it easily). I have identified the following sympthoms:

  1. When trying to read a voltage divider made with resistors bigger than 10 kOhm, not just the analog input the divider is connected to, but some of the others (some times all of them), start either giving wrong readouts and/or, apparently, block themselves (The bigger the value the most probable the problem; I like very much this english construction: "the further they are the faster they move" -the planets. I am not english native).

  2. Even when everything seems being working correctly, simply by disconecting one of the sensors may fool the whole ADC subsystem. The clamp diodes and the 100 nF cap keep being connected in every -of the 8- input.

I do not know how a defective ADC system works ... I just can recommend:

  1. Using a cap in every input.
  2. Do not connect sensors without disconnecting the whole system.
  3. Do use low impedance sensors and/or use a buffer.

Best regards.

vffgaston:
As many other characteristics of this microcontroller, this parameter is not well docummented and this behaviour has no apparent reason.

Yes it is well documented and their is a reason.

It is the sample and hold capacitor on the input to the A/D. Doing just a simple analog write to an input channel switches the input analogue multiplexer to the new channel and starts a conversion. There is little time for the sample and hold capacitor to acquire the same voltage as the newly switched input if the input of that source has a high impedance. It is also worse if the previous channel that was measured had a large difference in voltage than the previous one.

A capacitor allows more rapid charging of the sample and hold capacitor as it equalises voltages quickly especially when the external capacitor is >> than the internal one.

The two samples method allows the sample & hold capacitor to charge up to the input voltage during the time the first sample is taken and then at the second sample it hopefully is at the correct voltage. With much higher impedances it will not be fully charged and then you should introduce a delay between the two samples.

All the information to deduce this is in the data sheet, and promulgated almost weekly on this forum.

  1. Do not connect sensors without disconnecting the whole system.

Do not do any sort of wiring up to a system that is powered up. A lot of beginners have never been told this. Probably because of video tutorials made by people who don't know what they are doing.