Lab 7: Controlling Actuators

Control servo motors and pumps based on sensor measurements

Learning Goals

  • Create scripts and functions in Blockly
  • Learn and practice how to control actuators, servo motors, and a pump based on the sensors' measurements.

Software and Hardware

  • BlocklyProp Solo
  • Activity Board and Parallax USB programming cable
  • Soil moisture sensor
  • Temperature/RH sensor
  • Servo motor
  • Pump (peristaltic pump)
  • Outlet Power Relay Module

Hardware Components

Servo Motor

The Parallax Feedback 360° High-Speed Servo provides the functionality of a light-duty standard servo, continuous rotation servo, high-speed servo, and encoder in one convenient package.

Please note that the power switch of the activity board should be in position 2. You can connect the servo motor to one of the servo pins. Please use pins 16 and 17 and make sure the jumper is set to Vdd (regulated 5 VDC for this board). We should also provide power using a 7 Volt adaptor to supply adequate power/current for the servo.

Servo Motor Connection

Peristaltic Pump

The pump houses a flexible tube fitted in a circular pump casing. The pump works through a rotary motion that displaces the fluid inside the tube at a constant rate by squeezing fluid against the pump housing.

Peristaltic Pump Schematic

Outlet Power Relay Module

The outlet Power Relay Module (EKM-Switch120) is a power cord that switches 120 AC voltage with a DC control voltage of 3.3--60 VDC, which allows it to be controlled remotely. It has three types of outlets: always ON, normally ON, and normally OFF.

Power Relay Module
  • Always ON: it continuously gives power when the module is powered on.
  • Normally OFF: it is normally OFF. It becomes ON when the module is powered ON and the relay switch is turned ON by the activity board.
  • Normally ON: it is normally ON. It becomes OFF when the relay switch is turned ON by the activity board.

Connection: Connect the relay module to 'relay 1' socket (or 'relay 2' socket) on the green custom-designed board mounted on the activity board.

  • Relay 1 socket is connected to pin 13.
  • Relay 2 socket is connected to pin 12.
Relay Connection Method A Relay Connection Method B

Programming Assignment

Create a script that:

  1. Asks users to enter a threshold for relative humidity level and saves it as a variable called "rh_threshold".
  2. Asks users to enter a threshold for soil moisture level and saves it as a variable called "moisture_threshold".
  3. Reads RH level in percentage using temp/RH sensor and assigns it to "rh" variable; please note the temp/RH sensor is connected to PIN 14.
  4. Reads soil moisture level and assigns it to "moisture" variable; please note that the soil moisture sensor is connected to AD2 (analog to digital converter).
  5. Prints the measured value for the relative humidity (%) in the terminal.
  6. Prints the measured value for soil moisture in the terminal. Please note that the output value is voltage (volt-100ths between 0-5).
  7. Makes decisions based on the measured RH. If the measured RH is more than the defined threshold, we need to spin the servo motor 360 degrees. We assume the motor acts like a fan to vent moisture and reduce humidity in a greenhouse.
  8. Makes decisions based on the measured soil moisture level. If the measured soil level is less than the defined threshold, we need to turn ON our irrigation system (the pump).
Condition Action
Relative humidity > threshold Spin the servo motor 360° per second (fan ON). Otherwise, set speed to 0.
Soil moisture < threshold Turn on the pump until soil moisture returns to desired level.

Save your code as: Lab7_YourInitials_actuators (e.g., Lab7_AM_actuators)

Blockly Programming Blocks

Servo Motor Blocks

Servo Initialize Block Servo Speed Block Servo Position Block Servo Status Block

Peristaltic Pump Control

Set pin 13 (which is relay 1) high to turn on the pump.

Pump Control Block

Code Structure and Hints

Main Block Structure

  • Iteration = 1
  • Get the RH threshold in the terminal
  • Get moisture threshold in the terminal
  • A continuous loop (use repeat forever block):
    • Print iteration number
    • Call function that reads and prints RH sensor data
    • Call function that reads and prints soil moisture data
    • Call function that makes decisions based on RH value
    • Call function that makes decisions based on soil moisture value
    • Pause for 4000 ms
    • Increment iteration variable
    • Clear the screen

Function Blocks

You have four functions, name them as:

  • rh_sensor: reads the RH sensor data
  • moisture_sensor: reads the soil moisture data
  • servo_motor: changes the speed of the servo motor
    • If RH value > rh_threshold: Set servo speed to 360°/second & Print("Fan is ON!")
    • Else: Set servo speed to 0°/second & Print("Fan is OFF!")
  • irrigation_pump: changes the status of the irrigation pump
    • If moisture value < moisture_threshold: Make PIN 13 high & Print("The irrigation pump is ON!")
    • Else: Make PIN 13 low & Print("The irrigation pump is OFF!")

What to Submit

Submit your code saved as a *.svg file.

Naming: Lab7_YourInitials_actuators.svg