PROJECT Nº 1: Automatic watering for a plant

Learn to build and program an automatic watering system for a small plant using the components of the Maker Control Kit and Maker Kit 1.

First, use the ground humidity sensor to measure the humidity of the earth. Then, use the measurement obtained to indicate when the system should water the plant. It’s that easy!

EXERCISES INDEX:

  • Exercise 1.1: Measure the ground humidity
  • Exercise 1.2: Create an automatic watering system

Exercise 1.1: Measure the ground humidity

Use the soil moisture sensor and the 4in1 Build&Code board to measure the humidity of the soil. That way, you will know when the plant has enough water and when it does not.

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 20 min.

MATERIALS:

  • 1 Soil moisture sensor
  • 1 Plant (small)
  • 1 4in1 Build&Code board
  • 1 USB – Micro USB cable
  • Computer

What is a ground humidity sensor?

A soil moisture sensor is a small sensor that measures the humidity of the soil that it touches. After taking the measurement, it emits an analog signal proportional to the humidity of the soil.

The soil moisture sensor is used by inserting its two gold points into the soil until the gold surface is completely below the soil.

CONNECTIONS:

Connect the soil moisture sensor to the analog port A0 on the 4in1 Build&Code board.

Look at the colors of the cables and the colors of the terminals on the 4in1 Build&Code board to guide you. Every cable must be connected to its color:

PROGRAMMING CODE:

The program consists in seeing the amount of humidity in the soil on the computer. It should be a value between 0 and 100.

The humidity sensor will measure the humidity in the soil at a value between 0 and 1023. Then, you must find this number’s equivalent on a scale from 0 to 100. To do this, use the following formula:

Maximum value of the sensor / Maximum value on the new scale = Scaled value

1023 / 100 = 10.23

You will use the following formula in the program:

Humidity sensor reading / 10.23 = Value on a scale from 0 to 100

You can do this activity by using Arduino and Bitbloq software, as well as other compatible block programming software. Below you will find the programming code needed for each software.

Arduino Code

  1. Download the Arduino software and go through the installation process.
  2. Open the Arduino program, and once in, copy the following program:
    int PortSoil = A0, SoilSensor; // Analog port of the soil moisture sensor; dependent on the data reading on a scale from 0 to 1023.
    float Moisture; // Value of the soil humidity on a scale from 0 to 100
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin (9600); // Configuration for values readings
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      SoilSensor = analogRead (PortSoil); // Sensor amount readings on a scale from 0 to 1023
      Moisture = (SoilSensor / 10.23); // Saved and conversion from amounts to a scale from 0 to 100
      Serial.println(Moisture); // Show the value of the plant's humidity on a scale from 0 to 100 on the screen
    }
    
  3. Configure and load the code, following the instructions indicated in the document First Steps for the 4in1 Build&Code board.

Code for compatible block programming software

  1. Download the software and go through the installation process.
  2. Open the program, and once in, copy the following code:
  3. Configure and load the code. Below we show you which options you should select:
    3.1 Select the type of board that you are going to use. If using the 4in1 Build&Code board, you should select:

    Boards → Arduino Uno

    3.2 Select the port to which the 4in1 Build&Code board is connected:

    Connect → Serial Port → COM (the number where the board is connected)

    3.3 Insert the communication program between the program and the 4in1 Build&Code board:

    Connect → Upgrade Firmware

  4. Then click the green flag to start the program.

BitBloq Code

  1. Get the BitBloq software.
  2. Open the BitBloq program, and once in, copy the following code:
    • Hardware
    • Software
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

MEASURING:

Once the soil moisture sensor is connected to the soil and the 4in1 Build&Code board, and the program is loaded onto the board, measure the humidity of the soil without watering the plant. Take the measurement for a few days without watering it and write down the value shown by the humidity sensor.

When you have taken note of the value, water the plant manually, without getting water on the humidity sensor. Measure the humidity of the soil again and write down this new value.

RESULT OF THE EXERCISE:

Now that you have the values shown by the soil moisture sensor noted, you know when it is necessary to water the plant and when it is not.

Do exercise 1.2 to build the automatic watering system.

 

Exercise 1.2: Create an automatic watering system

