Introduction: Arduino DHT22 Sensor and Soil Moisture Project With Menu

Hello guys
Today I am presenting you my second project on instructables.
This project presents the mixture of my first project in which I used Soil Moisture sensor and DHT22 sensor which is used for measuring temperature and humidity. This project is easy to make, and people that are using Arduino will feel it quiet interesting to make. Difference between this project and the first one is that in this project user will have menu in which he can chose what he wants to see at the moment. There will be four options. So grab you kit and start to make this project which can be used in any home.

Step 1: Obtaining of All Parts

This project uses few part. These parts are very cheap to get, so don't worry about the price. Some of the parts used in this project can be changed so project can be cheaper to make. It is on you which parts of recommended are you going to use and make this project even better.
Parts used in this project:

  1. Arduino uno rev3 (You can also use other Arduino)
  2. Breadboard
  3. LCD 1602 green display with I2C (you can also use display withous I2C but you will need more pins to connect it)
  4. 16 button keypad (Changeable)
  5. FC-28-d Soil hygrometer detection module + soil moisture sensor
  6. DHT22 temperature and humidity sensor (You can use DHT11 which is cheaper to get)
  7. Red LED diode
  8. Blue LED diode
  9. 2 Resistors 220 ohm(used for diodes)
  10. 4k7 resistor used for DHT22 on schematic
  11. Arduino battery connector
  12. Few jumper cables to connect all of the parts

One thing that I need to tell you before you start building this project is that keypad is not necessary. I used keypad this time because my rotary encoder was broken. I think that this project would be perfect if it has rotary encoder because it would use lesser pins, or it can use 3 buttons.

Step 2: Connecting All Parts Together

In this step you can see the schematic I made with fritzing. I will write down hot to connect every key part of this project.

As you can see we are using 5V and GND from arduino to power the breadboard.


  • VCC to 5v (+ part on breadboard)
  • GND to gnd (- part on breadboard)
  • SDA to analog pin A4
  • SCL to analog pin A5

Keypad with 16 buttons:

  • We are using pins 9, 8, 7, 6, 5, 4, 3, 2 to connect the keypad (this is the reason why I would use rotary encoder, because it would only took 3 pins on the board)

Soil Moisture Sensor:

  • VCC to 5v (+ part on breadboard)
  • GND to gnd (-part on breadboard)
  • D0 to digital pin 0
  • A0 to analog pin A0


  • VCC to 5v (+ part on breadboard)
  • GND to gnd (-part on breadboard)
  • Out pin is connected to pin 12

Diode connecting:

  • one part of diode goes into - part of breadboard
  • second part goes through resistor of 220 ohm and after that is is connect to pin 10(blue diode) or 11 (red diode)

Step 3: Writing Code

I'll try to explain code in few parts. There will also be written full code so you can copy it and also change it if you see any need. Also in this code there are written few methods for sensor work, but this time the main focus was on creating menu that will be easy to understand for people that are new with Arduino. This time I am not using any interrupts but in my next projects I will, so keep in mind that this code can get much more better with interrupts.

  1. First part of code is including all of the used libraries for this project. Keep in mind that for all of the parts that I told that I am using you need next libraries: Wire, LiquidCrystal_I2C, Keypad and DHT. All of the libraries can be found on Arduino IDE if you go to the sketch part and then in include libraries. Also keep in mind that if you use something like rotary encoder you will probably need to get new libraries instead of keypad, which would probably be rotary.h and button. If you use DHT11 sensor the library is still DHT.
  2. In second part of the code there will be defining of all used parts. First of all is LCD. After that there is DHT sensor which is represent like object with dht type of sensor, and also a pin that is connect. Soil Moisture sensor and diodes are third one.
  3. I will describe the keypad a little bit more. As I said my rotary encoder was broken, so I decided to use it.
    For this project it is enough to have only four buttons, even three is good for it. So I am using four buttons on keypad for just one option. You can use some of the buttons if you want for something else if you have an idea. You need to define rows and columns in this part. After that hexaKeys will represent you options used for this project. In my project there are B (back), U(up), D(down) and A(accept). You can make every button to do something else. One button could turn on backlight, one can turn it off. So feel free to play with it some more
  4. In this part are global variables used in code. Bool variables are using for screen changing. Welcome variable is true for few seconds only when the arduino i turned on, after that it will be false for the rest of the time. The main focus is on mainScreen variable. This variable is used to guide you from menu to any other option in code. If this variable is false then that means that user decided to use one of four options of this project.
  5. This is where are written all of the methods used in this code. I will try to explain all of written methods in this part
  • void startScreen(); // method for starting project and arduino
  • int choiceNumber(int choice); // this changes your choise of options of the project. Number goes from 1 to 4
  • void mainScreenP(int choice); //there will be written four options of device that is made
  • bool mainScreenCS(bool mainScreen); //this changes mainScreen to false
  • bool mainScreenBack(bool mainScreen); //this changes mainScreen to true
  • void tempCelsius(); // reading temperature in C DHT sensor option
  • void tempFarenheit(); // reading temperature in F DHT sensor option
  • void printHumidity(); // reading humidity DHT sensor option
  • void readSensorData(); // reading data on connected sensors
  • String getTemperatureC();
  • String getTemperatureF();
  • String getHumidity();
  • void soilMoisture(); // this is for another sensor and diodes
  • void printSensorSoilMoisture(); // printing soil moisture part on lcd
  • void diodeLights(int value); // turning on and off diodes
  • void printValue(int value);

6.Setup for arduino is part where you set up LCD and DHT sensor and also diodes

7.Main part is the part where all of the above written methods are used.

Full code of this project will be in attachment of this step. Keep in mind that there is possibility that the pins are maybe not connected like on the schematic, I think that the diodes are changed.

Step 4: Using Your Arduino

This is probably the funniest part. At least it is funnier after all of coding written.
In this part you can see pictures of how project works.
There are 4 options.

  1. Reading temperature in Celsius
  2. Reading temperature in Fahrenheit
  3. Reading humidity
  4. Turning on diodes and reading values of soil moisture sensor.

You can chose any of possible options, also you can go back and chose again if you want to see something else.
Simple and easy to use.

If there is any other question you can ask me.
Thank you guys for looking at my project.
With all regards.