Appendix B. Building a custom IoT sensor
Sometimes the exact sensor you need isn’t available off the shelf, or isn’t available in the right configuration. For example, you might need to combine temperature, humidity, and soil moisture in a single affordable unit. I needed to correlate soil moisture with ambient humidity to understand how indoor plants affect home climate. No commercial sensor provided this combination affordably, so I built one.
B.1 Hardware
You’ll need:
- ESP32 development board (for example, a WROOM 32E board) (~$6)
- DHT22 temperature/humidity sensor (~$9)
- Capacitive soil moisture sensor (~$2)
- Miscellaneous: 10kΩ pull-up resistor, wires, breadboard (~$5)
The circuit (figure B.1) connects the DHT22 to GPIO 23 with a 10kΩ pull-up resistor, the moisture sensor to GPIO 33 (ADC1 channel), and both sensors to 3.3V and ground.
Figure B.1 Sensor circuit design.
B.2 Cloud configuration
Before writing device code, configure AWS IoT Core so your device can securely publish readings.
B.2.1 Step 1: Create a thing
- Navigate to AWS IoT Core → Manage → All devices → Things
- Click "Create thing". Choose to create a single thing, and you will be presented with the screen shown in figure B.2 where you must give your thing a name.
Figure B.2 Thing properties within AWS. Give your thing a name here.
B.2.2 Step 2: Generate certificates
Select the option to auto generate a new certificate as shown in figure B.3.
Figure B.3 Create device certificates.