Click here to Skip to main content
13,863,150 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 4 Dec 2016
Licenced CPOL

Connecting an ESP8266-12 to a DS1820 Thermometer and Do a HTTP Post Data to the Internet

, 4 Dec 2016
Rate this:
Please Sign up or sign in to vote.
Here's how to connect an ESP8266-12 to a DS1820 thermometer and do an HTTP post data to the internet.


I'll be using these components:

  • A standard ESP8266-12 on a breakout-board such as the one shown
  • Three 4.7k resistors
  • A 3v battery (I use a CR123a) for powering the ESP826612
  • A DS1820 (I use the DO-92 packaged version below)

The following requirements should be met:

  • All connections, including those on the The ESP 8266-12 on the breakout-board, are solid and conduct power as they should.
  • The battery holds at least 2.8v of power.
  • The ESP8266-12 has been programmed with the following sketch:
    #include OneWire.h
    #include DallasTemperature.h
    #include ESP8266WiFi.h
    #include ESP8266WiFiMulti.h
    #include ESP8266HTTPClient.h
    #define ONEWIRE_PIN 13
    OneWire oneWire(ONEWIRE_PIN);
    DallasTemperature sensors(&oneWire);
    boolean TempSensorAvailable = false;
    DeviceAddress TempSensor;
    float tempCtry1;
    float tempCtry2;
    //AP definitions
    #define AP_SSID "your wifi-network name here<your-wifi-network-name-here>"
    #define AP_PASSWORD "wifi password here<your-wifi-network-password-here>"
    void setup() {
    //enable this to test from the arduino serial monitor
    Serial.print("Found ");
    Serial.print(sensors.getDeviceCount(), DEC);
    Serial.println(" OneWire device(s).");
    // report parasite power requirements
    Serial.print("Parasite power: ");
    if (sensors.isParasitePowerMode()) Serial.println("ON");
    else Serial.println("OFF");
    if (!sensors.getAddress(TempSensor, 0)) {
    Serial.println("No OneWire Device Found");
    } else {
    TempSensorAvailable = true;
    Serial.println("OneWire Device Found");
    sensors.setResolution(TempSensor, 12);
    void loop() {
    <onewire .h=""><dallastemperature 
    .h=""><esp8266wifi .h=""><esp8266wifimulti 
    <onewire .h=""><dallastemperature 
    .h=""><esp8266wifi .h=""><esp8266wifimulti 
    <your-wifi-network-password-here>delay(60 * 1000);
    void postTemperature()
    sensors.requestTemperatures();            // Get temprature
    tempCtry1 = sensors.getTempC(TempSensor); // save temperature
    sensors.requestTemperatures();            // Get temprature
    tempCtry2 = sensors.getTempC(TempSensor); // save temprature
    HTTPClient http;
    http.addHeader("Content-Type", "application/json");
    String postMessagePart1 = String("{ 'sensorId' : 
    'L15-Out1', 'temperature' : '");
    String postMessagePart2 = String("', 'postAttempts' : '");
    String postMessagePart3 = String("', 'batteryVoltage' : '");
    String postMessagePart4 = String("' }");
    String postMessage = postMessagePart1 + ((tempCtry1+tempCtry2)/2) + 
    postMessagePart2 + retries + postMessagePart3 + vdd + postMessagePart4 ;
    int httpCode = http.POST(postMessage);
    Serial.print("http result:");
    if ( httpCode != 200 && httpCode != 201)
    void wifiConnect()
    Serial.print("Connecting to AP");
    WiFi.begin(AP_SSID, AP_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
    Serial.println("WiFi connected");

Don't forget to import the libraries into the Arduino IDE environment.

Given the above is in order, go ahead and connect the components as per the following picture:

  • The RESET and GPIO16 pins should be connected - this enables the ESP 8266-12 to wake up from deep sleep mode.
  • The GPIO0 and GPIO2 should be connected to VCC with a 4.7k resistor in the middle. This is to prevent a so-called 'zombie-mode', in which the ESP8266-12 has trouble waking up from deep sleep.
  • The data-line and the VCC line of the DS1820 should be joined by a 4.7k resistor, or the temperature will not be read.
  • The data-line of the DS1820 should be connected to the GPIO13-pin of the stand-alone ESP8266-12, as this corresponds with the "#define ONEWIRE_PIN 13" statement of the code.

With the ESP connected like so, my ESP8266-12 happily does an HTTP post to my web-service every 60 seconds, before repeating the cycle.

You should put the ESP8266-12 into deep sleep mode if you power your thermometer via battery.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Denmark Denmark
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190214.1 | Last Updated 4 Dec 2016
Article Copyright 2016 by harleydk
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid