Earn Maker Points on Every Order! Learn More!

Upload Sensor Data to ThingSpeak using NodeMCU

Back to Blog
Upload Sensor Data to ThingSpeak using NodeMCU - Upload Sensor Data to ThingSpeak using NodeMCU - Upload Sensor Data to ThingSpeak using NodeMCU - Upload Sensor Data to ThingSpeak using NodeMCU

Upload Sensor Data to ThingSpeak using NodeMCU

ThingSpeak is an Open-Source IoT application and API to store and retrieve data from Hardware devices and Sensors. It uses HTTP Protocol over the Internet or LAN for its communication. The MATLAB analytics is included to analyze and visualize the data received from your Hardware or Sensor Devices.

We can create channels for each and every sensor data. These channels can be set as private channels or you can share the data publically through Public channels. The commercial features include additional features. But we will be using the free version as we doing it for educational purpose.

You can make projects like Weather Station, Tide Prediction, Counter and Many More.

Features:

  • Collect data in private channels.
  • Share Data with Public Channels
  • REST API and MQTT APIS
  • MATLAB® Analytics and Visualizations.
  • Worldwide Community

In this tutorial, we will be using an LDR to plot its light Intensity level on ThingSpeak using NodeMCU. We will program the NodeMCU to read and store the LDR data into a variable and then upload it to ThingSpeak using its channel name and API key. The NodeMCU should be connected to the internet via Wi-Fi. We will see how to create ThingSpeak Channels and configure it on NodeMCU.

Hardware Required:

  • NodeMCU
  • LDR Module
  • 10K Ohm Resistor
  • Jumper Wires
  • Breadboard (Optional)

Circuit Diagram:

NodeMCU LDR_bb

 

Once the hardware is set up, We can go ahead and create our ThingSpeak Channel.

Step 1: Go to https://thingspeak.com/ and create your ThingSpeak Account if you don’t have. Login to Your Account.

Step 2: Create a Channel by clicking ’New Channel’.

1.Sign In

Step 3: Enter the channel details.

Name: Any Name

Description: Optional

Field 1: Light Intensity LDR – This will be displayed on the analytics graph. If you need more than 1 Channels you can create for additional Sensor Data.

Save this setting.

3.Channel Details

Step 4: Now you can see the channels. Click on the ‘API Keys’ tab. Here you will get the Channel ID and API Keys. Note this down.

4.Channel ID API Key

Step 5: Open Arduino IDE and Install the ThingSpeak Library. To do this go to Sketch>Include Library>Manage Libraries. Search for ThingSpeak and install the library.

5.Install Thingspeak Library

Step 6: Now we need to modify the program with your credentials.

In the below code you need to change your Network SSID, Password and your ThingSpeak Channel and API Keys.

Replace the following content in the code,

Your SSID Here’ – Your Wi-Fi Name

Your Password Here’ – Your Wi-Fi Password

YYYYYY’ – Your ThingSpeak Channel Number (without Quotes)

XXXXXXXXXXX’ – Your Thing Speak API Key.

 

Code:

#include <ESP8266WiFi.h>;

#include <WiFiClient.h>;

#include <ThingSpeak.h>;

const char* ssid = "Your SSID Here"; //Your Network SSID

const char* password = "Your Password Here"; //Your Network Password

int val;

int LDRpin = A0; //LDR Pin Connected at A0 Pin



WiFiClient client;

unsigned long myChannelNumber = YYYYYY; //Your Channel Number (Without Brackets)

const char * myWriteAPIKey = "XXXXXXXXXXXXXXX"; //Your Write API Key

void setup()

{

Serial.begin(9600);

delay(10);

// Connect to WiFi network

WiFi.begin(ssid, password);



ThingSpeak.begin(client);

}



void loop()

{

val = analogRead(LDRpin); //Read Analog values and Store in val variable

Serial.print(val); //Print on Serial Monitor

delay(1000);

ThingSpeak.writeField(myChannelNumber, 1,val, myWriteAPIKey); //Update in ThingSpeak



delay(100);

}