After putting exercise 1.1 into practice, build the automatic watering system. You will use the values obtained from the soil moisture sensor in exercise 1.1 to know when it is necessary to water the plant and when it is not.

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 60 min.

MATERIALS:

  • 1 Soil moisture sensor
  • 1 Plant (small)
  • 1 Servomotor
  • 1 White LED
  • Material to make the watering structure
  • Adhesive
  • 1 Plastic cup
  • 1 4in1 Build&Code board
  • 1 USB – Micro USB cable
  • Computer

CONNECTIONS:

  1. Connect the soil moisture sensor to the analog port A0 on the 4in1 Build&Code board.
  2. Connect the white LED to digital port 4 on the 4in1 Build&Code board.
  3. Connect the servomotor to digital port 9 on the 4in1 Build&Code board. The color coordination to connect the servomotor to the 4in1 Build&Code board is: brown – black, red – red, and orange – yellow.

Look at the colors of the cables and the colors of the terminals on the 4in1 Build&Code board to guide you. Each cable should be connected to its color:

 

BUILDING THE STRUCTURE:

To build the watering system, you will use wide wooden sticks and a plastic cup.

Download the quick assembly guide and follow the steps shown.

With the system’s operation in mind, you can create another structure to your liking.

PROGRAMMING CODE:

The program consists in activating the automatic watering system, following the signal emitted by the soil moisture sensor.

If the signal shows a value less than the value that indicates the plant needs water, the automatic watering system will be activated.

If the signal shows a value greater than the value that indicates the plant has enough water, the automatic watering system will be deactivated.

You can do this activity by using Arduino and Bitbloq software, as well as other compatible block programming software. Below you will find the programming code needed for each software.

Arduino Code

  1. Download the Arduino software and go through the installation process.
  2. Open the Arduino program, and once in, copy the following program:
    #include <Servo.h>
    int PortSoil = A0, SoilSensor; // Analog port of the soil moisture sensor; dependent on the data reading on a scale from 0 to 1023.
    float Moisture; // Value of the plant humidity on a scale from 0 to 100
    int LED = 4; // Digital port of the LED
    int Degree ; // Dependent on the servomotor degrees
    Servo motor1; // Declare the servomotor as motor1
    
    void setup() {
      // Put your setup code here, to run once:
      Serial.begin (9600); // Configuration for amount readings
      motor1.attach (9); // Digital port pwm 9 where servomotor 1 is connected
      Degree = 15; // Servomotor at 15º
      motor1.write (Degree); //
    }
    
    void loop() {
      // Put your main code here, to run repeatedly:
      SoilSensor = analogRead (PortSoil); // Sensor amount readings on a scale from 0 to 1023
      Moisture = (SoilSensor / 10.23); // Saved and conversion from amounts to a scale from 0 to 100
      Serial.println(Moisture); // Show the amounts of the plant's humidity on a scale from 0 to 100 on the screen.
      if(Moisture < 50) // If the amount of Moisture is less than 50
      {
        digitalWrite (LED, HIGH); // LED = ON
        for(int x=0; x<25; x++) // Move the servomotor 25 times at intervals of 5 degrees every 0.1 seconds so that the cup pours water.
        {
          motor1.write(Degree); // Servomotor = degrees of Degree
          Degree = Degree+5; // Degree increased by 5 degrees
          delay(100); // Wait time of 0.1 seconds
        }
        delay (2000); // Wait time of 2 seconds
        Degree = 15; // Degree is equal to 15 degrees
      }
      else // If the reading of Moisture is greater than 50
      {
        motor1.write(15); // Servomotor at 15 degrees
        digitalWrite (LED, LOW); // LED = OFF
      }
    }
    
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

Code for compatible block programming software

  1. Download the software and go through the installation process.
  2. Open the program, and once in, copy the following code:
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

BitBloq Code

  1. Get the BitBloq software.
  2. Open the BitBloq program, and once in, copy the following code:
    • Hardware
    • Software
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

RESULT OF THE EXERCISE:

After getting the readings from the soil moisture sensor, you know when the plant needs water and when it has enough. Based on these values, the automatic watering system will water the plant when necessary. Now you have your own automatic watering system!

1 0

0