keep analog input separated from output pin: wrong analog read with out pin high

Dear all

i've got an arduino uno REV3 powered with 12V DC with the following logic:

if (A0 < A1+x){
PIN12=HIGH
}else if (A1<A0){
PIN12=LOW
}

the problem is that when PIN12 goes high, the consumption of current of the realy causes a wrong reading on A0 and A1.

Any suggestion?

how can i keep the analog circuit separated from the digical circuit?

Thanks

Here my pin layout connection:

5v (PIN)---------
|-------R1
| |
| PIN(A0)
| |
| R2 (thermistor ntc5k)
| |
| GND
|
|-------R1
| |
| PIN(A1)
| |
| R2 (thermistor pt1000)
| |
| GND
|
|
| *****2 RELAY MODULE
|-------[VIN]
[IN1] - PIN(12)
[IN2]
[GND] - GND

i've found this function:

https://code.google.com/p/tinkerit/wiki/SecretVoltmeter

long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}

Available on Arduinos with a 328 or 168, i'll try to use this in the voltage divider function.

I don't get why that function can fix it... But if the relay is causing it to flip then:

  1. You power supply is weak, or
  2. It's not buffered enough, add some caps to the relay power lines or use a seperate voltage regulator for the relay part, or
  3. You have to wait a little before reading the ADC's again (please don't use delay :p)
  1. your ground wiring to the sensor is going through the ground wire that is carrying the relay current and causing ground lift.
  2. you are trying to connect the relay directly to the arduino output pin
  3. your "diagram" is wrong.

i'm quite new to electionics and arduino in general.

i've noticed that when the relay in on readVcc gives me 5023, when the relay is off i have 5068.

This difference causes a wrong reading as i'm using a PT-1000 which is very sensible in a small range of ohm.

using the readVcc function i've removed the error that i've made with the assumption that the 5 volt pin will be stable.

Hi,

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

Can you please post a copy of your complete sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

What is your relay module?

What is the spec of your 12V module?

Tom...... :slight_smile:

Hi TomGeorge and thanks for your reply.

i've found this page showing how to keep the two circuits separated

https://arduino-info.wikispaces.com/RelayIsolation

With this connection i don't have the problem.