I am finding that analog input pins on my Mega 2560 do not behave as I expect. T
To read the current signals from two constant current sensors (oxygen Electrodes) at intervals, I am reading the voltage across a resistance for each one. They operate on 24V and provide a fixed current in the range of 5-20 mA to indicate the oxygen level.
I have used the book "Arduino circuits and projects guide" by Gunter Spanner to set up a voltage divider, so that I have a 550 Ohm resistor in parallel with the divider (R1 = 100 and R2 = 380 Ohms) between the signal input terminal and ground. For protection, I also have a Schottky diode parallel to R1 between the ground and the line to the Analog pin; and another from this pin to 5V. I am referencing the analog pins to the 1.1V reference voltage.
As these are nominal resistance values, I have measured each one before connection, so as to calculate the total resistance for the Voltage drop and the voltage divider ratio. The calculated total resistance is 250 and the measured total (between the sensor input terminals) is 258.
My code for one sensor is attached below. For both sensors I get a current that does not match the current I measure with a meter before connecting the sensors. The two sensors meter measurements are similar, yet the Arduino values also differ for the two sensors. The Arduino values are fairly constant over time. Further, when the sensors are disconnected, I still get a (smaller) reading from the analog pins!
Can you advise what is happening here, and how I can correct it?
Thank you in advance! Rob
// Measuring two constant current sensors at intervals
unsigned long nowTime;
unsigned long prevTime; //time of last recording
const unsigned long oneMin = 60000;
int nowSecs = 0;
int printNo;
//constant current sensor definitions
const float voltDividera = 98.8/(98.8 + 377);
const float vRef =1.10;
const int analogPina = A10;
int readingA = 0;
const float calA = vRef/1023 * 0.94/voltDividera;
float voltageSa = 0;
float currenta_mA = 0;
void setup() {
//Dissolved oxygen sensor code
Serial.println("Measuring current from sensors with resistors");
analogReference(INTERNAL1V1);
prevTime = 0;
printNo = 1;
Serial.println("Data: printno, secs from start, ReadingA, VoltageA, CurrentA, ");
}
void loop() {
nowTime = millis();
if (nowTime - prevTime >= oneMin) { //set time when sensors recoreded
prevTime = nowTime;
nowSecs = int(nowTime / 1000);
readingA = analogRead(analogPina);
delay(5);
voltageSa = readingA * calA;
currenta_mA = (1000 * voltageSa / 258);
Serial.print(printNo); Serial.print(", "); Serial.print(nowSecs); Serial.print(", ");
Serial.print(readingA); Serial.print(", ");
Serial.print(voltageSa); Serial.print(", "); Serial.println(currenta_mA);
readingA = 0;
printNo++;
}
}