Arduino Uno Wifi Temperature Sensor

You can use an Arduino Uno WiFi board to create sensors that are web accessible. This project allows you to read the temperature through a web browser.

Note: I found that the 5V pin on my Arduino Uno WiFi only actually outputs 4.85V. This means the temperature readings are off by about 5 degrees. Make sure to verify your project is reading the correct temperature, and if not tweak the math as need be.

Functional Parts in the Project:

#include <SPI.h>
#include <WiFiNINA.h>

#define sensorPin A0

char ssid[] = "test";
char pass[] = "";
int keyIndex = 0;

int status = WL_IDLE_STATUS;
WiFiServer server(80);

void setup() {
  Serial.begin(9600);

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(10000);
  }
  server.begin();

  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
}

void loop() {

  int reading = analogRead(sensorPin);
  float voltage = reading * 5.0;
  voltage /= 1024.0;
  float temperatureC = (voltage - 0.5) * 100 ;
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;

  WiFiClient client = server.available();   
  if (client) {                             
    Serial.println("new client");           
    String currentLine = "";                
    while (client.connected()) {            
      if (client.available()) {             
        char c = client.read();             
        Serial.write(c);                    
        if (c == '\n') {                    

          if (currentLine.length() == 0) {

            client.print("Temperature: ");
            client.println(temperatureF);

            break;
          } else {
            currentLine = "";
          }
        } else if (c != '\r') {
          currentLine += c;
        }
      }
    }

    client.stop();
    Serial.println("client disonnected");
  }
}

Be the first to comment

Leave a Reply