Send Sensor Data (DHT11 & BMP180) to ThingSpeak With an Arduino, Using Cable or WiFi (ESP8266) or Use ESP8266 Alone (UPDATED AUGUST 2016)





Introduction: Send Sensor Data (DHT11 & BMP180) to ThingSpeak With an Arduino, Using Cable or WiFi (ESP8266) or Use ESP8266 Alone (UPDATED AUGUST 2016)

About: I am a physician by trade. After a career in the pharmeceutical world I decided to take it a bit slower and do things I like. Other than my hobbies that involves grassroots medicine in S.E.&P Asia. I have bu...

I wrote this instructable because Thingspeak -nevermind how easy to set up- has a few hurdles that I ran into and that, judging from reactions, other people are struggling with as well.

This instructable discusses the following:

  • How to set up Thingspeak
  • How to connect your Arduino with a W5100 Ethernetshield
  • How to connect your Arduino via an ESP8266-01
  • How to connect to Thingspeak with only an ESP8266-01

NOTE: Although this presented project does work well, I would probably never combine an Arduino with an ESP8266 again because it is overkill. The ESP8266 can do a lot of things the Arduino can do, especially if it is just collecting sensor data. Have look in the 'ESP8266 only' step of this instructable, or check my newer instructables such as the one here.

Things you need:
WS5100 EthernetShield (if you have the old ENC28J60 ethercard, look here)
Thingspeak Account
Sensors (such as DHT11 and BMP180)
Internet connection
For the WiFi:
ESP8266-01 (or other ESP8266)

I wanted to collect some weather-data with my Arduino and have that available as nice graphs, on a webpage, so I could also monitor it from afar
I could ofcourse just use an Arduino as a webserver, but if you want to do anything more than send numbers to a webpage, The Arduino will soon run out of memory.
There are services that can digest and publish your data: Pachube, later called Xively is a known one but currently they have a waiting list for their free accounts. Truthfully, I have a Pachube account that became a Xively account, but just never got any results on it.

There're few alternatives for Xively:

I picked 'Thingspeak'
As the signup and creating a channel etcetera is quite easy and well explained I will not go into too much detail of that. Basically after you sign up you create a channel to which you add fields where later sensors will send their data.
Under the API tab you will find an API that you later should put in your program.

I describe a simpel connection with an ethernet cable and a connection via WiFi

Step 1: Hurdles and Solutions

Hurdle 1
Now where to find a program? a working example would be nice right? In the right top corner there is a button 'Support' that will go to 'Tutorials'.
Under 'Tutorials' you will find:

"Using an Arduino + Ethernet Shield to Update a ThingSpeak Channel"
Sounds great, so you download that program into your IDE, add the API -key and then compile it.
Darn.... it doesnt compile, you try to fix it (and that is certainly possible) until you come to a point you have no idea what is required.
Apparently the program still expects everybody to use the 022 or 023 IDE.
There is a link to a Github page but that will give u a program to tweet and that is not what you want, at least not for now.
You ill find a better program to start from right here:

That program takes a reading from the A0 port and sends that to "Field1" in your datastream

Ok so you try that, you hang a variable resistor like an LDR or NTC on port A0, add your API in the program and run it.
That works fine, but I didnt only want to read a value from an Analog port, I had a DHT11 Moisture&Temperature sensor as well as a BMP180 Pressure & temperature sensor. I figured it shouldnt be too hard.

