Skip to content

Commit

Permalink
Added relay instead of battery (#2378)
Browse files Browse the repository at this point in the history
Co-authored-by: JessamyT <[email protected]>
  • Loading branch information
mestcihazal and JessamyT authored Jan 10, 2024
1 parent c71b318 commit 201e7a4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 33 deletions.
Binary file modified assets/tutorials/plant-watering-pi/full-wiring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/tutorials/plant-watering-pi/pump-motor-config-builder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/tutorials/plant-watering-pi/pump-motor-control.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 28 additions & 33 deletions docs/tutorials/projects/make-a-plant-watering-robot.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,23 @@ With a Raspberry Pi and some cheap, basic hardware, you can keep your plants hea
Follow this tutorial to learn how to set up an automatic plant watering system:

1. [Complete the physical assembly and wiring](#set-up-your-plant-watering-robot).
2. [Create and connect to the robot](#configure-the-components-of-your-robot-in-the-viam-app).
3. [Configure your robot's components](#configure-the-components-of-your-robot-in-the-viam-app).
4. [Configure the ADC as a module from the registry](#configure-the-adc-as-a-module-from-the-registry).
5. [Write code utilizing the Viam Python SDK to control the plant watering robot](#add-python-control-code).
2. [Create and connect to the robot, and configure your robot's components](#configure-the-components-of-your-robot-in-the-viam-app).
3. [Configure the ADC as a module from the registry](#configure-the-adc-as-a-module-from-the-registry).
4. [Write code utilizing the Viam Python SDK to control the plant watering robot](#add-python-control-code).

{{<youtube embed_url="https://www.youtube-nocookie.com/embed/Q6UuUKJpDn0?start=877">}}

You can also follow a simplified version of this tutorial in this video: it eliminates the need for the ADC, the breadboard, and the motor speed controller, and uses the digital pin of the moisture sensor to get “high” and “low” readings and to turn a relay on and off.
You can also follow a simplified version of this tutorial in this video: it eliminates the need for the ADC and the breadboard, instead using the digital pin of the moisture sensor to get “high” and “low” readings and to turn a relay on and off.
You can start with this simple version and then add the ADC to make your machine more accurate!

The tutorial uses the following hardware, but you can adjust it as needed:

- A Raspberry Pi 3B or 4B with SD card and [5V USB power supply](https://www.amazon.com/CanaKit-Raspberry-Supply-Adapter-Listed/dp/B00MARDJZ4)
- A [resistive soil moisture sensor](https://www.amazon.com/KeeYees-Sensitivity-Moisture-Watering-Manager/dp/B07QXZC8TQ)
- A [peristaltic pump](https://www.amazon.com/Gikfun-Peristaltic-Connector-Aquarium-Analytic/dp/B01IUVHB8E) motor and [tubing](https://www.amazon.com/dp/B08H1ZD5VZ?psc=1&)
- An [Adafruit MCP3008 ADC](https://a.co/d/csRaIHE)
- A [motor speed controller](https://www.amazon.com/High-Power-Transistor-Controller-MELIFE-Electronic/dp/B09XKCD8HS)
- A [5V mini water pump](https://www.amazon.com/gp/product/B09TGK9N5Q/) with clear vinyl tube
- A [MCP3008 ADC](https://a.co/d/csRaIHE)
- A [one channel relay switch](https://www.amazon.com/HiLetgo-Channel-optocoupler-Support-Trigger/dp/B00LW15A4W/)
- A [breadboard](https://www.amazon.com/SunFounder-Raspberry-Breadboard-solderless-Circuit/dp/B07ZYR7R8X)
- A [9V battery](https://www.amazon.com/dp/B08BRJQQSL/)
- Optional: [wire leads](https://www.amazon.com/Battery-Hard-Shell-Connector-Insulated-Wires/dp/B07WTYS1PM/) in place of alligator clips for wiring the battery
- Assorted [breadboard jumper wires](https://www.amazon.com/EDGELEC-Breadboard-Optional-Assorted-Multicolored/dp/B07GD2BWPY/), including wires with [alligator clips](https://www.amazon.com/Goupchn-Alligator-Breadboard-Flexible-Electrical/dp/B08M5P6LHR/)
- A planter box or flower pot
- A water container
Expand All @@ -58,7 +55,7 @@ Make sure your Pi is flashed with a Viam-compatible operating system, and that y
## Set up your plant watering robot

Before programming the Pi to make the plant watering robot functional, you need to physically set up the plant watering robot by wiring the different components together.
You will set up the robot to receive signals from the resistive soil moisture sensor and signal to the peristaltic pump when it is time to pump water from the water's container to the plant's container.
You will set up the robot to receive signals from the resistive soil moisture sensor and signal to the pump when it is time to pump water from the water's container to the plant's container.

### Full wiring diagram

Expand All @@ -83,19 +80,22 @@ Use this to orient the ADC to determine the location to insert your wires.
{{% /alert %}}

Insert the MCP3008 into your breadboard so that it bridges both sides of the divide.
Then, use the rows on the side of your MCP3008's pins and the GPIO pins on your PI to connect the pins with wires as follows:
Then, use the rows on the side of your MCP3008's pins and the GPIO pins on your Pi to connect the pins with wires as follows:

<!-- prettier-ignore -->
| MCP3008 ADC Pin | Raspberry Pi Pin |
| ----------- | ---------------- |
| VDD | 3.3V |
| VREF | 3.3V |
| VDD | 5V |
| VREF | 5V |
| AGND | GND |
| DGND | GND |
| CLK | SCLK |
| DOUT | MISO |
| DIN | MOSI |
| CS/SHDN | GPIO8 |
| CS/SHDN | 24GPIO8 |

Use an additional wire to wire Raspberry Pi [pin 4 (a 5 volt power pin)](https://pinout.xyz/pinout/5v_power) to the power rail of the breadboard (the red plus sign column).
This brings the 5V power output from the Raspberry Pi to the ADC and the sensor.

### Wire your resistive soil moisture sensor

Expand All @@ -106,37 +106,32 @@ Reference this diagram of the blue module part of the sensor:
![Pinout diagram for the resistive soil moisture sensor.](/tutorials/plant-watering-pi/moisture-sensor-pinout.png)

Start by connecting the female jumper wires at the end of the sensor prongs to the blue module where the diagram shown above is labeled "Connect with Probe."
Be careful of the positive and negative sides, and make sure to match them correctly.

Then, wire the rest of the pins on the module to the Pi and ADC as follows:

<!-- prettier-ignore -->
| Pi | ADC |
|--|--|
|<table> <tr><th>Moisture Sensor Pin</th><th>Raspberry Pi Pin</th></tr><tr><td>VCC</td><td>3.3V</td></tr><tr><td>GND</td><td>GND</td></tr> </table>| <table> <tr><th>Moisture Sensor Pin</th><th>MCP3008 ADC Pin</th></tr><tr><td>A0 (Analog Signal Output)</td><td>CH0</td></tr> </table>|
|<table> <tr><th>Moisture Sensor Pin</th><th>Raspberry Pi Pin</th></tr><tr><td>VCC</td><td>5V on the power rail</td></tr><tr><td>GND</td><td>GND</td></tr> </table>| <table> <tr><th>Moisture Sensor Pin</th><th>MCP3008 ADC Pin</th></tr><tr><td>A0 (Analog Signal Output)</td><td>CH0</td></tr> </table>|

Put the soil moisture sensor inside of the container holding your plant.

### Wire your pump

Now, wire and power your Peristaltic Pump [motor](/components/motor/) and [motor speed controller](https://www.amazon.com/High-Power-Transistor-Controller-MELIFE-Electronic/dp/B09XKCD8HS) to complete your hardware setup.

Reference this diagram of the motor speed controller:
Now, wire and power your pump [motor](/components/motor/) and relay module to complete your hardware setup:

![Pinout diagram for the motor speed controller.](/tutorials/plant-watering-pi/motor-speed-controller-diagram.png)

1. Attach [alligator wire clips](https://www.amazon.com/Goupchn-Alligator-Breadboard-Flexible-Electrical/dp/B08M5P6LHR/) to your battery to connect it to the DC power pins on your motor speed controller.
Match the **+** notation on the battery to the **+** DC power pin.
2. Attach [alligator wire clips](https://www.amazon.com/Goupchn-Alligator-Breadboard-Flexible-Electrical/dp/B08M5P6LHR/) to the pump to connect the output pins on your motor speed controller to the pump.
3. Connect the GND pin hole on the controller to GND on the Pi.
4. Connect the PWM pin hole on the pump to [Pin 12 (GPIO 18)](https://pinout.xyz/pinout/pin12_gpio18) of the Pi.
Note that the controller does not come with header pins.
1. Attach an [alligator wire clip](https://www.amazon.com/Goupchn-Alligator-Breadboard-Flexible-Electrical/dp/B08M5P6LHR/) to your 5V pump motor's positive wire, and connect it to the NO pin on relay module.
NO stands for normally open, which will keep the circuit open unless the pin is triggered.
2. Attach another [alligator wire clip](https://www.amazon.com/Goupchn-Alligator-Breadboard-Flexible-Electrical/dp/B08M5P6LHR/) to your 5V pump motor's negative wire, and connect it to [pin 39 (ground)](https://pinout.xyz/pinout/ground) on the Raspberry Pi.
3. Connect the COM (common) pin on the relay to [pin 1 (3.3V)](https://pinout.xyz/pinout/3v3_power) on the Pi.
4. Connect the 5V pin on the relay to [pin 2 (5V)](https://pinout.xyz/pinout/5v_power) on the Pi.
5. Connect the GND pin on the relay to [pin 14 (ground)](https://pinout.xyz/pinout/ground) on the Pi.
6. Connect the IN pin on the relay to the [pin 8 (GPIO 14)](https://pinout.xyz/pinout/pin8_gpio14) on the Pi.

{{% alert title="Tip" color="tip" %}}

To complete steps 2 and 3, you must insert the end of the jumper wires into the DC and output pin gates on the motor speed controller and tighten the screws on these gates with your screwdriver to close the wires inside.

For steps 3 and 4, note that the motor speed controller linked does not come with header pins.
You can either bend or soldier the jumper wire here to make the connection between the jumper wire and the PWM hole of the controller.
To complete the steps, insert the ends of the jumper wires into the pin gates on the relay module and tighten the screws on these gates with your screwdriver to close the wires inside.

{{% /alert %}}

Expand Down Expand Up @@ -301,7 +296,7 @@ First, add your Pi as a [board component](/components/board/) by creating a new

Then, add your pump as a [motor component](/components/motor/) by adding a new component with **type** `motor` and **model** `gpio`.

Set the motor's attributes **Max RPM** to `1000` and **PWM** to `12 GPIO 18` (the board and GPIO pin that you wired the pump's PWM to).
Set the motor's attributes **Max RPM** to `1000` and **PWM** to `8 GPIO 14` (the board and GPIO pin that you wired the relay's IN to).

{{< tabs name="Configure an Pump Motor" >}}
{{% tab name="Config Builder" %}}
Expand All @@ -323,7 +318,7 @@ Set the motor's attributes **Max RPM** to `1000` and **PWM** to `12 GPIO 18` (th
"a": "",
"b": "",
"dir": "",
"pwm": "12"
"pwm": "8"
},
"board": "local",
"max_rpm": 1000
Expand Down

0 comments on commit 201e7a4

Please sign in to comment.