Arduino: build moisture sensor - how it works
You can easily use the Arduino as a moisture sensor. You can find out how to do this in this practical tip.
Arduino: build moisture sensor
So that you can build your own moisture sensor, you need an Arduino and a DHT11 module with matching jumper cables. You can find the complete code in the picture.
- Connect the "VCC" pin to 5V or 3.3V and the "GND" pin to the ground. The data pin is connected to pin 2.
- Also make sure that you have already installed the "SimpleDHT" library. Then you can import them with the "#include" command.
- Create a variable for the data pin ("int pinDHT11 = 2;") and a new DHT11 object ("SimpleDHT11 dht11;").
- In the setup method, specify that you want to use the serial monitor. Also create two byte variables in the loop method: "byte temperature = 0; byte humidity = 0;".
- With the command "if (dht11.read (pinDHT11, & temperature, & humidity, NULL)) {Serial.print (" ERROR "); return}" you can specify that the word "error" should be output if the Arduino does not Receives data from the DHT11 module.
- You get the current temperature in degrees Celsius with the command "(int) temperature". You measure the humidity with "(int) humidity".
In the next practical tip, we will show you how to set up a GSM module on the Arduino.