Hurdle 2
I added the necessary libraries to the Thingspeak program, added the objects and read the sensors into a variable.
The sensors however have floats as outcome and Thingspeak wants you to send strings.
With most variables it is rather easy to turn them into a string with the simple 'string' function, but it isnt that easy for floats. With floats you have to use the "dtostrf" command (which I guess stands for 'double-to-string-function'

Trying to find info on that function on internet quickly led me to endless discussions on 'how stupid' it was and people asking questions were often told "why would you need that, Serial.print will do that for you" Yeah, true, but I don't want to print, I need it because Thingspeak wants it.

To use the dtostrf command you need to set up a buffer space where the string will be stored. It works like this:

char t_buffer[10];
String temp=dtostrf(t,0,5,t_buffer);

That bufferspace is important. I had it working with '7' or even '5', but when I added a second sensor that needs this function, my datastream would crash and or I got the weirdest results. I also figured that I could use the same bufferspace alternating for each sensor, but that also didnt really work, so now i have a bufferspace for each sensor.
Now I am no crack in C, so maybe there is a better way to do this, if so i would love to hear it, but this worked for me.

Once I had the string conversions, I could add the data to the datastream.
The Thingspeak example program shows that for one field only, but it becomes clear pretty fast that you have to add the strings and throw in the right amount of plussesand ampersands.

So for say 4 different fields it becomes like this:


Step 2: Connecting With Ethernetshield

Below you will find the full code.
Just a few remarks:
The BMP180 is an updated version of the BMP085. The BMP085 libraries are compatible with the BMP180.
AdaFruit has 2 versions of the libray. I picked version 1 as i found it easier to work with. Version 2 also requires installation of the 'Sensor' library.
In the code I also present an extra float: 'm'. that gives the Pressure in "mmHg" as I havent used it for now there is no string conversion yet and it is not added to the datastream, but adding it should now be as simple as 1+1

Arduino --> ThingSpeak Channel via Ethernet
The ThingSpeak Client sketch is designed for the Arduino and Ethernet.
This sketch updates a channel feed with an analog input reading via the
ThingSpeak API (
using HTTP POST. The Arduino uses DHCP and DNS for a simpler network setup.
The sketch also includes a Watchdog / Reset function to make sure the
Arduino stays connected and/or regains connectivity after a network outage.
Use the Serial Monitor on the Arduino IDE to see verbose network feedback
and ThingSpeak connectivity status.
Getting Started with ThingSpeak:
* Sign Up for New User Account - <a href="" rel="nofollow">
* Enter a MAC Address in this sketch under "Local Network Settings"
* Create a new Channel by selecting Channels and then Create New Channel
* Enter the Write API Key in this sketch under "ThingSpeak Settings"
Arduino Requirements:
* Arduino with Ethernet Shield or Arduino Ethernet
* Arduino 1.0 IDE
Network Requirements:
* Ethernet port on Router
* DHCP enabled on Router
* Unique MAC Address for Arduino
Created: October 17, 2011 by Hans Scharler (
Additional Credits:
Example sketches from Arduino team, Ethernet by Adrian McEwen
Added dht11/BMP180 showed dtostrf function by diy_bloke 22/11/2014
#include <SPI.h>
#include <Ethernet.h>
#include <dht11.h>
#include <Wire.h>
#include <Adafruit_BMP085.h> // This is the version 1 library
#define DHT11PIN 4  // The Temperature/Humidity sensor
Adafruit_BMP085 bmp;
dht11 DHT11;

// Local Network Settings
byte mac[] = { 0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; // Must be unique on local network
// ThingSpeak Settings
char thingSpeakAddress[] = "";
const int updateThingSpeakInterval = 16 * 1000; // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)
// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;
// Initialize Arduino Ethernet Client
EthernetClient client;
void setup()
// Start Serial for debugging on the Serial Monitor
// Start Ethernet on Arduino
void loop()
// Read value from Analog Input Pin 0
String analogPin0 = String(analogRead(A0), DEC);
// Print Update Response to Serial Monitor
if (client.available())
char c =;
int chk =;
char t_buffer[10];
char h_buffer[10];
float t=(DHT11.temperature);
String temp=dtostrf(t,0,5,t_buffer);
//Serial.print(" ");
float h=(DHT11.humidity);
String humid=dtostrf(h,0,5,h_buffer);

            float p=(bmp.readPressure()/100.0);//this is for pressure in hectoPascal
            float m=(bmp.readPressure()/133.3);//  this is for pressure in mmHG
            float t2=(bmp.readTemperature());
            char p_buffer[15];
            char t2_buffer[10];
            String pres=dtostrf(p,0,5,p_buffer);
            String temp2=dtostrf(t2,0,5,t2_buffer);
 //         }

// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)
// Update ThingSpeak
if(!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval))
// Check if Arduino Ethernet needs to be restarted
if (failedCounter > 3 ) {startEthernet();}
lastConnected = client.connected();
void updateThingSpeak(String tsData)
if (client.connect(thingSpeakAddress, 80))
client.print("POST /update HTTP/1.1\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
lastConnectionTime = millis();
if (client.connected())
Serial.println("Connecting to ThingSpeak...");
failedCounter = 0;
Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
lastConnectionTime = millis();
void startEthernet()
Serial.println("Connecting Arduino to network...");
// Connect to network amd obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0)
Serial.println("DHCP Failed, reset Arduino to try again");
Serial.println("Arduino connected to network using DHCP");

Step 3: Connect to Thingspeak Using an ESP8266 WiFi Module

The previous presented internet connection was made via a cable. However, there is a cheap WiFi module that is available to attach to the Arduino: The ESP 8266.
The ESP8266 is a cheap WiFi module. Bear in mind that it needs 3.3 Volt. Some models however claim to be 5 Volt tolerant. I added 2 circuits that could be used as voltage converter.
The ESP8266 really needs its own 3.3 V source as the current coming from the Arduino just doesnt cut it.
There is plenty of information on how to connect the module, I want to focus on the software to make a Thingspeak connection
The SoftSerial library is added for debugging. it is not really necessary once the progrem is working. The same goes for all the print statements to the Software serial port
I use 3 analog values rather than an example with the BMP108 and DHT11 as that requires libraries, so the implementation of theESP8266 is easier to follow. Once you get that, it is easy to implement other sensors. Just make sure you turn all output into a string
Below a program to Connect 3 analog sensors to Thingspeak via an ESP8266 module:

// <a href="" rel="nofollow">

#include <SoftwareSerial.h>
int sensor_temp = A0;
int value_temp;
int sensor_light = A1;
int value_light;
int sensor_humid = A2;
int value_humid;

#define DEBUG FALSE //comment out to remove debug msgs

//*-- Hardware Serial
#define _baudrate 9600

//*-- Software Serial
#define _rxpin      2
#define _txpin      3
SoftwareSerial debug( _rxpin, _txpin ); // RX, TX

//*-- IoT Information
#define SSID "[YOURSSID]"
#define IP "" // ThingSpeak IP Address:

// GET /update?key=[THINGSPEAK_KEY]&field1=[data 1]&field2=[data 2]...;
String GET = "GET /update?key=[ThingSpeak_(Write)API_KEY]";

void setup() {
   Serial.begin( _baudrate );
  debug.begin( _baudrate );

    debug.println("RECEIVED: OK\nData ready to sent!");


void loop() {
  value_temp = analogRead(sensor_temp);
  value_light = analogRead(sensor_light);
  value_humid = analogRead(sensor_humid);
  String temp =String(value_temp);// turn integer to string
  String light= String(value_light);// turn integer to string
  String humid=String(value_humid);// turn integer to string
  updateTS(temp,light, humid);
  delay(3000); //
//----- update the  Thingspeak string with 3 values
void updateTS( String T, String L , String H)
  // ESP8266 Client
  String cmd = "AT+CIPSTART=\"TCP\",\"";// Setup TCP connection
  cmd += IP;
  cmd += "\",80";
  if( Serial.find( "Error" ) )
    debug.print( "RECEIVED: Error\nExit1" );

  cmd = GET + "&field1=" + T +"&field2="+ L + "&field3=" + H +"\r\n";
  Serial.print( "AT+CIPSEND=" );
  Serial.println( cmd.length() );
  if(Serial.find( ">" ) )
    sendDebug( "AT+CIPCLOSE" );//close TCP connection
  if( Serial.find("OK") )
    debug.println( "RECEIVED: OK" );
    debug.println( "RECEIVED: Error\nExit2" );

void sendDebug(String cmd)
  debug.print("SEND: ");

boolean connectWiFi()
  Serial.println("AT+CWMODE=1");//WiFi STA mode - if '3' it is both client and AP
  //Connect to Router with AT+CWJAP="SSID","Password";
  // Check if connected with AT+CWJAP?
  String cmd="AT+CWJAP=\""; // Join accespoint
    debug.println("RECEIVED: OK");
    return true;
    debug.println("RECEIVED: Error");
    return false;

  cmd = "AT+CIPMUX=0";// Set Single connection
  sendDebug( cmd );
  if( Serial.find( "Error") )
    debug.print( "RECEIVED: Error" );
    return false;


In the latest version of the ESP8266 firmware AT+CIOBAUD is no longer supported and returns ERROR.
The replacement command is AT+IPR. See here for further details :-

More note
Apparently lately there appear to be some people experiencing difficulties because they didnt connect the ESP8266 to the hardware serial but to the software serial.
This program expects an ESP connected to hardware serial

Step 4: Using Just the ESP8266

if you come upon this page and see gibberish... there was a full step here, but somehow Instructables decided it would be better to replace it with gibberish...after i already saved it. I will give it another go In the previous step I used an ESP8266 to send the sensorvalues that were read by an Arduino to Thingspeak. However, it is also possible to do it without an Arduino at all. I connected a DHT11 to pin 2 of my ESP8266-01 and used the following program. I can't take full credit for the program, I think the original is from Jeroen Beemster

#include <DHT.h> //  DHT.h library
#include <ESP8266WiFi.h> // ESP8266WiFi.h library

#define DHTPIN 2
#define DHTTYPE  DHT11

const char* ssid     = "YourNetworkSSID";
const char* password = "YourPassword";
const char* host = "";
const char* writeAPIKey = "YourWriteAPI";


void setup() {
  // Initialize sensor

//  Connect to WiFi network
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {

void loop() {
 float humidity = dht.readHumidity();
 float temperature = dht.readTemperature();

  if (isnan(humidity) || isnan(temperature)) {

// make TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {

  String url = "/update?key=";
  // Request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");

It is not the goal of this instructable to explain how to program the ESP8266, there are plenty of sources for that. A good one is here. If you already have an USB-TTL module at 3.3 Volt, you dont need to worry about voltages. If you only have a 5Volt USB-TTL module you still can use it but have to use a voltage divider between the Tx of the module and the Rx of the ESP8266. Never ever put 5 volt on the ESP8266

Note: The DHT library from Adafruit contains an error that usually doesnt occur when using an Arduino, but can become apparent when using an ESP8266, especially if the program is a bit bigger. See the enclosed picture for changes you need to make in the cpp file. It basically is commenting out two lines

Step 5: A Bonus

In case you do not want to use Thingspeak but just want your own webserver: use this program:

 * DHT11 Sensor connected to Pin 2
 <a href="" rel="nofollow">>
 Based on code by David A. Mellis & Tom Igoe
Adapted by diy_bloke
 * bmp180sensor on a4/a5

/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <Ethernet.h>
#include <dht11.h>
#include <Wire.h>
//#include <Adafruit_Sensor.h>
//#include <Adafruit_BMP085_U.h>
#include <Adafruit_BMP085.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define DHT11PIN 2  // The Temperature/Humidity sensor

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

/*-----( Declare objects )-----*/
IPAddress ip(192,168,1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

//Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
Adafruit_BMP085 bmp;
dht11 DHT11;  //The Sensor Object
/*-----( Declare Variables )-----*/

void setup()   /****** SETUP: RUNS ONCE ******/
  // Open serial communications and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  Serial.print(F("server is at "));
}//--(end setup )---

void loop()   /*----( LOOP: RUNS OVER AND OVER AGAIN )----*/
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println(F("new client"));
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c =;
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connnection: close");
          client.println("<!DOCTYPE HTML>");
          // add a meta refresh tag, so the browser pulls again every 5 seconds:
          client.println("<meta http-equiv=\"refresh\" content=\"5\">");
          client.println(F("My Home Environment"));
          client.print(F("<h3>My Home Environment</h3>"));
          //client.println("<br />");

          /*----(Get sensor reading, calculate and print results )-----------------*/

          int chk =;

          Serial.print(F("Read sensor: "));
          switch (chk)
          case 0:
          case -1:
            Serial.println(F("Checksum error"));
          case -2:
            Serial.println(F("Time out error"));
            Serial.println(F("Unknown error"));
          /* Get a new sensor (BMP085) event */
          // sensors_event_t event;
          // bmp.getEvent(&event);
          client.print(F("<table style='border:1px solid black; background-color: white;'>"));
          client.print("<font color='red'>Temperature</font> (°C): ");
          client.print(F("</td><td align='right'>"));
          client.println((float)DHT11.temperature, 1);
          client.println(F("<br />"));
          client.print("<b>Temperature</b> (°F): ");
          client.print(F("</td><td align='right'>"));
          client.println(Fahrenheit(DHT11.temperature), 1);
          client.println("<br />");
          client.print("<font color='blue'>Humidity</font> (%): ");
          client.print(F("</td><td align='right'>"));
          client.println((float)DHT11.humidity, 0);
          client.println("<br />");
          client.print("<b>Temperature</b> (°K): ");
           client.println(Kelvin(DHT11.temperature), 1);
           client.println("<br />");
          client.print("<i>Dew Point</i> (°C): ");
          client.print(F("</td><td align='right'>"));
          client.println(dewPoint(DHT11.temperature, DHT11.humidity));
          client.println("<br />");
          client.print("<i>Dew PointFast</i> (°C): ");
          client.print(F("</td><td align='right'>"));
          client.println(dewPointFast(DHT11.temperature, DHT11.humidity));
          client.println("<br />");

          if (!bmp.begin()) {
            client.print("geen sensor");
            client.print("Pressure (hPa): ");
            client.print(F("</td><td align='right'>"));
            client.print("Pressure (mmHg): ");
            client.print(F("</td><td align='right'>"));
            client.println("Temperature (°C): ");
            client.print(F("</td><td align='right'>"));
            client.println("<br />");
          /* Display the results (barometric pressure is measure in hPa) */

          /* Display atmospheric pressure in hPa */
          /*    client.print("Pressure: ");
           client.println(" hPa");
           client.println("<br />");

          /*--------( End Sensor Read )--------------------------------*/
        if (c== '\n'){
          // you're starting a new line
          currentLineIsBlank = true;
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data
    // close the connection:
    Serial.println(F("client disonnected"));
} // END Loop

/*-----( Declare User-written Functions )-----*/
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
  return 1.8 * celsius + 32;

//Celsius to Kelvin conversion
double Kelvin(double celsius)
  return celsius + 273.15;

// dewPoint function NOAA
// reference: <a href="" rel="nofollow">>
double dewPoint(double celsius, double humidity)
  double A0= 373.15/(273.15 + celsius);
  double SUM = -7.90298 * (A0-1);
  SUM += 5.02808 * log10(A0);
  SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
  SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
  SUM += log10(1013.246);
  double VP = pow(10, SUM-3) * humidity;
  double T = log(VP/0.61078);   // temp var
  return (241.88 * T) / (17.558-T);

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: <a href="" rel="nofollow">>
double dewPointFast(double celsius, double humidity)
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity/100);
  double Td = (b * temp) / (a - temp);
  return Td;
/* ( THE END ) */

7 People Made This Project!


  • Clocks Contest

    Clocks Contest
  • Water Contest

    Water Contest
  • Oil Contest

    Oil Contest

210 Discussions

Hi, re the ethernet code compilation error: the cause is the absence of the DHT11 and BMP085 modules. Is it possible to write code for a simple analog input to be read and transmitted? Thanks!

8 replies

yes, that is very well possible, take out the DHT11 and BMP code and do an analogread.

I must say though that I have no idea what platform you are using now. An Arduino with ethernetshield? Or just a nodeMCU?

I would use here an Arduino Uno with ethernet shield. How can a NodeMCU be used with ethernet?

a NodeMCU board connects via WiFi

ok, but that is in step 3 (with wifi). I was refering to step 2: Arduino with ethernet shield.

I am not referring to any step, just saying the NodeMCU connecs through wifi,not through ethernet, if you also want to connect the NodeMCU through ethernet -though i do not dee the point of that- you need to connect e.g. a wiz5100 module

For this trial I loaded the wifi code in an Arduino Uno. Now I just have to figure out the sketch for use with analog inputs instead of the sensor modules. Will take some time but I will report back.

I have a code for analog inpiuts in one of the steps

I found that now in step 3; compiles perfect. Just need to test with Thingspeak now.

I read you would now program ESP8266 for all this instead of combining with Arduino. Can you give some url's where I can find more beginners' info on that please?

Hi, I notice you set the hardware serial baudrate to 9600baud. But the ESP8266 does by default communicate with 11520baud. Now do you get it to work at 9600baud?

6 replies

just set it at 9600 Bd in the IDE
But I am getting confused, you just wrote that you are using a UNO with ethernet shield

well, you have 2 programs, one that runs with Uno and Ethernet shield. And the other with Uno and ESP8266: that is what I am referring to here; the ESP8266 is by default set to communicate at 115200 baud (if you use a fairly recent firmware version).

Just one further remark Erik, I already said I think that I do not use the ESP8266 anymore just to connect an arduino via WiFi. At the time of the ESP8266-01 when there was hardly a core available, that seemed the best thing to do, but the ESP8266 has been developed further. Anyway, you know that and there might be many reasons why you still want to do it.
yet, i have never been fond of the AT commands, and the soft serial solution another way to do it is if you want to use an Arduino and still have WiFi is to connect them with I2C. You can just let the Arduino do its thing and put values in a register and the ESP82666 can just pick them up and send them over WiFi.
You could choose either one as slave or as master, depending on your configuration and needs.

Hi, to me thisis just for learning purposes, later I will use the applications as you refer to.

I did not even know you can connect ESP8266 over I2C. Interesting!

ah ok. In that case you cant set the baudrate via de IDE. When I made this the default was 9600 I think. It is something you have to set with the AT commands, but if your ESP is 115200 it might be handier to just set it in the program as 115200

Can the wireless sketch be used with a Node MCU 1.0 development board? I get a compiler error stating 'A1' was not declared in this scope.

2 replies

Not sure which 'wireless' sketch you refer to. You mean the one in Step3?

Step 3 is about an Arduino connected to an ESP8266-01 module, wher would you want to use the nodeMCU? to replace the Arduino? That would be extremely odd. or to replace the 8266-01? that would be total overkill.
Or just to replace both? The code is totally unsuitable for that as it is about the AT driven communication between the 2 modules.
Note that this is a relatively old instructable and now I wouldnt dream of using an arduino in combo with an ESP, I would just use an ESP8266 as stand alone.

The reason that A1 is not declared in this scope is because the NodeMCU does not have an A1, it only has one analogport A0

Hi, thank you for your reply. I had wrongly loaded the wifi sketch into the ESP module. I know better now.

Loading the ethernet code in an Arduino Uno gives a general compiler error: exit status 1: what do I do wrong?