Ragazzi ho un problema, utilizzo il seguente codice per leggere la temperatura e scriverlo su una pagina web.
Uso arduino uno e arduino wifi-shield. Il mio problema è che la temperatura non è corretta, in quanto non conosco il tipo di termistore in mio possesso e come inserire i valori di quest'ultimo nello script. Posto una foto del termistore in allegato , spero qualcuno possa fornirmi delucidazioni.
include
#<SPI.h>
#include <WiFi.h>
#include <SD.h>
#define maxLength 25
#include <math.h>
int pin= A0;
double v;/*voltaggio tra 0 e 1023*/
double volt;/* voltaggio reale tra o e 5 volt*/
double Rt;/* resistenza del termistore*/
double R1=4600;/*resistenza in ohm che abbiamo messo noi*/
double temp;/* temperatura in Kelvin*/
double Temperatura;
char ssid[] = "Mac"; // your network SSID (name)
char pass[] = "Hac"; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
File htmlFile;
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
server.begin();
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println("SUCCESS - SD card initialized.");
// you're connected now, so print out the status:
printWifiStatus();
}
void loop()
{
v=analogRead(pin);/*leggiamo il valore della tensione ai capi di R1*/
volt=5*v/1023;/* riportiamo la tensine tra 0 e 5 volt con una proporzione*/
Rt=R1*(5/volt-1);/*resistenza del termistore*/
temp=1/(0.001319+(0.000234125*log(Rt))+(0.0000000876741*log(Rt)*log(Rt)*log(Rt)));/*calcolo la temperatura con la formula di Steinhart-Hart*/
Temperatura=temp-273.15;/* gradi Chelsius*/
Serial.println("temperatura");/*stampiamo sul monitor la temperatura*/
Serial.println(Temperatura);/*stampo il valore della teperatura*/
delay(1000);
char* file_to_load = "index.htm";
String inString = String(maxLength);
WiFiClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (inString.length() < maxLength) {
inString += c;
}
if (c == '\n' && currentLineIsBlank) {
if (inString.indexOf(".htm") > -1) {
String new_file_load;
int rootIndex = inString.indexOf("/");
new_file_load = inString.substring((rootIndex+1), (rootIndex+13));
int endIndex = new_file_load.indexOf(" ");
if (endIndex > -1) {
new_file_load = new_file_load.substring(0, endIndex);
}
if (new_file_load != "") {
new_file_load.toCharArray(file_to_load,12);
}
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html><head></head><body>");
client.println(Temperatura);
client.println("</body></html>");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
}
void read_file( char* page_html, WiFiClient client )
{
htmlFile = SD.open( page_html );
if (htmlFile) {
while (htmlFile.available()) {
client.write(htmlFile.read());
}
// close the file:
htmlFile.close();
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}