So I am trying to use this thermistor to measure temperature and with this code below it always puts the same value (2147483647). I used this tutorial to do the wiring and coding. I don't think the wiring is the problem but think the problem is somewhere in my code or perhaps I am using a wrong type of thermistor? Am I missing something? Any help is greatly appreciated.
I am only using a 1k resistor in series with the thermistor but don't think that would be a problem, right?
Edit: I should have mentioned I'm using the adafruit huzzah esp8266 so there are a few pins.
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <Phant.h>
#include <ESP.h>
#define DHTPIN 2
#define DHTTYPE DHT22
#define THERMISTORPIN 4
DHT dht(DHTPIN, DHTTYPE);
const char* ssid = "xxxx";
const char* password = "yyyyyy";
const char* host = "data.sparkfun.com";
const String publickey = "uuuuuu";
const String privatekey = "ttttttt";
const byte NUM_FIELDS = 5;
const String fieldNames[NUM_FIELDS] = {"ghumidity", "gtemp", "light", "otemp", "wtemp"};
String fieldData[NUM_FIELDS];
//thermistor variables
const int thermresistor = 987; //value of resistor in series with thermistor
int thermtemp = 0;
uint8_t i;
uint8_t numsamples = 5;
uint8_t To = 25;
const int B = 3950;
void setup(){
Serial.begin(115200);
delay(10);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
fieldData[0] = 1; //humidity
fieldData[1] = 2; //garden temp
fieldData[2] = 3; //light
fieldData[3] = 4; //outside temp
fieldData[4] = 8; //water temp
//turnpumpon();
posttophant();
//turnpumpoff();
ESP.deepSleep(1200000000, WAKE_RF_DEFAULT);
}
void posttophant()
{
fieldData[0] = dht.readHumidity();
fieldData[1] = dht.readTemperature(true);
//read outside temp (otemp) data and convert to a temp
for (i=0; i<numsamples; i++){
thermtemp = analogRead(THERMISTORPIN);
thermtemp += thermtemp;
delay(10);
}
//take the sum of all the readings and divide by # of samples to get avg.
thermtemp = thermtemp / numsamples;
#voltage divider equation
thermtemp = thermresistor / (1023 / thermtemp - 1);
//Steinhart eqn.
thermtemp = 1 / (log(thermtemp / thermresistor) / B + (1 / (To + 273))) - 273;
fieldData[3] = String(thermtemp);
WiFiClient client;
const int httpPort = 80;
if (!client.connect (host, httpPort)){
return;
}
client.print("POST /input/");
client.print(publickey);
client.print("?private_key=");
client.print(privatekey);
for (int i=0; i<NUM_FIELDS; i++)
{
client.print("&");
client.print(fieldNames[i]);
client.print("=");
client.print(fieldData[i]);
}
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(host);
client.println("Connection: close");
client.println();
}

