Introduction: 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

Step 1: 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.

  1. 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.
  2. 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)
  3. place your jumper wires for the sensor to the following pins (image A):
  4. 3V3 (ESP32) -> VIN (AHT21)
  5. GND (ESP32) -> GND (AHT21)
  6. 21 (ESP32) -> SDA (AHT21)
  7. 22 (ESP32) -> SCL (AHT21)
  8. 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)
  9. 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)

Step 2: Arduino Setup and Code

Download and install Arduino IDE (https://www.arduino.cc/en/software).

Download Hardware support for the ESP32 board

  1. 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.

  1. 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.
  2. There are multiple Libraries you will need to install here:
  3. Start with ArduinoIoTCloud by Arduino (install all support libraries)
  4. AHT20 by dvarrel (https://www.arduinolibraries.info/libraries/aht20)
  5. 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

  1. download the following files from this instructable:
  2. Temperature_and_Humidity.ino
  3. ReadMe.adoc
  4. arduino_secrets.h
  5. sketch.json
  6. thingProperties.h
  7. open Temperature_and_Humidity.ino in Arduino IDE
  8. 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.
  9. Temperature_and_Humidity.ino contains all the code used to make the project work.
  10. 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.
  11. The ThingProperties.h file needs to be modified by you to include the device key you will get from Arduino Cloud.
  12. The sketch.json file doesn't need to be touched.

Connect to your ESP32 board

  1. Connect the USB cable to the ESP32 board
  2. Inside Arduino IDE click on tools, Board, esp32, ESP32 Dev Module
  3. Also under the Tools menu select port, /dev/cu.usbserial.0001 (for Mac, if PC use the appropriate port)
  4. You should now see your board show up in top left drop down box
  5. Before you can write the code to the board and have it work you will have to go to the next step

Step 3: 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.

  1. 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)
  2. Once you authenticate, go to your home screen and clic on the IOT Cloud button
  3. Click Create button on the IOT Cloud Things landing page
  4. Give your Thing a Name
  5. Add 2 variables see example image
  6. Temperature
  7. Floating Point Number (Type)
  8. Read Only
  9. Periodically
  10. 2 seconds
  11. Humidity
  12. Floating Point Number (Type)
  13. Read Only
  14. Periodically
  15. 2 seconds
  16. Click Select Device on the right hand side
  17. Click Setup New Device
  18. Click Third Party Device
  19. Select ESP32
  20. Select ESP32 Dev Module (you can type out Dev Module to save time finding it)
  21. Click Continue and give it a name
  22. 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.
  23. 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.

Step 4: Writing Code to ESP32

Write your code to the ESP32 board.

  1. Return to Arduino IDE that we imported our code into.
  2. Make sure to update arduino_secrets.h and ThingProperties.h with the keys we got from Arduino IOT Cloud Thing and Device creation.
  3. Save
  4. 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.
  5. The code I have written is set to show the temperature in Fahrenheit, you can modify it to show Celsius.
  6. Click on the Magnifying glass to see the Serial Monitor output. This will show you if everything is working.
  7. 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.

Step 5: Arduino IoT Cloud Dashboard

Create a Dashboard in Arduino IOT Cloud

  1. Click Dashboard tab on top of website
  2. Click Create button
  3. Give the Dashboard a name
  4. Add a Widget to the dashboard
  5. I selected Gauge for Temperature and Percentage for Humidity
  6. 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.

Step 6: 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.

  1. 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.
  2. You may have to modify the box yourself if you choose to not use 100% of the parts I used.
  3. 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.
  4. After you download the STLs, modify anything if needed and print out each piece.
  5. I used 3 and 5 mm screws and hot glue to assemble everything.

ESP32, AHT21, Solar LiPo charger, LiPo battery

  1. I clipped the connectors off the bottom of the ESP32 and AHT21 and soldered the connections to the top of the boards.
  2. I used the 5v and GND for the Solar LiPo charger connection
  3. I used the 3V, GND, Pin 21 and 22 to connect the ESP32 to the AHT21 sensor.
  4. 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.
  5. Test everything, I found that my batteries came wired with the Red wire being - and the Black wire being + so that threw everything off.