---
title: "Activity: Seed Planter"
date: "2023-10-31"
categories: ["Activities", "All", "Simulator Activities"]
tags: ["Colour Sensors", "Branching", "Iteration", "Algorithm Design", "Advanced"]
excerpt: "Use the seed planter attachment to start your own little garden. Organise your garden layout and have the rover precisely deposit seeds in soft soil. Cover it up as you go, and finish with some water! SetupFor this task, you must purcha"
featuredImage: "/images/resources/activity-seed-planter.jpg"
---

Use the seed planter attachment to start your own little garden. Organise your garden layout and have the rover precisely deposit seeds in soft soil. Cover it up as you go, and finish with some water!

### Setup

For this task, you must purchase some garden seeds of your choice, research planting conditions, and find how far apart seeds must be planted. Prepare a garden bed or ground area to ensure the soil is tilled and soft. Get two long beams of solid material and lay them parallel to the rover tracks (the rover will use these like a train).

The seed planter attachment works by rotating the seed barrel so that seeds are loaded in it. Next, the barrel rotates out so the loaded seeds deposit into the planting cone. The attachment then drives the cone into the ground, pushing the seeds into the dirt.

Once all the prep is done, load the seeds into the seed tank on the attachment and program the rover to move and plant them at the correct intervals. Once a row is complete, move the beams to the next row and go again. Repeat until your garden bed is complete!

Note that the height of the planting cone may need to be adjusted depending on how high the robot is from the soil.

### Here’s Our Approach

**Constant -** A constant is a variable that never changes when the code is run. In python, we write this in all capitals with underscores between words.

#### 1) Setting the Constants:

![](/images/content/76c398-constants.jpg)

Start by making constant variables to store the up and down positions for the cone servo

The constants we have provided might need to be tweaked for your specific rover. This can be done through trial and error to find the best values for you.

#### 2) The Plant Function:

![](/images/content/fb0607-plant-function.jpg)

A ‘*plant’* function should also be made to perform the whole act of planting a single cell. First, the cone is moved to the down position. Next, if the count is even, the barrel spins clockwise, otherwise it spins counterclockwise. This is to prevent the seeds from jamming. Then, the barrel is stopped, the cone comes back up, and the rover drives forward to the next cell.

#### 3) Prepare the Servos:

![](/images/content/5ea32d-servo-prep.jpg)

Back in the main code, the servos should be initialised to the ‘cone_up’, and off positions. This is to ensure the servos are in the correct positions before starting. Add a 1 second delay to allow the servos to settle.

#### 4) The Planting Loop:

![](/images/content/ef68a1-loop.jpg)

Finally, create a loop that will execute several times (20 in this example), corresponding to how many seeds you want to be planted. We will store the amount of times looped in a variable called ‘count’. Inside this loop, run the ‘*plant’* function with and input of ‘count’ This means that the barrel will spin back and forth every time the robot plants a seed.

#### Complete Code:

![](/images/content/ce5ea2-complete-code.jpg)

**Tip:** 

Try making your own seed barrel and cone with different-sized holes for your different seeds. That will help you add a bit of variety to your garden!
