ESP8266 on NodeMCU board + DS18B20 + ArduinoIDE + ThingSpeak

You may also like...

8 Responses

  1. Erik Näsström says:

    Hi and thanks a million for the tutorial!

    After trying to get it running with a ESP-01, arduino nano etc I finally gave up and bought a nodeMCU card and now it seems to be working! Just wanted to say thanks!

  2. Simo says:

    Problem… first it was up dating ThingSpeak put suddenly… it’s quiet.. after few min.
    code below…

    // ESP8266 DS18B20 ArduinoIDE Thingspeak IoT Example code
    // http://vaasa.hacklab.fi
    //
    // https://github.com/milesburton/Arduino-Temperature-Control-Library
    // https://gist.github.com/jeje/57091acf138a92c4176a

    #include
    #include
    #include
    #include

    #define ONE_WIRE_BUS D6

    // const char* host = “api.thingspeak.com”; // Your domain
    const char* host = “thingspeak.com”; // Your domain
    String ApiKey = “CD8N0FYO7N5R3TCK”;
    String path = “/update?key=” + ApiKey + “&field1=”;

    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature DS18B20(&oneWire);

    const char* ssid = “KILKE”;
    const char* pass = “97dibmm2jrtem”;

    char temperatureString[6];

    void setup(void){
    Serial.begin(115200);
    Serial.println(“”);

    WiFi.begin(ssid, pass);
    // Wait for connection
    while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.print(“.”);
    }

    Serial.println(“”);
    Serial.print(“Connected to “);
    Serial.println(ssid);
    Serial.print(“IP address: “);
    Serial.println(WiFi.localIP());

    DS18B20.begin();
    }

    float getTemperature() {
    float temp;
    do {
    DS18B20.requestTemperatures();
    temp = DS18B20.getTempCByIndex(0);
    delay(100);
    } while (temp == 85.0 || temp == (-127.0));
    return temp;
    }

    void loop() {

    float temperature = getTemperature();

    dtostrf(temperature, 2, 2, temperatureString);
    // send temperature to the serial console
    Serial.println(temperatureString);

    WiFiClient client;
    const int httpPort = 80; // HTTP
    // const int httpPort = 443; // HTTPS
    if (!client.connect(host, httpPort)) {
    Serial.println(“connection failed to Host ThingSpeak..”);
    return;
    }

    client.print(String(“GET “) + path + temperatureString + ” HTTP/1.1\r\n” +
    “Host: ” + host + “\r\n” +
    “Connection: keep-alive\r\n\r\n”);
    delay(16000);

    }

    What might be the problem.. any suggestions..

  3. Tungsten says:

    I am able to download this program to ESP-12E develop board and run normally but not able to download this to ESP-01, I import this tools to Arduino IDE to download:
    http://arduino.esp8266.com/stable/package_esp8266com_index.json
    When I download to ESP-01, it upload the program to the board but can not complete

  4. Tungsten says:

    I can only write temperature data to thinkspeak, what wrong in my modify?

    #include
    #include “SparkFunHTU21D.h”
    #include
    #include

    HTU21D myHumidity;

    const char* host = “api.thingspeak.com”; // Your domain
    //String ApiKey = “THINGSPEAK_API_KEY”;
    String ApiKey = “xxxxxxxx”;
    String path1 = “/update?key=” + ApiKey + “&field1=”;
    String path2 = “/update?key=” + ApiKey + “&field2=”;

    const char* ssid = “xxx”;
    const char* pass = “yyy”;

    char temperatureString[6];
    char humidityString[6];

    void setup(void){
    Serial.begin(38400);
    Serial.println(“”);

    WiFi.begin(ssid, pass);
    // Wait for connection
    while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.print(“.”);
    }

    Serial.println(“”);
    Serial.print(“Connected to “);
    Serial.println(ssid);
    Serial.print(“IP address: “);
    Serial.println(WiFi.localIP());

    Wire.begin(0,2); //Use Io-0 & Io-2 as SDA & SCL
    myHumidity.begin();
    }

    void loop() {

    float temp = myHumidity.readTemperature();
    float humd = myHumidity.readHumidity();

    dtostrf(temp, 2, 2, temperatureString);
    dtostrf(humd, 2, 2, humidityString);
    // send temperature to the serial console
    Serial.println(temperatureString);
    Serial.println(humidityString);

    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
    Serial.println(“connection failed”);
    return;
    }

    client.print(String(“GET “) + path1 + temperatureString + ” HTTP/1.1\r\n” +
    “Host: ” + host + “\r\n” +
    “Connection: keep-alive\r\n\r\n”);
    delay(5000);
    client.print(String(“GET “) + path2 + humidityString + ” HTTP/1.1\r\n” +
    “Host: ” + host + “\r\n” +
    “Connection: keep-alive\r\n\r\n”);
    delay(5000);
    }

  5. Tungsten says:

    At the front of definition:
    #include
    #include “SparkFunHTU21D.h”
    #include
    #include

  6. Juha U says:

    Gee, that was easy! Thanks a lot for this post!

    I needed to add OneWire -library like DallasTemperature -library, then it compiled and now is logging to thingspeak.

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.