4

Monitoring your freezer with the NodeMCU board

 1 year ago
source link: https://devm.io/iot/monitoring-freezer-nodemcu-board
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Defrosting

Monitoring Your Freezer With the NodeMCU Board

08. Dec 2022


A nightmare: The basement freezer failed and we only discovered the mishap weeks later. All our frozen food is spoiled and needs to be disposed of. Wouldn't it be great if we had a little overseer monitoring the freezer’s temperature that made a loud noise early on in case of a malfunction? Node-RED and the NodeMCU board make it possible.

In this article, we’ll build a temperature monitoring system with the NodeMCU board that’s observable across multiple channels. We’ll use Node-RED for the NodeMCU’s connection board and to deliver the bad news.

NodeMCU

Our project’s core component is the NodeMCU board. The board is inexpensive to order on Amazon [1]. An ESP8266 microcontroller is installed on the NodeMCU board. This has a WiFi interface, which helps us establish a connection to the WLAN. Table 1 shows the ESP8266’s technical data. The NodeMCU board provides us with an interface that lets us conveniently program the ESP8266 via USB. Programming the microcontroller is done via the Arduino IDE.

32-Bit-RISC-CPU Tensilica Xtensa LX106 with 80 MHz
Program memory 64 KB
Data memory 96 KB
External Flash (optional) 512 KB to 4 MB
GPIO 10 Pins; possible interfaces: SPI, I²C, I²S, UART; DMA and IRQ can be used
Wi-Fi - IEEE 802.11 b/g/n

- WEP or WPA/WPA2 Authentication

- Wi-Fi Direct (P2P), softAP

- integrated TCP/IP protocol stack

ADC 1x 10 Bit Converter
Antenna integrated
Power output +19.5dBm in 802.11b mode
Size 17.2x12.3mm
Standby power consumption <1.0mA

Table 1: ESP8266 technical data

Arduino IDE set-up

Installing the Arduino IDE is quite simple. Download the files suitable for your operating system from the project homepage [2] and follow the installation instructions. Windows users need to install an additional driver, which is already available for all Linux-based operating systems. You can download the driver from GitHub [3]. Please start the Arduino IDE now. As the name suggests, it was originally developed for programming Arduino boards, but programming other microcontrollers is possible with special board managers. To include the board manager for the NodeMCU board, you must perform the following steps: First, another board manager URL must be entered. From this URL, download the board administrator for the NodeMCU board. In the menu, under FILE| PREFERENCES, enter the following URL in the ADDITIONAL BOARD MANAGER URLs field and save it by clicking OK: http://arduino.esp8266.com/stable/package_esp8266com_index.json. In the next step, we’ll install the board manager for the NodeMCU board by searching for “ESP8266” under the menu item TOOLS | BOARD: “<ANY BOARD NAME>” | BOARD MANAGER…Then, install the ESP8266 community’s board manager. Depending on your Internet connection, it may take a moment for the installation to complete. After that, close the installation window.

The ESP8266 community board manager supports many different ESP8266 modules, including the NodeMCU board. Now, we need to select the NodeMCU 1.0 (ESP-E12 module) from the menu item TOOLS| BOARD| ESP8266 Boards (2.7.4). Now, we can perform a small test and see if everything’s worked so far. For this, connect the NodeMCU board with our PC’s USB interface and load a test program into the controller. As a test, we’ll use an existing example program. Open the Blink example from the menu (FILE | EXAMPLES| 01.Basics | BLINK). This program makes the LED installed on the ESP8266 blink every second. To load the program into the controller and start it, click the UPLOAD icon (the right arrow, in the top left under the navigation bar). It takes a moment to start the program. If you get an error message after clicking the UPLOAD icon, please check that you’ve selected the correct serial post. The interface can be selected under TOOLS| PORT. Its designation may vary depending on your operating system and computer structure (example: Linux: /dev/ttyUSB0; Windows: COM1).

After our first NodeMCU board and IDE test was successful, we can start adding the libraries that our project needs. There’s a library for querying the DS18B20 temperature sensor and another that provides WebSockets. To add libraries, select SKETCH | INCLUDE LIBRARY | MANAGE LIBRARIES... from the menu. In the search field, enter "DS18B20". Then select the library by Mathias Munk Hansen and install it.

After the installation is complete, search for “WebSockets2_Generic”. Here, you’ll see that only one library can be installed. After the WebSocket library is finished installing, close the window. The IDE preparations are now complete; next, we turn to the sensor's hardware.

Hardware set-up

When building the hardware, we need to keep one important point in mind. A freezer is like a Faraday cage. If we put a microcontroller in the freezer, it won't have a chance to connect to the WLAN. So, we need to place it outside the freezer. But, the temperature sensor has to be inside the freezer. That means we need an extension cable for our sensor so we can use it inside the freezer. We’ll use a simple flat ribbon cable as our extension, since we can easily run it through the freezer’s seals without a big temperature loss. Usually, you’d use an analog sensor for measuring the temperature. In our case, this could be tricky because cable length affects the measurement results. The circuit would need to be individually calibrated and adjusted for each application. Not only would it be a lot of work, but it would also unnecessarily complicate the circuit. Apart from that, you need the right measuring devices for calibrating the circuit. The program would also have to calculate the correct temperature from the analog measured values based on the sensor’s characteristic curve. All in all, it’s a lot of effort, but what alternative do we have? We could use a digital sensor that’s already factory-calibrated. With digital data transmission, the line length is irrelevant for the measured value. Digital sensors are only slightly more expensive than analog ones. But when you consider how much work this can save, they’re definitely worth the money. For this project, we’ll use the DS18B20 temperature sensor [4]. A ten-pack of sensors costs about 9 euros on Amazon. A waterproof version (a ten-pack) is available for about 17 euros [5].

The DS18B20 transmits its measured values serially to our microcontroller. This means we need three lines connecting the sensor to our microcontroller: two for the power supply and one for data transmission. For our data signal to be generated cleanly, we need a pull-resistor between the data line and the positive voltage supply. This resistor’s value is 4.7 kiloohms; **Figure 1 **shows the arrangement’s circuit diagram.

Fig. 1: Sensor’s circuit diagram

Fig. 1: Sensor’s circuit diagram

The ribbon cable’s individual wires are soldered to the DS10B20. Then, we use a heat shrink tubing to insulate individual wires from each other—don’t forget to pull the heat shrink tubing over the wires before soldering (Fig. 2). To mechanically protect the DS18B20, pack it into a small housing. Then, the case is sealed with silicone. An old paint pen cap does a good job here. Now, we come to the power supply. We have several possibilities. We can work with a 3-volt button cell directly at the 3V connector. Or we can use a battery pack with about 5 volts at the VIN connector, or—last but not least—a simple USB power supply. There’s always a chance that the batteries will discharge without us noticing, and then our nice sensor won’t work. No matter what kind of power supply you choose, it’s always a good idea to take advantage of the microcontroller's power-saving features as much as possible. To use them, connect pins D0 and RST on the NodeMCU board. But this connection interferes with the board’s automatic reset. If there are any problems with the connection when uploading the program, manually reset it with the small button on the board. After uploading the program, the hardware reset can also be disturbed, so manual reset helps here. Figure 3 shows the finished setup.

Fig. 2: DS18B20 soldered to the cable

Fig. 2: DS18B20 soldered to the cable

Fig. 3: The finished setup with the DS18B20 and NodeMCU board

Fig. 3: The finished setup with the DS18B20...


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK