Skip to content

Instantly share code, notes, and snippets.

@danielsotopino
Last active October 15, 2020 19:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielsotopino/f52c7f26b4cff12b1369d5935b9d1f01 to your computer and use it in GitHub Desktop.
Save danielsotopino/f52c7f26b4cff12b1369d5935b9d1f01 to your computer and use it in GitHub Desktop.
Arduino ESP8266 TMP36

# Hello

#include <ESP8266WiFi.h>

const char* ssid = ""; const char* password = ""; const int sensorPin = A0;

WiFiServer server(80);

void setup() {

Serial.begin(9600);

Serial.println(); Serial.print("Connecting to "); Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }

Serial.println(""); Serial.println("WiFi connected");

// Start the server server.begin(); Serial.println("Server started");

// Print the IP address Serial.print("Use this URL to connect: "); Serial.print("http://"); Serial.print(WiFi.localIP()); Serial.println("/");

}

void loop() { WiFiClient client = server.available(); if (!client) { return; }

// Read the first line of the request String request = client.readStringUntil('\r'); Serial.println(request); client.flush();

int sensorVal = analogRead(sensorPin); Serial.print("Sensor value: "); Serial.print(sensorVal);

float voltage = (sensorVal / 1024.0) * 3.3; Serial.print(", Volts: "); Serial.print(voltage); Serial.print(", degrees C: ");

float temperature = (voltage - .5) * 100;

Serial.println(temperature);

// Return the response client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); // do not forget this one client.println(""); client.println(""); client.print("degrees C: "); client.print(temperature); client.println(""); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment