Home / Tutorials / ESP8266 Tutorial / Display Sensor Data to NodeMCU Web Server
NodeMCU Webserver

Display Sensor Data to NodeMCU Web Server

We setup a simple NodeMCU web server in our previous tutorial. There we controlled a LED from a web page hosted by the NodeMCU ESP8266 board! This time, we'll be displaying data from a sensor connected to the NodeMCU's analog pin.

In this tutorial, I'll be displaying data coming from a light dependent resistor (LDR) to our NodeMCU web server. You can use any sensor available to you as long as its output voltage is not more than the recommended maximum of 3.3 V.

The ESP8266 itself accepts only up to 1 V on its analog pin. Thankfully, the NodeMCU board has a built-in voltage divider.

The ESP8266 (which is the main chip on the NodeMCU) uses a 10-bit ADC. This means the input voltage from 0 to 3.3 V will be equivalent to 0 to 1024.

Materials Needed

Wiring Diagram

Here's our simple circuit for this tutorial:

nodemcu sensor

I used a trimmer together with the LDR for voltage division so that I can adjust the "sensitivity" of my sensor.

Code

Basically I used analogRead() to capture the voltage from the divider circuit setup by the trimmer and the LDR. The data is then embedded to the web server page.

Upload the code and open your browser to the address shown on the serial monitor (see previous tutorial for more on this).

 

 

Output

Here's what the web page should look like:

nodemcu server page

Try to cover the LDR and refresh the page. It should show a different value.

The disadvantage with this sketch is that you need to refresh the page to update the sensor values. With ajax, you can avoid refreshing the page manually.

That's it! Next up, we'll log our sensor data to a spreadsheet program like Google Sheets.

 

Check Also

nodemcu ajax dynamic sensor data

NodeMCU Ajax: Dynamic Sensor Data on Web Page

Last time we managed to display sensor data to a NodeMCU web server. The problem …

10 comments

  1. Can I show this to my won website ??

  2. my web page not loaded

  3. please give your libraries. my esp8266wifi library is not compleate

  4. c satish kumar

    hlo can u tell me how can i automatically refresh the webpge,without doing it mannually. to read the sensor data continously

  5. Thank you for the article.

    As continuation of this proyect would be really interesting show how to display in a website accesible everywhere

  6. Hi. Looking for a way to attach a DHT11 temperature/humidity sensor and 3 magnetic door switches. So i can see the temp/hum and if a door/window is open. could you please tell me how can i achieve that, please? Also how can i send the info to my server(in my LAN).

  7. how can i send data from my webpage to nodemcu

Leave a Reply

Your email address will not be published. Required fields are marked *