I have an Arduino UNO WiFi REV2 with a TMP36 temperature sensor which I have configured to connect to the network, and send an email once the temperature has reached a certain temperature in our IT room. Am able to get on the network and its able to send an email when the temperature reaches what I have set the limit to be. The challenge is that the reading are never constant, I have tried to be in different environments and I keep getting a reading that is not constant. Below is my code and the reading
#include <WiFiNINA.h>
#include <LCDIC2.h>
#define sensorPin A0
char ssid[] = "*******";
char pass[] = "";
int status = WL_IDLE_STATUS;
int pinDHT11 = 2;
LCDIC2 lcd(0x27, 16, 2);
byte Degree[] = {
B00111,
B00101,
B00111,
B00000,
B00000,
B00000,
B00000,
B00000
};
char server[] = "******";
String postData;
String postVariable = "Temperature=";
WiFiClient client;
void setup() {
Serial.begin(9600);
//analogReference(EXTERNAL);
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
if (lcd.begin());
}
void loop() {
int reading = analogRead(sensorPin);
double voltage = reading * 0.004882814;
double temperatureC = (voltage - 0.5) * 100.0;
double temperatureF = (temperatureC * 1.8) + 32;
postData = postVariable + temperatureC;
if (temperatureC >= 30){
if (client.connect(server, 80)) {
client.println("POST /arduino/emailScript.php/ HTTP/1.1");
client.println("Host: *******");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(postData.length());
client.println();
client.print(postData);
Serial.println("Email Sent");
Serial.println(postData);
Serial.println(" C");
}
if (client.connected()) {
client.stop();
}
delay(60000);
}
Serial.println(postData);
lcd.print(postData);
lcd.print("C");
for (uint8_t i = 0; i < 15; i++) {
lcd.setCursor(i, 1);
delay(250);
}
for (uint8_t i = 0; i < 15; i--) {
lcd.setCursor(i, 1);
delay(250);
}
delay(3000);
lcd.clear();
}
and the output is as below;
sometimes even in negative
Put
Serial.println(reading);
After analogRead .
That will tell whether the problem is in your sensor/wiring or in your sketch...
Also, when comparing to float you should use >= 30.0
In IDE press ctrl-t. Your indentation does not match your curly braces.
TemperatureC is not a String. Can you concatenate a String and a double this way? Maybe you should first convert the double to a String...
Those analgRead values seem too low... can you send a schematic and a picture of your setup?
I presume you are not outside above 5000 m?
Or near the north or south pole...
...or in a fridge...
Hi,
Your code shows you have more than the 36 connected, can we have a COMPLETE schematic please?
Have you just got code that reads the 36 and NOTHING else, WITH NOTHING else connected?
If not, then please forget your current code for the moment and write some simple code to prove you are connected to the 36. Do this with all the other hardware disconnected as well.
This procedure should have been your first bit of code you wrote.
I have disconnected all hardware and I have used a new 36 not the one used before, below is the new diagram for your reference and the output (I have used the code from the page you gave me)