IoT has made easy the machine-to-machine communication. Most of the devices use wireless connection (such as Wifi, Lora, etc.). In house, the level of radio-frequency emission is continuously increasing and occupants are living within an electro-smog. My concern is to keep this level as lower as possible and use as much as possible wired connection BUT without giving up with the IoT benefits.
The purpose of this project is to make available a "generic" MQTT device :
Supports DHT sensor for humidity and temperature
Provides 6 analog inputs (0-5V over 10-bit [0-1023] * )
Provides 6 digital outputs (+5V)
Static IP with gateway, DNS and network mask
LED blinks when publishing data
LED steady when network is disconnected
SEND Button to force publishing (and disable network at startup)
* The analog inputs have the internal pull-up enabled. These internal 20K resistors pull-up the inputs to 5V.
Application example :
This module could be used to control heating in different rooms. Analog inputs will be connected to Thermistors (NTC) as temperature sensors and outputs to water solenoid valves or electrical heating elements using relays.
For reading temperature, you just have to connect 20K Thermistors between inputs and GND. For reading a position, replace the Thermistor by a potentiometer. Your external component and the Arduino internal 20K pull-up resistor built a voltage divider bridge. When both resistanced are equals, read value for the corresponding input equals 512.
When using a Thermistors, you may want to linearize the sensor response around the ambient temperature (25°C) by adding of a parallel resistor to the NTC (browse the Internet for tutos).
The Bill Of material is about 8 €.
- Amazon-TOOGOO / Ref. B00QLOSFDS / Arduino Nano V3.0 AVR ATmega328 (2.99€)
- Amazon-BeautyToday /B07M78KLST /Moligh doll ENC28J60 Ethernet module for Nano 3 (3.65€)
- Amazon-Toogoo/ 021430 -B00LO2U134 / LED 5mm (0.0129€)
- Amazon- Semoic /B07Q3TDYM4 / Push button red (0,25 €)
- Amazon-MachinYesell / B07NSZRHJ7 /Arduino Nano 32 extension module (0.99 €)
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Building the Device
Wire the components has shown on the schematic.
NOTE: The Relay, "Force mode" button and 20K Thermistor on the schematic are optional and only shown as an example.
D2 - DHT sensor data bus D3 - LED: stills on disconnected network and blinks on message sending A0 - BUTTON: long press at startup to disable network / press to force message sending D10- CS for SPI D11- MOSI for SPI D12- MISO for SPI D13- SCK for SPI
Connect the DHT-MQTT module USB port to a PC and launch a terminal such as "Termite" using the 115200 baud rate.
Flashing the code into the Arduino Nano.
There are two versions of the Firmware : one with the bootloader and one without.
In order to enable and have the watchdog running correctly, you must flash the Optiboot bootloader into your Arduino Nano. The Atmega328p bootloader (usually available with the chinese Arduini Nano devices) does not handle correctly the watchdog and crash.
NOTE : For flashing a new bootloader, browse the Internet. there are plenty of website explaining how to proceed. You will need a second Arduino for this and connect the device to be flashed using the SPI wiring (ISP).
IMPORTANT : To configure the firmware with the correct IP address and other parameters, use a console (Arduino IDE or Termite) and keep depressed the SEND button during power-up until the serial connection display "CONFIG Mode" instead of "MQTT mode". This disable the network and avoid the firmware to hang while trying to connect to a wrong server. When the broker ( MQTT server) is outside your LAN, don't forget to set the DNS (e.g. your F.A.I. DNS) and the Gateway (your box or router) IPs.
SERIAL COMMANDS: ================ Configure the baudrate at 115 200 Bauds and the suffix to LF for sending command. ? Show help DHT=xx,yy DHT sensor model. xx: 11,21, 22 and yy: delay in secs WDG=[ON or OFF] Enable/disable watchdog (8secs delay) MAC=HH:HH:HH:HH:HH:HH Set MAC address (Hexa) IP =xxx.xxx.xxx.xxx Set IP address DNS=xxx.xxx.xxx.xxx Set IP address GWY=xxx.xxx.xxx.xxx Set IP address MSK=xxx.xxx.xxx.xxx Set IP address SVR=xxx.xxx.xxx.xxx Set MQTT server/broker IP CID=client Set client ID (5 chars max) default is DHT01 USR=name Set user name (8 chars max) default is user PWD=password Set password (8 chars max) default is pass DLY=xxxxx Set Publish delay in secs OPTIONS Show parameters values SAVE Save parameters into EEPROM MEMORY Show free memory VERSION Show firmware version
Keep button depressed during startup to disable network and ease configuration through USB.
This device can be added to your existing home automation by creating a MQTT device input or into a Node-RED dashboard. The topic is made of the CID (default value is DHT01) followed by the I/O in the list below. Therefore, the DHT temperature message can be read using the topic DHT01/TEMP and the output n°0 activated using DHT01/OUT0=(0 or 1).
Press the SEND button to force publishing. Publishing occurs every DLY seconds.
MESSAGE DESCRIPTION ------------------------------------------ Published Output data (Measures/Button): INA0: Analog on A1 (input 0-5V) INA1: Analog on A2 INA2: Analog on A3 INA3: Analog on A4 INA4: Analog on A5 INA5: Analog on A6 TEMP: Temperature (with DHT) HUMD: Humidity (with DHT) Subscribed Input data (Relays/LEDs): OUT0: Relay #0 (on D4) (values: 0/5V, I<40mA) OUT1: Relay #1 (on D5) OUT2: Relay #2 (on D6) OUT3: Relay #3 (on D7) OUT4: Relay #4 (on D8) OUT5: Relay #5 (on D9)