Print Friendly, PDF & Email

Components Required:

1. NodeMCU DEVKIT – Buy

2. Linux PC/Windows PC (Tested with Windows 10, Ubuntu 14.04 LTS)

3. Micro USB cable – Buy

4. Potentiometer – 10K Ohm

5. Breadboard – 1

6. Jumper Wires

Way to go ->

1. Connect NodeMCU DEVKIT to PC via the Micro USB cable.

2. Create a channel in your ThingSpeak acccount.

3. Write the following Lua scripts and upload to NodeMCU.

init.lua

wifi.setmode(wifi.STATION)
wifi.sta.config("wifi_name","wifi_password")
print(wifi.sta.getip())
dofile("ToThingSpeak.lua")

 ToThingSpeak.lua

function postThingSpeak(level)
    local volt = adc.read(0)
    print ((volt / 1024) * 3.2)
    local connout = nil
    connout = net.createConnection(net.TCP, 0)
 
    connout:on("receive", function(connout, payloadout)
        if (string.find(payloadout, "Status: 200 OK") ~= nil) then
            print("Posted OK");
        end
    end)

    connout:on("connection", function(connout, payloadout)
 
        print ("Posting...");
 
        -- local volt = adc.read(0);      
 
        connout:send("GET /update?api_key=Write_API_Key&field1=" .. ((volt/1024) * 3.2)
        .. " HTTP/1.1\r\n"
        .. "Host: api.thingspeak.com\r\n"
        .. "Connection: close\r\n"
        .. "Accept: */*\r\n"
        .. "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n"
        .. "\r\n")
        print("Data Sent")
    end)
 
    connout:on("disconnection", function(connout, payloadout)
        connout:close();
        collectgarbage();
    end)
 
    connout:connect(80,'api.thingspeak.com')
end
 
tmr.alarm(1, 60000, 1, function() postThingSpeak(0) end)

ThingSpeak Chart

ADCRead

Hardware Connections ->

1. NodeMCU Pinout

NodeMCUPinout

2. NodeMCU to Potentiometer connections

POT_schem

POT_bb