M-Duino PLC with Thermistor

The equipment I am working with is a standard Arduino Uno, an M-Duino PLC 58+, and a 500C Thermistor from Dyze’s Design. Below I have included links to the products I am working with.

M-Duino PLC 58+ - https://www.industrialshields.com/shop/product/is-mduino-58-m-duino-plc-arduino-ethernet-58-e-s-analogicas-digitales-plus-176
500C Thermistor - https://dyzedesign.com/shop/accessories/thermistor-300c-500c/

To start out I made sure that I could get the Thermistor to work with a regular Arduino Uno. I used a simple ohmmeter code and created a voltage divider circuit. The known resistor value was 100000 ohms and when I combined it with the resistance tables that were provided with the Thermistor I was able to obtain accurate temperature readings. No problems there but to be safe I included the code down below.

CODE ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

int analogPin = 0; //analog input pin
int raw = 0;
int Vin = 5;
int i = 0;
float Vout = 0;
float R1 = 1000000; //reference resistance value
float R2 = 0;
float buffer = 0;
float Temperature;

//below are the resistance and temperature tables to linearly interpolate resistance to voltage

float Resistor_Array[27] = {8100000, 5200000, 4500000, 2830000, 666000, 288000, 136000, 70000, 38500, 22200, 13200, 8070, 5120, 3380, 2240, 1555, 1100, 790, 578, 434, 333, 253, 196, 157, 125.4, 102, 83.7};
float Temperature_Array[27] = {10, 20, 25, 30, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360, 380, 400, 420, 440, 460, 480, 500};

void setup() {

Serial.begin(9600);

}

void loop() {

raw = analogRead(analogPin);

if (raw) {

buffer = raw * Vin;         //calculates the R2 value to be converted to temperature
Vout = (buffer) / 1024.0;
buffer = (Vin / Vout) - 1;
R2 = R1 * buffer;
Serial.print("R: ");
Serial.println(R2);

while (R2 < Resistor_Array[i]) { 

  i = i + 1;

}

while (R2 > Resistor_Array[i]) {

  i = i - 1;

}

}

Temperature = ( ( R2 - Resistor_Array[i] ) * ( Temperature_Array[i + 1] - Temperature_Array[i] ) / ( Resistor_Array[i + 1] - Resistor_Array[i] ) ) + Temperature_Array[i]; //linear interpolation
Serial.print("T: ");
Serial.println(Temperature);

delay(1000);

}

Next, I wired it to the PLC. I created the same voltage divider circuit wiring it to an external 5V and GND while the only wire going to the PLC was for the analog input pin. The pin I used was pin I0.12 (for reference I included the M-Duino Datasheet below). However, I was getting extremely high resistance values on the order of 99Mohms. The Thermistors max resistance was 8.1Mohms and at room temperature should be ~5.2Mohms. I traced the problem back to the PLC and the analogRead() function in my code. The “raw” values were sporadic and random between 0-50 while a working thermistor would read ~170. Looking at the Datasheet I found that the analog input voltage range for the PLC is different than the Arduino Uno. The Arduino Uno’s analog inputs operate between 0-5V. So, with a 10bit logic, the 5V is divided by 1024 (2^10) to give increments of 4.8mV. The PLC on the other hand is 10V divided by the same 10bit logic so the increments are 9.7mV. To fix this I changed the “Vin” in the code to 10V while still powering it from 5V. The code for the PLC is below, it is similar and the only things that change is the Vin and analog input pin.

CODE ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

int analogPin = I0_12; //analog input pin
int raw = 0;
int Vin = 10;
int i = 0;
float Vout = 0;
float R1 = 1000000; //reference resistance value
float R2 = 0;
float buffer = 0;
float Temperature;

//below are the resistance and temperature tables to linearly interpolate resistance to voltage

float Resistor_Array[27] = {8100000, 5200000, 4500000, 2830000, 666000, 288000, 136000, 70000, 38500, 22200, 13200, 8070, 5120, 3380, 2240, 1555, 1100, 790, 578, 434, 333, 253, 196, 157, 125.4, 102, 83.7};
float Temperature_Array[27] = {10, 20, 25, 30, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 320, 340, 360, 380, 400, 420, 440, 460, 480, 500};

void setup() {

Serial.begin(9600);

}

void loop() {

raw = analogRead(analogPin);

if (raw) {

buffer = raw * Vin;         //calculates the R2 value to be converted to temperature
Vout = (buffer) / 1024.0;
buffer = (Vin / Vout) - 1;
R2 = R1 * buffer;
Serial.print("R: ");
Serial.println(R2);

while (R2 < Resistor_Array[i]) { 

  i = i + 1;

}

while (R2 > Resistor_Array[i]) {

  i = i - 1;

}

}

Temperature = ( ( R2 - Resistor_Array[i] ) * ( Temperature_Array[i + 1] - Temperature_Array[i] ) / ( Resistor_Array[i + 1] - Resistor_Array[i] ) ) + Temperature_Array[i]; //linear interpolation
Serial.print("T: ");
Serial.println(Temperature);

delay(1000);

}

Any assistance would be greatly appreciated and if I need to provide more information I am more than happy too. Thank you in advance.