I have a circuit with preferably long wires that get data from thermistors. The Arduino sends this data (formatted in JSON) to a web server where it can be collected by another program. Some of these values appear correct, while others do not.
[
{
"dht11": {
"temperature": 73.4,
"humidity": 41,
"heat-index": 77.15
},
"thermistors": {
"therm1": {
"temp": 71.21,
"resistance": 12727.27
},
"therm2": {
"temp": 76.22,
"resistance": 12045.51
},
"therm3": {
"temp": nan,
"resistance": -19393.41
}
}
}
]
code:
#define THERMISTORPIN A0
#define THERMISTORNOMINAL 10000
#define TEMPERATURENOMINAL 25
#define NUMSAMPLES 25
#define BCOEFFICIENT 4050
#define SERIESRESISTOR 10000
#define THERMISTORPIN2 A5
#define THERMISTORPIN3 A3
#define DHTPIN 2
#define PHOTORESISTOR 3
#define DHTTYPE DHT11
int samples[NUMSAMPLES];
int samples_two[NUMSAMPLES];
int samples_three[NUMSAMPLES];
int stuckintime;
#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"
byte mac[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0xEE
};
IPAddress ip(192, 168, 1, 3);
EthernetServer server(80);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
dht.begin();
analogReference(EXTERNAL);
}
void loop() {
uint8_t i;
float average;
float average_two;
float average_three;
float stuckintime;
for (i = 0; i < NUMSAMPLES; i++) {
samples[i] = analogRead(THERMISTORPIN);
samples_two[i] = analogRead(THERMISTORPIN2);
samples_three[i] = analogRead(THERMISTORPIN3);
delay(10);
}
for (i = 0; i < NUMSAMPLES; i++) {
average += samples[i];
average_two += samples_two[i];
average_three += samples_three[i];
}
average /= NUMSAMPLES;
average = 1023 / average - 1;
average = SERIESRESISTOR / average;
float tempreading;
tempreading = average / 10975;
tempreading = log(tempreading);
tempreading /= BCOEFFICIENT;
tempreading += 1.0 / (TEMPERATURENOMINAL + 273.15);
tempreading = 1.0 / tempreading;
tempreading -= 273.15;
tempreading = tempreading * 9 / 5 + 32;
average_two /= NUMSAMPLES;
average_two = 1023 / average_two - 1;
average_two = SERIESRESISTOR / average_two;
average_two = average_two;
float tempreadtwo;
tempreadtwo = average_two / 11811;
tempreadtwo = log(tempreadtwo);
tempreadtwo /= BCOEFFICIENT;
tempreadtwo += 1.0 / (TEMPERATURENOMINAL + 273.15);
tempreadtwo = 1.0 / tempreadtwo;
tempreadtwo -= 273.15;
tempreadtwo = tempreadtwo * 9 / 5 + 32;
average_three /= NUMSAMPLES;
average_three = 1023 / average_three - 1;
average_three = SERIESRESISTOR / average_three;
float tempreadthree;
tempreadthree = average_three / THERMISTORNOMINAL;
tempreadthree = log(tempreadthree);
tempreadthree /= BCOEFFICIENT;
tempreadthree += 1.0 / (TEMPERATURENOMINAL + 273.15);
tempreadthree = 1.0 / tempreadthree;
tempreadthree -= 273.15;
tempreadthree = tempreadthree * 9 / 5 + 32;
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
float hif = dht.computeHeatIndex(f, h);
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connection: close");
client.println("Refresh: 0");
client.println("");
client.println("[");
client.println(" {");
client.println(" \"dht11\": {");
client.print(" \"temperature\": "); client.print(f); client.println(",");
client.print(" \"humidity\": "); client.print(h); client.println(",");
client.print(" \"heat-index\": "); client.print(hif); client.println("");
client.println(" },");
client.println(" \"thermistors\": {");
client.println(" \"under-bed\": {");
client.print(" \"temp\": "); client.print(tempreading); client.println(",");
client.print(" \"resistance\": "); client.print(average); client.println("");
client.println(" },");
client.println(" \"side-bed\": {");
client.print(" \"temp\": "); client.print(tempreadtwo); client.println(",");
client.print(" \"resistance\": "); client.print(average_two); client.println("");
client.println(" },");
client.println(" \"top-bed\": {");
client.print(" \"temp\": "); client.print(tempreadthree); client.println(",");
client.print(" \"resistance\": "); client.print(average_three); client.println("");
client.println(" }");
client.println(" }");
client.println(" }");
client.println("]");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
}
I have no idea what is causing this to happen - pushing RESET doesn't fix it at all, reconnecting wires does not fix it, any help?
(Please tell me what else to include if you need it.)