Close
0%
0%

Simple IOT

A workshop on IOT including a simple IOT device using Wemos D1, a DS18B20 temperature sensor, a battery shield and a rechargeable battery.

Similar projects worth following
To exemplify the IOT concept I built this project based on:
- several hardware remote nodes, each using a microcontroller, a sensor and a communication modem
- the backend, comprised of a data interface (data API and a database)

On the hardware side, we use the following components:
- Wemos D1 Lite
- DS18B20 temperature shield
- Battery shield
- External Lithium rechargeable battery

This is a support material for a workshop I'm doing at Balccon2k17 in Novi Sad / September 2017.

IOT stands for Internet of Things and refers to small devices equipped with direct internet connectivity, without needing an external computer. They are usually composed of a main microcontroller and an additional connectivity (eg. ESP8266 for Wifi, ENC28J60 for Ethernet) or they are complete SOC including both the processing unit and the connectivity modems in one single package. Regardless of their form or shape, these devices open new applications for remote sensing and controlling, and bring system automation to a new level of performance. Examples of such devices were presented on this blog even before IOT was coined as a buzzword. See the Ethernet controlled power relay based on enc28j60 or the development of first prototypes of what is now uRADMonitor.

Simple IOT temperature sensor

To exemplify the IOT concept I propose the following architecture: 

  • several hardware remote nodes, each using a microcontroller, a sensor and a communication modem
  • the backend, comprised of a data interface (data API and a database)
  • Requirements

    On the hardware side, we need the following components:

  • Wemos D1 Lite
  • DS18B20 temperature shield
  • Battery shield
  • External Lithium rechargeable battery
  • For the backend I will demo using the open source EXP server protocol introduced with the KIT1. This is handled by the uRADMonitor server, but alternatively a simple PHP script can be used too.

    Assembling the hardware

    There are multiple way of putting these together, I went for putting the Wemos D1 at the bottom, the battery shield in the middle, and the Temperature shield at the top for better air contact and less internal heating interference. This means we solder the female headers to the Wemos D1, the mixed headers to the Battery Shield and the male headers to the DS18B20 Temperature shield. Here's the result: The PCBs can now be stacked in the proposed order, with the Wemos at the bottom and the DS18B20 sensor at the top. Here's the assembled device:

    The software

    With the simple IOT device ready, we need to program it. The firmware needs to setup the Wifi connection to an Internet Wireless Router, then periodically read the temperature values and send them to the backend. Before we can start, there are few tools we need to install:

  • Arduino IDE download
  • CH340G driver also available here.
  • Install Wemos D1 support over Arduino. First, open Preferences and add "http://arduino.esp8266.com/stable/package_esp8266com_index.json" to Additional Boards Manager URLs:
  • Open Boards Manager and install the esp8266: Finally, we're all set and you can select the Wemos D1 R2 & mini from the Tools -> Board menu: Under Tools -> Port, select the corresponding serial port as allocated to the CH340G connected to your USB port. Go to Tools->Upload speed, and select 921600.

    Simple IOT firmware

    Create a new Arduino sketch. We will be using a few extra libraries: the OneWire and the DallasTemperature, so go to Sketch->Include Library->Manage Libraries and add them: The following code reads the DS18B20 temperature:

    // DS18B20 libraries
    #include <OneWire.h> 
    #include <DallasTemperature.h>
    // sensor settings
    #define SENSOR_BUS D2               // the DS18B20 has the sensor connected to D2
    OneWire oneWire(SENSOR_BUS);        // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) 
    DallasTemperature sensor(&oneWire); // Pass our oneWire reference to Dallas Temperature. 
    ...
    sensor.begin();                   // Start up the sensor library 
    ...
    sensor.requestTemperatures(); // Send the command to get temperature readings 
    Serial.print("Temperature is: "); 
    Serial.println(sensor.getTempCByIndex(0));

    Now we need to add ESP8266 code logic, to make the module connect to an Internet Wireless Router at program start, then periodically read temperature and send it to the backend.

    The uRADMonitor EXP Protocol

    The EXP protocol was introduced with the open source KIT1 design, to implement a way of building custom IOT devices...

    Read more »

    • 1 × Wemos D1
    • 1 × Battery Shield
    • 1 × DS18B20 Shield
    • 1 × Lithium Rechargeable Battery

    • #Balccon2k17

      Radu Motisan10/19/2017 at 19:05 0 comments

      I did a workshop on "Simple IOT" at the Balccon2k17 in Novi Sad, now at its fifth edition. 

      The participants received tens of kits to assemble (including some soldering) their "Simple IOT" devices, a cube like unit that runs on battery, measures temperature and sends all data online via Wifi. The workshop went great, and at the end we got several units up and running, talking to the server to report remote temperature readings.

      More on this on the blog:  https://www.uradmonitor.com/balccon2k17

      If interested in building yours, you can find all hardware and software details on Github: https://github.com/radhoo/SimpleIOT

    • Improvements

      Radu Motisan09/07/2017 at 16:42 0 comments

        This simple construction illustrates the IOT concept and provides a solid base for expanding to more complicated sensors. The EXP Protocol can be used to add additional readings to the "Simple IOT Device", including sensors for CO2 or PM2.5. Since the Simple IOT device runs on a battery, power consumption can be implemented in the code, turning the ESP8266 Radio off to save power, and only reconnecting before data upload. A good approach is to have it take measurements every 30-60 minutes and sleep in between. There are four types of sleep modes for the ESP8266: No-sleep, Modem-sleep, Light-sleep, and Deep-sleep. They all have different functions and different current cost:

      • NO-SLEEP: The No-Sleep setting will keep everything on at all times. This will drain the most current. 
      • MODEM-SLEEP: Modem-sleep is the default mode for the ESP8266. It's only enabled when you're connected to an access point. In this mode, the ESP8266 will disable the modem (WiFi) as much as possible. It turns off the modem between DTIM Beacon intervals. This interval is set by your router.
      • LIGHT-SLEEP: Light-sleep performs the same function as Modem-sleep, but also turns off the system clock and suspends the CPU. The CPU isn't off; it's just idling.
      • DEEP-SLEEP: Everything is off but the Real Time Clock (RTC), which is how the computer keeps time. Since everything is off, this is the most power efficient option. 
      • You can use the Deep-sleep mode to have the ESP8266 go idle when measurements are not needed . You can take temperature readings every 60minutes and have the Wemos D1 go to sleep in between. Then on wake-up, make sure the connection is up before retransmitting. The logic is as follows:

      • Read sensor
      • Sleep for n microseconds 
      • Repeat
      • The sleep time is specified in microseconds (µs), and you can call it with: ESP.deepSleep(50e6); // 50e6 is 50 seconds

    View all 2 project logs

    Enjoy this project?

    Share

    Discussions

    Does this project spark your interest?

    Become a member to follow this project and never miss any updates