Upload the code. Once it is connected to Wi-Fi the data will start uploading to the ThingSpeak Channel. You can now open your Channel and see the data changes plotted on the ThingSpeak.

6.Channel Output

Share this post

Comments (116)

  • Simon

    Hi Sharath
    I have an automated greenhouse setup that runs on MQTT and node red on,I would like to change to Thingspeak but can’t fathom how to alter the script, could you take a look and let me know what I need to remove and add
    Thanks

    #include
    #include
    #include
    #include

    // Uncomment one of the lines bellow for whatever DHT sensor type you’re using!
    #define DHTTYPE DHT22 // DHT 22

    // Change the credentials below, so your ESP8266 connects to your router
    const char* ssid = “xxxxxxxx”;
    const char* password = “xxxxxxxxx”;

    // Change the variable to your Raspberry Pi IP address, so it connects to your MQTT broker
    const char* mqtt_server = “192.168.1.68”;

    // Initializes the espClient. You should change the espClient name if you have multiple ESPs running in your home automation system
    WiFiClient espClient;
    PubSubClient client(espClient);

    #define DHTTYPE DHT22
    #define DHTPIN D8
    #define DHTVCC D2
    #define soilMoisterPin A0
    #define soilMoisterVcc D6
    #define ptrVcc D5
    #define relay_pump D4
    #define relay_leds D7
    #define relay_heat D3
    #define relay_fan D0
    // Initialize DHT sensor.
    DHT dht(DHTPIN, DHTTYPE);

    //Define variables
    float hum = 0;
    float temp = 0;
    int soilMoister = 0;
    int lum = 0;
    int soilPourcents = 0;
    long lastRecu = 0;

    //define treshold for variables
    //tresholds in % now
    int seuil_lum = 60;
    int seuil_moisture = 40;
    int seuil_temp = 17;
    int seuil_tempmax = 26;
    int seuil_hum = 70;
    int time_pump_ON = 2000;
    bool leds_ON = false;
    //Flag master if command received => the actuators won’t be triggered while flag_master == 1
    int Flag_master_LED = 0;

    //declaration of the timer
    SimpleTimer timer;

    //Delcaration of prototypes
    void getData();

    //This functions connects your ESP8266 to your router, you should avoid customizing it as it might be a bit tricky sometimes.
    void setup_wifi() {
    delay(10);

    // We start by connecting to a WiFi network
    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.print(“WiFi connected – ESP IP address: “);
    Serial.println(WiFi.localIP());
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    // This functions is executed when some device publishes a message to a topic that your ESP8266 is subscribed to
    // Change the function below to add logic to your program, so when a device publishes a message to a topic that
    // your ESP8266 is subscribed you can actually do something
    void callback(String topic, byte* message, unsigned int length) {

    Serial.print(“Message arrived on topic: “);
    Serial.print(topic);
    Serial.print(“. Message: “);
    String messageTemp;

    for (int i = 0; i < length; i++) {
    Serial.print((char)message[i]);
    messageTemp += (char)message[i];
    }
    Serial.println();

    // Feel free to add more if statements to control more GPIOs with MQTT

    // If a message is received on the topic Garden/Lights, you check if the message is either on or off. Turns the lamp GPIO according to the message
    if (topic == "Garden/Lights")
    {
    Serial.print(" Switching Leds ");
    if (messageTemp == "true") {
    Flag_master_LED = 1;
    digitalWrite(relay_leds, LOW);
    Serial.print("On");
    }
    else if (messageTemp == "false") {
    Flag_master_LED = 0;
    digitalWrite(relay_leds, HIGH);
    Serial.print("Off");
    }

    }
    else if (topic == "Garden/Water")
    {
    Serial.print(" Switching water pump ");
    if (messageTemp == "true") {
    digitalWrite(relay_pump, LOW);
    Serial.print("On");
    }
    else if (messageTemp == "false") {
    digitalWrite(relay_pump, HIGH);
    Serial.print("Off");
    }
    }

    Serial.println();
    }

    // This functions reconnects your ESP8266 to your MQTT broker
    // Change the function below if you want to subscribe to more topics with your ESP8266
    void reconnect()
    {
    // Loop until we're reconnected
    while (!client.connected()) {
    Serial.print("Attempting MQTT connection…");
    // Attempt to connect
    if (client.connect("ESP8266Client")) {
    Serial.println("connected");
    // Subscribe or resubscribe to a topic
    // You can subscribe to more topics (to control more LEDs in this example)
    client.subscribe("Garden/Lights");
    client.subscribe("Garden/Water");
    } else {
    Serial.print("failed, rc=");
    Serial.print(client.state());
    Serial.println(" try again in 5 seconds");
    // Wait 5 seconds before retrying
    delay(5000);
    }
    }
    }

    // The setup function sets your nodeMCU GPIOs to Outputs, starts the serial communication at a baud rate of 115200
    // Sets your mqtt broker and sets the callback function
    void setup() {
    Serial.println("start setup \n");
    //Soil moisture
    pinMode(soilMoisterVcc, OUTPUT);
    digitalWrite(soilMoisterVcc, LOW);
    //DHT
    pinMode(DHTVCC, OUTPUT);
    digitalWrite(DHTVCC, HIGH);
    pinMode(DHTPIN, INPUT);
    //LDR
    pinMode(ptrVcc, OUTPUT);
    digitalWrite(ptrVcc, LOW);
    //Relays
    pinMode(relay_pump, OUTPUT);
    pinMode(relay_leds, OUTPUT);
    pinMode(relay_heat, OUTPUT);
    pinMode(relay_fan, OUTPUT);

    digitalWrite(relay_pump, HIGH);
    digitalWrite(relay_leds, HIGH);
    digitalWrite(relay_heat, HIGH);
    digitalWrite(relay_fan, HIGH);

    dht.begin();
    //timer.setInterval(60000L,getData);

    Serial.begin(115200);
    setup_wifi();
    // Set the callback function, the server IP and port to communicate with
    client.setServer(mqtt_server, 1883);
    client.setCallback(callback);
    client.subscribe("Garden/Lights");
    client.subscribe("Garden/Water");
    delay(2000);

    //Issues between timer and the mqtt broker connection so we remove the timer, i'll work on it asap

    Serial.println("End setup \n");

    }
    void getDhtData(void)
    {
    //digitalWrite (DHTVCC,HIGH);
    delay(500);
    float tempIni = temp;
    float humIni = hum;
    temp = dht.readTemperature();
    hum = dht.readHumidity();
    if (isnan(hum) || isnan(temp)) // Check if any reads failed and exit early (to try again).
    {
    Serial.println("Failed to read from DHT sensor!");
    temp = tempIni;
    hum = humIni;
    return;
    }
    //Serial prints for debugging, you can remove the Serials if you want a cleaner code but i let it like this so you can adapt your code and see what's happenning in Real time
    Serial.println("Temperature :");
    Serial.println(temp);
    Serial.println("Humidity :");
    Serial.println(hum);

    // To send data via MQTT we need to compute our datas into a table of char
    float hic = dht.computeHeatIndex(temp, hum, false);
    static char temperatureTemp[7];
    dtostrf(hic, 6, 2, temperatureTemp);

    static char humidityTemp[7];
    dtostrf(hum, 6, 2, humidityTemp);
    // we finaly publish in the topic our values, it'll be read by the MQTT broker and sent to the dashboard in our case
    client.publish("Garden/Temperature", temperatureTemp);
    client.publish("Garden/Humidity", humidityTemp);

    }
    // For this project, you don't need to change anything in the loop function. Basically it ensures that you ESP is connected to your broker
    void loop()
    {
    if (!client.connected()) {
    reconnect();
    }
    if (!client.loop())
    client.connect("ESP8266Client");
    long now = millis();
    getData();
    delay(5000);
    client.loop();

    }

    void getData()
    {

    Serial.println("analysis started");
    getDhtData();
    getSoilMoisterData();
    processing_temp();
    processing_tempmax();
    processing_hum();
    ProcessingLights();
    Processing_Moisture();
    }

    //function running the processing of heat collected Data, and triggering the heater if needed
    void processing_temp()
    {
    Serial.println("Processing heat \n");
    if (temp seuil_tempmax)
    {
    Serial.println(“FAN ON”);
    digitalWrite(relay_fan, LOW);
    }
    else
    {
    Serial.println(“FAN OFF”);
    digitalWrite(relay_fan, HIGH);
    }
    }

    //function running the processing of humidity collected Data, and triggering the fan if needed
    void processing_hum()
    {
    Serial.println(“Processing humidity \n”);
    if (hum > seuil_hum)
    {
    Serial.println(“FAN ON”);
    digitalWrite(relay_fan, LOW);
    }
    else
    {
    Serial.println(“FAN OFF”);
    digitalWrite(relay_fan, HIGH);
    }
    }

    //funtion processing the data coming from the LDR, turning OFF and ON the artificial light system if needed.
    void ProcessingLights()
    {
    if (Flag_master_LED == 0)
    {
    Serial.println(” “);
    Serial.println(“Start processing Light \n”);
    if (lum < seuil_lum && (leds_ON == false ))
    {
    Serial.println("LEDs ON");
    digitalWrite(relay_leds, LOW);
    }
    else if (lum < seuil_lum && (leds_ON == true))
    {
    Serial.println("LEDs already ON");
    }
    else
    {
    Serial.println("LEDs OFF");
    digitalWrite(relay_leds, HIGH);
    }
    }
    else
    {
    Serial.println("flag_master_LEDs : ON");
    }
    delay(200);
    }

    void getSoilMoisterData(void)
    {
    //digitalWrite (DHTVCC,LOW);
    digitalWrite (soilMoisterVcc, HIGH);
    delay (500);
    soilMoister = analogRead(soilMoisterPin);
    soilMoister = (soilMoister * 100) / 1024;
    soilMoister = map(soilMoister, 87, 29, 0, 100);
    soilPourcents = soilMoister;
    static char soilTemp[7];
    dtostrf(soilMoister, 6, 2, soilTemp);
    client.publish("Garden/Soil", soilTemp);

    Serial.println("Soil moisture measured:");
    Serial.println(soilMoister);
    digitalWrite (soilMoisterVcc, LOW);
    delay(500);
    digitalWrite (ptrVcc, HIGH);
    delay(500);
    lum = analogRead(soilMoisterPin);
    lum = (lum * 100) / 1024;
    static char lumTemp[7];
    dtostrf(lum, 6, 2, lumTemp);
    client.publish("Garden/Lum", lumTemp);

    Serial.println("Light measured:");
    Serial.println(lum);
    digitalWrite(ptrVcc, LOW);
    }

    //function running the processing of Soil moisture collected Data, and triggering the water pump if needed
    void Processing_Moisture()
    {
    Serial.println("Processing water pump \n");
    if (soilPourcents < seuil_moisture)
    {
    Serial.println("PUMP ON");
    digitalWrite(relay_pump, LOW);
    delay(10000);
    digitalWrite(relay_pump, HIGH);
    Serial.println("PUMP OFF \n");

    }
    else
    {
    Serial.println("PUMP OFF");
    digitalWrite(relay_pump, HIGH);
    }
    Serial.println("Waiting 15 Minuits \n");
    delay(900000);
    }

    October 1, 2019 at 11:26 PM
    • Sharath

      Hi Simon! That’s an awesome project.
       
      But, why do you want to change the MQTT and NODE-RED Setup. It is the best one I think. Because thingspeak will limit the number of requests for free plan.
       
      If you are only going to display the data in thingspeak, then you can directly update the variables that you already used in your code. But this will lead to unstable things. When the data is updating it will wait till the data is updated to thingspeak. So the other task that needs to perform will be delayed or might not even happen.
       
      The below function is the main function to update the code. As per the code if you want to update the ‘soilMoisture’ you can modify the function like this, similar to other variables too:
       
      ThingSpeak.writeField(myChannelNumber, 1,soilMoisture, apiKey); //Update in ThingSpeak

      October 2, 2019 at 10:57 AM
  • Simon

    Thanks for the help Sharath, I did a bit more google searching and realised I could use a Thingspeak node in node red to upload the data to thingspeak.
    Its working like a charm and didn’t need to edit the code on the nodeMCU.

    October 2, 2019 at 3:21 PM
    • Sharath

      Wow! That’s cool then. NodeRED is becoming popular nowadays.

      October 2, 2019 at 6:07 PM
  • irfan

    hello sir. thanks for your sharing. I need something else. How can i send values from thingspeak to arduino? I want to control a relay which is connected to arduino. can i do that?

    October 9, 2019 at 7:59 PM
  • hemanth kumar reddy

    hello sir, i need code for flame sensor data uploading for fire security system, using arduino, nodemcu and gsm module sending data to thingspeak. sir please help me sir..

    October 14, 2019 at 11:53 AM
  • Mallesh

    hello sir please help me with code taking input from 4 led’s using nodemcu through thingspeak

    December 3, 2019 at 1:46 PM
  • Teeai

    Good day sir, I faced some problem which is my sensor data is not accurate. I am using MG811 carbon dioxide sensor connect with the nodemcu ESP8266 WiFi. My system connect like this
    co2—nodemcu
    GND — GND
    AOUT — A0
    DOUT — D0
    VCC — 3V

    So, what I can do?

    December 3, 2019 at 9:03 PM
    • Sharath

      There are 2 things to be done:
       
      1. You need to supply the recommended VCC Voltage to the Sensor (3.3 or 5V depends on sensor). Most MQ Gas sensors take 5V as there is a heater coil in it.
       
      2. If the sensor woks on 5V Logic level (AOUT & DOUT) then it will happen with NodeMCU as the Pins Voltage Levels are 3.3V Tolerant. You need to use a voltage divider that will not exceed 3.3v on the sensor output (that connects to NodeMCU A0 Pin).
      You can use this calculator for voltage divider – http://www.ohmslawcalculator.com/voltage-divider-calculator

      December 4, 2019 at 10:39 AM
      • Teeai

        May I know what is VCC voltage for MQ811 carbon dioxide sensors used? CO2 Sensor is need to use 6 volts. As I know, nodemcu just have 3v only.
        At the begining my project is using arduino uno board atmega 328P connect with sensor, but the sensor data cannot enter to the firebase because of the arduino board did not have wifi function. So I change with nodemcu connect to sensor. Once I changed, the sensor data already is not accurate which is all data is same (1073670784.00 ppm)

        Here is my code

        /* Sending Sensor Data to Firebase Database */

        #include // esp8266 library
        #include // firebase library
        #include “MG.h” // mg811 carbon dioxide sensor library

        #define FIREBASE_HOST “iot-kids-monitoring-system.firebaseio.com” // the project name address from firebase id
        #define FIREBASE_AUTH “3FenGbA2QFIRqT5bARfjThSa5PjHmxxxxx” // the secret key generated from firebase

        #define WIFI_SSID “xxxxx” // input your home or public wifi name
        #define WIFI_PASSWORD “xxxxxxx” //password of wifi ssid

        #define MGPIN D0 // what digital pin we’re connected to
        #define MGTYPE MG811 // select mg type as MG811
        #define CO2level = 0;
        float ppm = 0.0;
        MG mg(MGPIN, MGTYPE);
        int analogPin = 35;
        void setup() {
        Serial.begin(9600);
        delay(1000);
        WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi
        Serial.print(“Connecting to “);
        Serial.print(WIFI_SSID);
        while (WiFi.status() != WL_CONNECTED) {
        Serial.print(“.”);
        delay(500);
        }
        Serial.println();
        Serial.print(“Connected to “);
        Serial.println(WIFI_SSID);
        Serial.print(“IP Address is : “);
        Serial.println(WiFi.localIP()); //print local IP address
        Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebase
        mg.begin(); //Start reading mg sensor
        }

        void loop() {
        float c = mg.readCO2();
        int adcVal = analogRead(analogPin);
        float voltage = adcVal*(3.3/4095.0);
        float voltageDiference=voltage-0.4;
        float concentration=(voltageDiference*5000.0)/1.6;

        if (isnan(c) ) {
        Serial.println(F(“Failed to read from MG sensor!”));

        return;
        }

        Serial.print(“voltage:”);
        Serial.print(voltage);
        Serial.println(“V”);

        Serial.print(concentration);
        Serial.println(“ppm”);
        //Serial.print(“Carbon Dioxide: “); Serial.print(c);
        //String fireCO2 = String(c);
        //Serial.println(” ppm “);

        delay(4000);

        Firebase.pushString (“/MG811/Carbon Dioxide”, fireCO2); //setup path and send readings

        }

        May sir help me see what problem with my code. Thank you

        December 4, 2019 at 3:49 PM
        • Sharath

          You should give 6V at VCC of Sensor to work precisely. As far I have seen the datasheets say the output will be 0 to 2V by default, So you can connect the AOUT Directly without any voltage dividers.

          You can connect the VCC Pin to the Vin Pin of NodeMCU if you are powering it via 5V micro-USB Port. But it is not the recommended method. You have to power the sensor with 6V Externally and the ground common altogether.

          December 4, 2019 at 4:28 PM
          • Teeai

            So sir, I need add one battery connect to the sensor? Or my nodemcu put on the nodemcu base and nodemcu base plug to the Adapter 12V 2A, and the carbon dioxide sensor connect with the voltage regulator 6V?

            Which one is better?

            December 4, 2019 at 7:29 PM
          • Sharath

            Both are fine. If you use battery then you need to consider charging it. It’s better to use a voltage regulator.

            December 4, 2019 at 7:44 PM
          • Teeai

            NodeMCU using adapter 12V connect to sensor. Am I right?

            December 4, 2019 at 8:28 PM
          • Sharath

            No, You have told, you will be using Voltage Regulator right?

            December 4, 2019 at 10:47 PM
          • Teeai

            Ya, my sensor voltage regulator is 6 volts, connect with the nodemcu is just 3v/5v, isn’t can?
            And again my sensor regulator is like this,
            https://my.cytron.io/p-voltage-regulator-plus-6v?src=search.instant

            December 5, 2019 at 9:05 AM
          • Sharath

            They have the circuit too. Check here – https://www.cytron.io/p-mg811-carbon-dioxide-co2-sensor-module

            December 5, 2019 at 10:12 AM
          • Teeai

            No, at the begining ya my sensor is connect to arduino board, but now I already changed to sensor connect with nodemcu because of my sensor data need send to a database

            December 5, 2019 at 10:33 AM
          • Teeai

            Good day sir, I faced a problem again, I already put 6 voltage regulator in my CO2 sensor, but the voltage I got is 0.01V and the concentration of carbon dioxide is -1212.23 ppm.

            Here is my code, is there something wrong?

            /* Sending Sensor Data to Firebase Database */

            #include // esp8266 library
            #include // firebase library
            #include “MG.h” // mg811 carbon dioxide sensor library

            #define FIREBASE_HOST “xxx” // the project name address from firebase id
            #define FIREBASE_AUTH “xxx” // the secret key generated from firebase

            #define WIFI_SSID “Why So Serious?” // input your home or public wifi name
            #define WIFI_PASSWORD “xxx” //password of wifi ssid

            #define MGPIN D0 // what digital pin we’re connected to
            #define MGTYPE MG811 // select mg type as MG811
            #define CO2level = 0;
            float ppm = 0.0;
            MG mg(MGPIN, MGTYPE);
            const int analogPin = A0;
            void setup() {
            Serial.begin(9600);
            delay(1000);
            WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi
            Serial.print(“Connecting to “);
            Serial.print(WIFI_SSID);
            while (WiFi.status() != WL_CONNECTED) {
            Serial.print(“.”);
            delay(500);
            }
            Serial.println();
            Serial.print(“Connected to “);
            Serial.println(WIFI_SSID);
            Serial.print(“IP Address is : “);
            Serial.println(WiFi.localIP()); //print local IP address
            Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebase
            mg.begin(); //Start reading mg sensor
            }

            void loop() {
            float c = mg.readCO2();
            int adcVal = analogRead(analogPin);
            float voltage = adcVal*(3.3/4095.0);
            float voltageDiference=voltage-0.4;
            float concentration=(voltageDiference*5000.0)/1.6;

            if (isnan(c) ) {
            Serial.println(F(“Failed to read from MG sensor!”));

            return;
            }

            Serial.print(“voltage:”);
            Serial.print(voltage);
            Serial.println(“V”);

            Serial.print(concentration);
            Serial.println(“ppm”);
            //Serial.print(“Carbon Dioxide: “); Serial.print(c);
            //String fireCO2 = String(c);
            //Serial.println(” ppm “);

            delay(4000);

            //Firebase.pushString (“/MG811/Carbon Dioxide”, fireCO2); //setup path and send readings

            }

            So sir, what I can do?

            December 5, 2019 at 10:08 PM
  • Dhinakar Roy

    Hello sir. Im from NIT Warangal and we are doing project on IOT BASED HEALTH MONITERING SYSTEM where we are measuring pulse with pulse sensor and temperature with lm35 and send data to THINGSPEAK IOT Platform.
    Initially we used general esp8266, we got output but not able to send data to thingspeak. Then now we are using NODEMCU ESP8266 we are able to sense and send one data either pulse or temperature but not both.
    Can you provide code for sending two analog data to thingspeak. I tried the above code but its not working and i didnt understand why did you gave int number = RANDOMNUMBER(0,100).
    PLEASE SEND ME THE CODE BRO.
    THANK YOU VERY MUCH.

    December 9, 2019 at 9:09 AM
    • Sharath

      You have to check this blog, where I used 2 different fields (Analog, Digital) – https://www.factoryforward.com/automatic-street-light-thingspeak-cloud/
       
      Doubt: (I didn’t used it in the above code). By the way
       
      int number = RANDOMNUMBER(0,100).
       
      This is just an arduino function that generates a random number between 0 to 100. The generated number is stored in the ‘number’ variable. It is actually used for feeding a dummy values to test whether the data uploading correctly, when you don’t have any sensor connected.

      December 9, 2019 at 10:42 AM
      • Dhinakar Roy

        sir with what i have to replace random(0,100) if i have two sensors connected
        sir do you have a complete code to upload temperature sensor data and pulse sensor data to thingspeak either with general esp8266 or with nodemcu.

        December 9, 2019 at 2:09 PM
        • Sharath

          You must have to check the blog link in previous comment.
          ThingSpeak.writeField(myChannelNumber, 2, IRval, myWriteAPIKey);
          ThingSpeak.writeField(myChannelNumber, 1, LDRval, myWriteAPIKey);

          In the above functions, 2 and 1 are different fields where the data updates.

          int LDRval = analogRead(LDRpin); //Read Analog values from LDR
          int IRval = digitalRead(IRpin); //Read IR is detected or not (Digital)

          These two lines has LDRval & IRval are two different variables that holds 2 different sensor values. You can notice the variables on the Thingspeak.writeField() functions.

          December 10, 2019 at 10:35 AM
  • Abigail

    Hi Sir, my project is using Arduino Uno Board connect with MG811 carbon dioxide sensor, LED and buzzer. Isn’t this circuit can connect to the thingspeak?

    December 11, 2019 at 8:40 AM
  • vignesh

    Sir how to interface ph sensor, GY21 Temperature and humidity sensor, Waterproof temperature sensor, liquid flow meter, and so on..
    i need code for thingspeak.

    December 14, 2019 at 9:18 AM
  • stepiiis

    Hello,
    The channel number means the channel ID?
    Thanks

    January 3, 2020 at 11:29 PM
  • Kaviyachelvan

    hi sharath i need a adriuno program for motion sensor and i need to connect it with the node mcu and Thingspeak and i need to to connect it to the buzzer so please i need some instructions and guidelines to make so please send me a model or abstract type of program so please help or post the program with some guidelines
    by
    K.Kaviyachelvan(student, Kings college of
    engineering,thanjavur)

    January 9, 2020 at 3:59 PM
  • Arduino Projeleri

    Thank you my friend. I will use it for my graduation project. However I have a question here, how could i use a sensor that supply voltage is 5V with NodeMcu Lolin V3. As you know that NodeMcu support to distribute max 3V even form A0 pin. I could supply 5V from nano by connecting the nano GND and NodeMcu GND. But when I measure the Vout of my sensor it gives me 3V max that should have been 5V. Please suggest me something to get over it. Thank you for now.
    Sincerelly
    Enes KILINC

    February 13, 2020 at 5:10 AM
    • Sharath

      You can use a voltage divider circuit that wouldn’t reach above 3.3v max at A0 pin of NodeMCU. There are some online websites like ohmslawcalculator, etc are available for resistor values.

      February 13, 2020 at 5:44 AM
  • sai karthik

    hiiiii anyone knows the code of rain sensor using nodemcu in thingsspeak

    March 4, 2020 at 7:34 PM
    • Sharath

      This code works with all analog sensors, You need to Connect A0 Pin to A0 of NodeMCU, That’s it. Every Sensor outputs a electric voltage 0-3.3V (In NodeMCU it sampled into 0 to 4095 values, In UNO 0-5, 0 to 1024 Samples).

      Note: You might need a voltage divider as the Sensor is 5V and the NodeMCU is 3.3V

      March 4, 2020 at 8:07 PM
  • N.Jaswanth

    Sir arduino Ide says ‘A0’ is not declared plz help with this !

    March 13, 2020 at 12:21 PM
    • N.Jaswanth

      Sorry i was using *A1

      March 13, 2020 at 12:22 PM
  • Aaronraj

    Hi sharath
    am doing a project on smart health coat which will consist of three parameters
    can you help out with the arduino code for the NODE MCU
    The parameters consists of heart beat temperature and blood pressure

    April 8, 2020 at 10:52 AM
  • İnayet Hilmi KONUR

    ESP8266Wifi.h library
    I couldn’t downlaad please help me

    June 6, 2020 at 7:21 PM
  • 604820790368

    Hi, Checking out our project on ‘Upload Sensor Data to ThingSpeak using NodeMCU’.
    Can you please tell me if this can be modified to read an LDR sensor or photodiod placed over the flashing LED on an electricity to read kWh.
    LED flash rate will vary depending on different meter types. My meter LED flashes at a rate 3200 imps/kWh.
    I would like to be able to monitor the LED to record power usage over 24hr periods and maybe over longer term.
    Can how this can be adapted ?
    I have many of you very interesting projects.
    Best regards,
    NormanG

    February 6, 2022 at 10:35 PM

Leave a Reply

Back to Blog