Introduction: Basys 3 and Arduino Soil Moisture Reader


Samuel Guerra

Ean Hendrickson

Ryan Schouten

Allen Deng

Hello! This instructable will show you how to create a soil moisture reader using a soil sensor, a basys 3 board, and an Arduino Uno. Below you will find reasons for the purpose of such a device, and how such a device can conserve resources.


This project was put together with the intent of conserving water, a resource that, given the current drought in California, is of a big concern to us. This project allows you, as the user, to monitor the soil moisture of plants in your home, or in your place of work/study. The Soil Moisture Reader is designed to help you prevent under watering and over watering.


This instructable will give you the step-by-step instructions on how to develop and build your own Soil Moisture Reader. The device makes use of a Soil Moisture Meter sensor, a basys 3 board, and Arduino Uno, and a few other intermediary materials to accomplish our goal of water conservation. The Soil Moisture Reader analyzes the moisture level of the plant soil, displays its current soil level as a percent, and informs you whether the plant needs water or not through an LED.


The Soil Moisture Reader generates an output based on the sensor reading and the user input. The user input qualitatively represents the user's desired soil moisture level. The user will input this desired moisture level on the basys 3 using the switches as designated, and the basys 3 will display the current moisture level as a percent on the seven-segment display. If the current moisture level in the soil is less than the user's desired level, an LED will turn on, signaling the user to begin watering his/her plant. As the user waters his/her plant, the sensor will continue to read the soil moisture, and once the moisture reaches the user's desired moisture level, the LED will turn off, signaling to the user to stop watering.

Step 1: Materials

To build your own Soil Moisture Reader, you will need the following:

  • 1 Digilent Basys 3 FPGA Board

See attached document for details on how to download the necessary software

  • 1 Arduino Uno
  • 1 Soil Moisture Meter Sensor
  • Wires
  • 1 LED (green)

Step 2: Black Box Diagram

In order to help guide the design and organization of our project, we created a black box diagram to visually give an overview of how the circuitry of the Soil Moisture Meter should be implemented. You can find our black box diagram attached, and use it as a guide for your own creation of this project.

The black box diagram includes the inputs and outputs of each module in the circuit, as well as the type of module that will need to be designed. The modules are represented as boxes, with each box having its own set of corresponding inputs and outputs.

FF: This box represents the set of 7 D flip-flops that we used to store the user input as memory. The module has three inputs: 7-bit user input, an enable, and clock. We will go into detail of the significance of these inputs at a later time. The flip-flops output a 7-bit signal.

Ard: This box represents the Arduino Uno that we used intermittently between the soil sensor and the basys 3 board. The arduino serves the purpose of translating the analog moisture reading of the sensor into a digital value that the basy3 can interpret.

Mult: This box represents the multiplier that we designed. This multiplier takes in the sensor data as an input from the arduino, and essentially converts this input to a 7-bit output representing a percentage.

Comp: This box represents our comparator, which takes in as inputs the output of FF and the output of Mult. The comparator outputs a one bit signal, the result of the comparison being made.

SSEG: This box represents the module that displays the soil moisture on the basys 3 board. The seven segment takes in the 7-bit output from the sensor and displays that data as its output.

Step 3: Arduino Uno Soil Measurement

The purpose of the Arduino Uno in our project is related to the type of Soil Moisture Meter sensor that we used in our design. The Soil Moisture Meter was designed to be used concurrently with the Arduino Uno, as the Soil Moisture Meter sensor outputs an analog value rather than a digital one. The basys 3 board cannot read this analog value as we need it to, since the basys 3 board can only take in digital values. It is for this reason that we needed to include the Arduino Uno as a part of our circuit; there were other, more complicated ways to accomplish this analog to digital conversion, but using the arduino was the most efficient for our design.

Because the Arduino Uno acts as a micro-processor, the coding and implementation of the arduino differs from that of the basys 3. Coding the arduino requires writing actual software, as coding the basys 3 requires CAD. We have attached the corresponding arduino software responsible for taking in the analog moisture reading and outputting a digital value to the basys 3.

Step 4: D Flip-Flop VHDL

For this memory-saving module we structurally combined a set of 7 D flip-flops, with each flip-flop storing 1 bit of the 7-bit input. One D flip-flop takes in 3 inputs, clk, D, and Enable, and outputs Q. Q gets fed back as input D, allowing for the "storing" of data necessary in our design. We have provided the source code for a single D flip-flop so you can see how this works. Using 7 D flip-flops allows us to store each bit of data coming from the user's input.

To say these flip-flops were combined structurally refers to the way the VHDL was implemented. As you'll see from the source code we have provided, structural logic involves using port mapping to "map" signals of one piece of circuitry within a module to another piece within that same module.These signal mappings represent the connections of wires from one piece of circuitry to another.

Step 5: Multiplier VHDL

The next step toward developing the Soil Moisture Reader is to implement a multiplier in VHDL. The purpose of the multiplier is to multiply the sensor reading by a certain factor in order to scale the input to a value the basys3 can efficiently work with. Essentially, when using the 3.3 Volt power, the arduino will output a range of 675 to zero (in binary). We want to multiply the sensor data by .144 to put it on a scale of 100 to 0, but we can't multiply by decimals. As a result, we mulitplied the sensor data by 144, and then outputted only the first two decimal numbers to put the output on a scale of 100 to 0.

