First off I am using an Uno for this demo. I boiled this down to an example which is mystifying me. I created a Software Serial port for RS-485 coms using pins 3 and 4 and pin 2 used as a direction pin for the RS-485 board. By only setting pin 2 to be used as an output my LM335 readings shift considerably. If I choose output pin 5 and up it does not shift. Any ideas? I have tried another Uno.
#include <SoftwareSerial.h>
SoftwareSerial RS485Serial(3, 4); // RX, TX
#define RS485Transmit HIGH
#define RS485Receive LOW
#define sSerialTxControl 2 //RS485 Direction control
void setup() {
Serial.begin(9600);
// RS485Serial.begin(19600); // SW Serial for RS-485 Coms
/******* Comment Out Next Line to Duplicate Problem ********/
pinMode(2, OUTPUT); //pins 5 and up work fine
//digitalWrite(sSerialTxControl, RS485Receive); // Set transceiver direction to Receive (LOW)
}
void loop() {
float sum = analogRead(A2);
float voltage, temperature;
Serial.println("Sum");
Serial.println(sum);
float millivolts = (sum / 1023.0) * 5000.0;
float celsius = (millivolts / 10.0 - 273.15); // error correction
float fahrenheit = celsius * 9.0 / 5.0 + 32.0;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" C");
delay(1000);
}
#define problemChild 2 // Change this to 5 and up and you get a different sum
void setup() {
Serial.begin(9600);
pinMode(problemChild, OUTPUT);
}
void loop() {
float sum = analogRead(A2);
Serial.println("Sum");
Serial.println(sum);
delay(1000);
}
A2 connected to center pin of LM335 which is also connected to + bus through a 2k resistor. Ground connected to ground side of LM335. I'll sketch that out if you like.
The issue seems to be anything that causes a small fluctuation in the supply voltage, and in my case maybe .03 volts, the ADC changes by maybe 2 degrees C. The voltage output of the LM335 stays the same with different loads on the supply voltage but the ADC in the Arduino Uno is affected negatively. The fluctuation in supply voltage in my case is caused by the RS-485 board.
I encountered this issue in my home automation system starting 30 some years ago and realized you needed a rock solid PWR supply to yield consistent readings. I'm considering redesigning that system and using Dallas sensors this time. The problem is I have a couple of LM335s that I can not get to that will need to be used in the new design. I'm just in the process of testing parts of that design for stability. The RS-485 bus is new to me and I'm still questioning stability. I like my automation hard-wired when possible and this is even a step away from that.
For those that need a schematic and why I boiled it down to a simple Uno was to simplify and yet yield the same problem since this may be beyond most to deal with.