Can you use two different sensors with 5V and 3.3V, both with analog inputs ?

I have a temperature sensor that requires 5V and an Air quality sensor that has a limit of 3.3V. I need both to be connected to separate analog inputs, A0 and A1 on the Arduino Uno. Both sensors connect to the same ground in my circuit on the arduino. The sensors are only connected to each other through the arduino and don't share circuitry except for the fact they both connect to pins on the arduino. Will the voltage difference cause issues?

There would be no real issues hooking them up straight to two analog inputs. However there's 2 things that will give you reduced accuracy:

  1. The 3.3V sensor is not covering the full 0-5V range of the analog input. So you get only 0-675 as the possible range of outputs. You could add an amplifier to amplify it up to 5V but that's a lot of extra circuitry.

  2. The sensors are usually "ratiometric" and the Arduino analog inputs are ratiometric. That means everything is a ratio to the supply voltage. A 5V pressure sensor running on 4.9V will give an output that is 4.9/5 times the voltage you would expect. That's fine when it is powered from the Arduino's "5V" line because the Arduino input is also 0.1V lower than expected and it corrects the error.

Now both the 3.3V and 5V lines won't be exactly at their nominal voltages. They can be higher or lower. If the 3.3V is a tiny bit high and the 5V is a tiny bit low, then the analog input will give a reading that is too high.

One way to correct for this is to connect a vacant analog input to the 3.3V line and use that to calculate a multiplier every time you take a reading from the 3.3V sensor.

I have done something similar many times: with a 3.3V Arduino and 5V ratiometric sensors, I use voltage dividers to bring everything down to the 3.3V range and there is an identical voltage divider on the 5V supply so I can measure that every time I take a measurement from my sensors.

"1. The 3.3V sensor is not covering the full 0-5V range of the analog input. So you get only 0-675 as the possible range of outputs. You could add an amplifier to amplify it up to 5V but that's a lot of extra circuitry."

Shouldn't that be fine though since the sensor's limit is 3.3V the outputs wouldn't need to have the full range because ordinarily wouldn't the sensor only go up to 3.3V anyways? Or is there something to do with analog inputs requiring certain voltages? Also, I forgot to mention I have another sensor that uses I2C and SDA and SCL lines that has a 3.3 Voltage limit as well. Will this cause issues If I use it the I2C 3.3 V instead of the analog 3.3 V sensor?

You have less resolution - only 675 different values possible, instead of 1024 different values.

Probably, it is possible!

1. Let the 5V sensor be biased with 5V of the UNO. Connect the signal output with A1-pin. Operate the sensor with VREF = DEFAULT = 5V. The resolution will be: 5/1024 = 4.88 mV/LSBit.

1. Let the 3.3V sensor be biased with 3.3V of the UNO. Connect the signal output with A0-pin. Operate the sensor with VREF = INTERNAL = 1.1V. The resolution will be: 1.1/1024 = 1.07 mV/LSBit.

3. Execute the following program (determined experimentally) which changes the VREF voltage as the type of the sensor changes.

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  sensor1();  //LM35 Temp Sensor; Bias Voltage=3.3V ;Vref=1.1V INTERNAL; Test Signal LM35 signal
  sensor2();   //bias Voltage 5V; Vref = 5V; Test Volt = 3.3V at Ch-1 ==> 1024/5 * 3.3 = 675
  delay(2000);
}

void sensor1()
{
  ADMUX = 0xC0;  //Channel-0 with Vref = 1.1V INTERNAL; 
  ADCSRA = 0b10000111;   //ADC is enabled; clkADC = 125 kHz
  bitSet(ADCSRA, 6);       //start conversion
  while (bitRead(ADCSRA, 6) != LOW)
    ;                                       //wait unti conversion is done    
  unsigned int x = ADCW;       //read ADC value

  float lmTemp = (float)100 * (1.1 / 1024) * x;//analogRead(A0);  //compute float value
  Serial.println(lmTemp, 2);
}

void sensor2()
{
  analogReference(DEFAULT);  //Vref = 5V
  unsigned int y = analogRead(A1);  //Channel-1
  Serial.println(y, DEC);
  //----------------------------------------------
  ADMUX = 0xC0;  //Channel-0 with Vref = 1.1V INTERNAL; mandatory to me
}

GolamMostafa:
1. Let the 3.3V sensor be biased with 3.3V of the UNO. Connect the signal output with A0-pin. Operate the sensor with VREF = INTERNAL = 1.1V. The resolution will be: 1.1/1024 = 1.07 mV/LSBit.

Only works like this if:

  1. the output of the 3.3V sensor is absolute, and
  2. the output of the 3.3V sensor is less than 1.1V.

OP didn’t specify the sensors used, so I’m not going to speculate on what he may or may not have.

Also you have to give the ADC some time to adjust to the new reference. Calling analogRead() twice and discarding the first reading normally does the job (it’s a quite slow function, taking some 100 µs to return).

If you change the reference then no analog input can be higher than the reference. How do you unplug the 5V sensor thousands of times per second?

MorganS: If you change the reference then no analog input can be higher than the reference.

By my understanding no analog input should ever be higher than Vcc+0.5V. All voltages >AREF give 1023 as output, but should not do any damage to the pin or cause any other issues.

From the data sheet:

Voltage on any Pin except RESET with respect to Ground . . . . . . . . . .-0.5V to V CC +0.5V

wvmarle: Only works like this if: 1) the output of the 3.3V sensor is absolute, and 2) the output of the 3.3V sensor is less than 1.1V.

Point-2 is fine. Point-1 is not clear -- in what sense, the output of the sensor is absolute.

How can you be sure? All OP disclosed is that it is an "air quality sensor".

GolamMostafa: Point-2 is fine. Point-1 is not clear -- in what sense, the output of the sensor is absolute.

In the sense that the voltage is derived from an absolute reference and is not simply a ratio of the supply voltage.

For example a LM335Z is an absolute sensor and a MPXV7002 is ratiometric.

So, we may state that -- LM35 and DS18B20 are also the examples of absolute sensors as their responses do not depend on their bias (supply) voltages.

The DS18B20 is a poor example as it's output is digital rather than analog.

wvmarle: The DS18B20 is a poor example as it's output is digital rather than analog.

It is my understanding that the sensors that react to the slowly varying environmental parameters (temperature, humidity, light intensity, and the similar) are inherently analog devices. They convert the causes into proportional analog electrical signals (voltages/currents) which we condition, in the next stage, using analog/digital interface circuitry.

Yes, but you don't read it with analogRead(). So there's no relevance to supply voltage.

MorganS: Yes, but you don't read it with analogRead(). So there's no relevance to supply voltage.

analogRead(); just reads the ADC value of the ATmega328P.

Yes, so it has nothing to do with a DS18B20.

MorganS: Yes, so it has nothing to do with a DS18B20.

Likewise, anaologRead(); has nothing to do with the absoluteness of LM35/DS18B20. So, which factor does disqualify DS18B20 to have the same absoluteness as the LM35 has?

Because you do read the LM35 with analogRead(). Or am I missing something?

MorganS: Because you do read the LM35 with analogRead(). Or am I missing something?

What else I have (without analogRead()) to read the value of LM35 ?