The multiplier multiplies the sensor data by 144 using a shift and add technique. Our multiplication ideally produces a range from 100000 to zero (in binary). We used a binary to Binary-Coded-Decimal (BCD) converter from to separate the first two decimal numbers from the rest of the numbers from the multiplication. Once we have only the first two digits in BCD, we used a BCD to binary converter to output the soil moisture percentage as a binary number.

Step 6: Seven-Segment Display VHDL

The seven-segment display is one of the elements on the basys 3 that allows us to physically represent some of the intricate processes involved in the circuitry of our Soil Moisture Reader. As we mentioned earlier in this instructable, the seven-segment display will display the current reading of the soil sensor. The soil sensor is constantly taking in measurements, so the display is subject to change. However, it is the nature of these constant measurements that allows us to inform the user when to stop watering their plant.

The VHDL that we have attached for your reference is not of our own composition. The code for this module, in its entirety, belongs to our instructor Professor Danowitz. This module was given to us earlier in the course to be used in one of our labs, and we were given permission to use it in this final project as well.

The seven-segment VHDL acts as a driver responsible for taking in the data from the multiplier and displaying it on the board. The module also allows the displayed value to change as the output from the multiplier changes. Each of the 7 individual segments on the display depends on the anode they are connected to. When this anode goes high, the appropriate segments will light up.


Step 7: Comparator VHDL

The final piece of the Soil Moisture Reader puzzle is the implementation of a comparator that takes in the outputs from the multiplier and the D flip-flops to generate our final output: the water/don't water signal in the form of a green LED. We implemented this comparator using behavioral logic, which, as you will be able to see from our attached file, is a very straightforward method of VHDL.

The comparator, as its name implies, makes comparisons between the two inputs, particularly comparisons of these inputs' values. The Soil Moisture Reader will shine the green LED if the soil needs water, which translates to the user input value being larger than the sensor reading value. Conversely, if the user input value is equal to, or less than, the sensor reading value, the LED will not light up. The comparator takes care of translating this equality/inequality into a meaningful output.


Step 8: Creating Your Master File

The last crucial step in developing your Soil Moisture Reader is creating a master file to combine all of your circuit elements together. For our master file, we used structural modeling and intermittent signals to wire our D flip-flops, Multiplier, Comparator, and Seven-Segment Display together, in the appropriate sequence.

As you can see from our attached file, the master file itself contains a series of inputs and outputs; these inputs and outputs are relevant to the system as a whole. It is crucial that any inputs and outputs taken in or generated within the circuit are somehow represented in this master file, or else the code will not run as it is intended.

As stated above, all the modules developed earlier are combined in this master file via structural modeling. This form of logic takes the outputs from each module and maps them as inputs to the successive appropriate module. The easiest way to help you keep track of which outputs should be mapped where is to refer back to the black box diagram we put together in Step 2. This visual representation of the Soil Moisture Reader circuit allows you to follow along where the signals leave and enter. One note of caution: the elements combined in the master file only refer to the modules developed in VHDL. For example, the Arduino Uno code we wrote earlier does not belong in this master file.

Step 9: Wiring Together All of Your Hardware

While making sure all your code and VHDL is written properly and makes sense in the context of digital design, its is important to remember that the circuit constructed digitally represents, and can be translated, into physical hardware. For the purposes of your Soil Moisture Reader, the project has to physically be wired together properly.

As we stated earlier, the materials needed to physically represent the Soil Moisture Reader involve a basys 3 board, an Arduino Uno, a set of several wires, an LED (we used a green one), and a Soil Moisture Meter sensor. The Soil Moisture Meter sensor wires to the Arduino; wires are then attached from the Arduino to ports of the basys 3, and the LED is attached directly into one of the ports on the basys 3 board.

As you will see from the pictures we have attached, it does not necessarily matter what pins you choose to place your wires into on the Arduino and the basys 3 board. However, it is important to keep track in your constraints file which output signals to assign to which ports on the basys 3. We have attached the constraints file that we used for our Soil Moisture Reader so you can see how signals from our VHDL match up with pins on the basys 3 board.

Step 10: Test Your Project Out

If you've made it to this last step, congratulations!! This is the moment of truth, the ultimate final test of whether or not your Soil Moisture Reader functions as we have designed it to. If all of your code was written correctly and the project was set up as we have intended, it should look and function like the attached picture.

As you can see, the Soil Moisture Meter sensor gets stuck directly into the plant. For best readings, make sure to stick your sensor as deeply into the soil as possible. With the basys 3 board and the Arduino Uno both on and programmed, you should see the segment display on the basys 3 light up and display the current moisture reading as a percent. You will notice that the number on the display may toggle and change a bit; do not worry, this is solely as a result of the sensor settling at a moisture level as it constantly takes in data.

The next step in testing your Soil Moisture Reader's functionality is to input a certain moisture level on the switches. We have attached a table for your convenience the binary representation of the percentages 10-90. Use this table to properly input a soil moisture level. If the number being displayed on the board (which corresponds to the current soil moisture reading) is below the number you have input, the green LED will light up, telling you to water the plant. Hopefully everything is working up to this point.

The last functionality that you'll want to test is that the sensor updates the soil moisture reading on the board as you water the plant. Pouring water onto the soil should cause the display number to increase, and once that number increases past the number you have input on the switches, the LED should turn off. This is signalling to you that you should stop watering. You may have to repeat this process a few times, as you'll probably notice (as we did) that it takes more water than you'd expect to increase the soil moisture level to your desired one.

We greatly appreciate the time you have spent reading through our intstructable, and we hope that, if you chose to implement this design, your project works out just as well as our did. Thanks for reading!