Beehive Temperature and Humidity Sensor With WiFi
by 4hivenuc in Circuits > Sensors
549 Views, 1 Favorites, 0 Comments
Beehive Temperature and Humidity Sensor With WiFi
I wanted to create a temperature and humidity sensor for the beehives in my apiary. I didn't want to buy what was on the market as I wanted full control of the sensors and how it communicated. The design I camp up with after searching the web for days and also seeing Andrzej Mizerkiewicz at AWS Re:Invent in 2022. He produced his own version of this, only instead of using WiFi, he used LoRan (which this project could be converted to). I have WiFi about 50 feet from my apiary so I decided to utilize that.
I wanted to know what was going on in my hives in winter time. Not that there would be much I can do to help my bees should they struggle, but to know when they began to decline (if) an associate it with the local weather. In the Winter of 2022 I lost all 9 of my colonies somewhere between January and February. I assumed the warm snap in January cause the cluster to break and they froze to death. Hopefully this will help me understand more what is happening in my hives.
There is for sure areas of improvement here. I was under a time crunch to get this completed, but already have a list of things I want to change.
Note: I use Arduino IOT Cloud to visualize whats happening in my colonies. You don't have to use this IOT SaaS source. This was the easiest and cheapest option for me.
Also the AHT21 sensor I use is a pain to code and there isn't much support out there. I went with this chip to save money and because it is small. You can for sure use other, more supported sensors like DHT11.
Lastly the ESP board I am using isn't perfect for this project. Yes, it does what I need it to do, however other boards designed for alternative power inputs would probably be easier to work with. That being said, this board has been a tank and I have had no problems with any of them.
Supplies
ESP32 Development board: https://www.amazon.com/dp/B0865YSHSS?psc=1&ref=ppx_yo2ov_dt_b_product_details
WiFi antenna and Cable: https://www.amazon.com/dp/B088GWHNCR?psc=1&ref=ppx_yo2ov_dt_b_product_details
AHT21 Temperature and Humidity sensor: https://www.amazon.com/dp/B0C6DZ8YZG?psc=1&ref=ppx_yo2ov_dt_b_product_details
Waterproof wire to connect Sensor to ESP32: https://www.amazon.com/dp/B07KK9J6VC?psc=1&ref=ppx_yo2ov_dt_b_product_details
Solar Panel to Battery and ESP32 board: https://www.amazon.com/dp/B082F7X8WS?psc=1&ref=ppx_yo2ov_dt_b_product_details
Solar Panels: https://www.amazon.com/dp/B0BJPXJ61X?psc=1&ref=ppx_yo2ov_dt_b_product_details
Wires to connect Solar Panels: https://www.amazon.com/dp/B089CSBD2Q?psc=1&ref=ppx_yo2ov_dt_b_product_details
3.7v LiPo battery: https://www.amazon.com/dp/B08T6QS58J?psc=1&ref=ppx_yo2ov_dt_b_product_details
Connecting Wires for Solar Panel Board: https://www.amazon.com/dp/B088NFRNZ2?psc=1&ref=ppx_yo2ov_dt_b_product_details
Queen Bee Cages: https://www.amazon.com/dp/B09FDR46W6?psc=1&ref=ppx_yo2ov_dt_b_product_details
Stainless Steel Mesh https://www.amazon.com/dp/B081QB3BLF?psc=1&ref=ppx_yo2ov_dt_b_product_details
I used PETG to 3D print the boxes and supports: https://www.amazon.com/dp/B0BZCWNY4K?psc=1&ref=ppx_yo2ov_dt_b_product_details
M3 and M5 screws and nuts to assemble.
Download and Install Arduino IDE software to program your ESP32 board.
Electronics
Once you have procured all the required equipment, I suggest you setup your hardware on a Breadboard like I did or something like it so you can begin to code and test. Be sure to have your pin outs in front of you to understand what pins connect to the Solar Panel board for battery/solar power (not required at this stage) and the AHT21 sensor.
- I had to put 2 breadboards together to allow access to the pins on both sides of this board. The width of the board makes it so that it will not fit on a standard single board.
- Place the AHT21 sensor on the bread board in its own section. I soldered the headers in place and then bent the pins so the unit would stand up on the bread board (not required)
- place your jumper wires for the sensor to the following pins (image A):
- 3V3 (ESP32) -> VIN (AHT21)
- GND (ESP32) -> GND (AHT21)
- 21 (ESP32) -> SDA (AHT21)
- 22 (ESP32) -> SCL (AHT21)
- Plug the ESP32 board into a USB Micro to USB A/C cable into your computer. (make sure this cable is able to transmit data or, you will not be able to connect to this board)
- If using a Mac OS device be sure you download and install the silicon labs driver in the image below. This will allow you to use a USB as a com port to communicate. (https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads)
Arduino Setup and Code
Download and install Arduino IDE (https://www.arduino.cc/en/software).
Download Hardware support for the ESP32 board
- In the Arduino IDE app, on the left hand side is a gray outline picture of a circuit board. Click this and you will see a drawer slide out to the right. This is where you search for ESP32 and install the one titled: "esp32 by Espressif Systems"
Download Libraries for Arduino IDE code to compile correctly.
- In the Arduino IDE app, on the left hand side is a gray outline picture of books, click this and you will see a drawer slide out to the right. This is where you search for and install your libraries.
- There are multiple Libraries you will need to install here:
- Start with ArduinoIoTCloud by Arduino (install all support libraries)
- AHT20 by dvarrel (https://www.arduinolibraries.info/libraries/aht20)
- Adafruit AHTX0 by Adafruit (install all support libraries) (this one may not be required, if you receive an error in compiling add this)
Load the scripts from this Instructable
- download the following files from this instructable:
- Temperature_and_Humidity.ino
- ReadMe.adoc
- arduino_secrets.h
- sketch.json
- thingProperties.h
- open Temperature_and_Humidity.ino in Arduino IDE
- This should pull the other files in with it, if not be sure to add new tabs by clicking on the hotdogs (top right) and open the other 4 items, you can exclude ReadMe if you prefer.
- Temperature_and_Humidity.ino contains all the code used to make the project work.
- The arduino_secrets.h file needs to be modified by you to include your WiFi, Password and Secret Device Key you will get from Arduino Cloud.
- The ThingProperties.h file needs to be modified by you to include the device key you will get from Arduino Cloud.
- The sketch.json file doesn't need to be touched.
Connect to your ESP32 board
- Connect the USB cable to the ESP32 board
- Inside Arduino IDE click on tools, Board, esp32, ESP32 Dev Module
- Also under the Tools menu select port, /dev/cu.usbserial.0001 (for Mac, if PC use the appropriate port)
- You should now see your board show up in top left drop down box
- Before you can write the code to the board and have it work you will have to go to the next step
Arduino IoT Cloud
All of the code in step 2 was written for use with Arduino IOT Cloud. If you choose not to use this, you will have to modify the code to meet which ever IOT provider you go through. There are several to choose from, I choose Arduino Cloud, because it was cheap, easy and had quick support. You can also use AWS, Azure, GCP as well as many many others.
- Go to https://create.arduino.cc/iot/things and sign up for a free Arduino IOT Cloud account (free for 2 "Things" only after that there is a charge)
- Once you authenticate, go to your home screen and clic on the IOT Cloud button
- Click Create button on the IOT Cloud Things landing page
- Give your Thing a Name
- Add 2 variables see example image
- Temperature
- Floating Point Number (Type)
- Read Only
- Periodically
- 2 seconds
- Humidity
- Floating Point Number (Type)
- Read Only
- Periodically
- 2 seconds
- Click Select Device on the right hand side
- Click Setup New Device
- Click Third Party Device
- Select ESP32
- Select ESP32 Dev Module (you can type out Dev Module to save time finding it)
- Click Continue and give it a name
- When you click next you will be given a screen only one time that shares your Device ID and Secret Key info required to send the data to Arduino IOT Cloud. This information will be used to modify the Code in Step 2. Simply copy and paste these keys in where needed in the code and on the network setup screen you will see next. Copy the Secret Key second as this is the one needed for the Network setup.
- Click Configure Network and give it your WiFi name, Password and the Secret Key we copied in the last step.
All of these steps have built some basic code to send to your ESP32 board. We will not be using this code as Arduino IOT Cloud wasn't able to receive the AHT20 library install as Arduino IDE was. So unless they fix this issue you will need to complete your setup in the Arduino IDE application.
Writing Code to ESP32
Write your code to the ESP32 board.
- Return to Arduino IDE that we imported our code into.
- Make sure to update arduino_secrets.h and ThingProperties.h with the keys we got from Arduino IOT Cloud Thing and Device creation.
- Save
- Click the -> at the top left of the Arduino IDE application. This will verify code, compile it and then write it to the ESP32 board.
- The code I have written is set to show the temperature in Fahrenheit, you can modify it to show Celsius.
- Click on the Magnifying glass to see the Serial Monitor output. This will show you if everything is working.
- I also put a sleep timer in the code. This will help save the battery as it will only take the temp and humidity readings every 15 minutes. You can of course modify this as well.
Arduino IoT Cloud Dashboard
Create a Dashboard in Arduino IOT Cloud
- Click Dashboard tab on top of website
- Click Create button
- Give the Dashboard a name
- Add a Widget to the dashboard
- I selected Gauge for Temperature and Percentage for Humidity
- Attach the Widget to your Device and click done
Now you have a widget that will show you the temperature and humidity when every you need to look. You can also download the app for Arduino IOT Cloud "IoT Remote" and view it from your mobile device anywhere.
Putting It Together
Now for the hardware, I have chosen to 3D print my boxes and solar panel supports. This is very time consuming, but I don't mind. I expect you to know how to use your 3D printer and the applications you need to create and send files to your printer.
- I have included all the STL files I used to create the box and solar panel supports. Credit to: Doug https://www.printables.com/model/414530-simple-less-rugged-box-parameterized for the box I modified.
- You may have to modify the box yourself if you choose to not use 100% of the parts I used.
- The box is designed to mount to the side of your beehive, you will have to drill a hole for the cable or put a shim board in on top of your upper deep (I use single deep) also you will need to screw it fast to the box. Make sure the solar panel is facing south at a minimum to maximize the sun.
- After you download the STLs, modify anything if needed and print out each piece.
- I used 3 and 5 mm screws and hot glue to assemble everything.
ESP32, AHT21, Solar LiPo charger, LiPo battery
- I clipped the connectors off the bottom of the ESP32 and AHT21 and soldered the connections to the top of the boards.
- I used the 5v and GND for the Solar LiPo charger connection
- I used the 3V, GND, Pin 21 and 22 to connect the ESP32 to the AHT21 sensor.
- I used hot glue to secure the pieces in place and to seal the holes for the cables coming in from the sensor and the solar panel.
- Test everything, I found that my batteries came wired with the Red wire being - and the Black wire being + so that threw everything off.