Challenge 1
Water three plants in a row, and nothing in between. Set them out with clear gaps. Run the robot along the row. Count three squirts for three plants. There must be nothing at the gaps, and nothing at the end of the row.
Quick Learn — the model, the instructions, the program and the challenges. The theory is in Full Lesson.
EV3 Robotics›Level 2 · Intermediate›Lesson 44
Level 2 · Lesson 44 · EV3-L02-4460 minutes · Ages 8+ · Model: EV3 Garden Robot
The Garden Robot: a machine that drives along a row of plants. It finds each plant with its Ultrasonic Sensor. When it is in the right place, it works its watering arm.
At first you will think, “water when something is close”. Try it. The robot waters the plant. Then it keeps watering as it drives past. Then it waters the wall at the end of the row. Then it waters you!
“Close” is not one number. A plant is about ten to thirty centimetres away. Nearer than that is the edge of the pot. Further than that is the next row. The robot needs a band: a gap between two numbers.
Parks, farms and golf courses water their plants by machine. Some sprinklers run on timers. Some pipes drip water along rows of vegetables. More and more machines now choose for themselves where to water, and how much.

Watering the wrong thing is a problem. Water costs money. Wet paths get green and slippery. One plant can get too much water and drown. The plant next to it goes thirsty. So these machines almost never use a rule with just one side.
A greenhouse machine does not just water when the soil is dry. The soil must be dry and the air not too hot or cold and it must not be midday. Each of those has a bottom number and a top number.
Say your rule only has a top number. Then it fires at everything under it. That includes things far too close to be what you meant. Flip the rule round, and it fires at everything else in the world. One number splits the world in two halves. The thing you want is almost never a whole half.
Real things sit between two numbers. If your rule has only one number, ask what is on the other side.
One and, two comparisons, one sensor. You get a band of distances the robot cares about. It ignores everything outside the band.
The bottom number is the floor. The top number is the ceiling. The space between them is called a window, or a range. One number on its own is called a threshold.
<<([4 v] distance in [cm v]) > (10)> and <([4 v] distance in [cm v]) < (30)>> :: operators
There is no new block here. It is the distance block from the Radar in Level 1, Lesson 41. Then the comparison from Lesson 6 and the and from Lesson 14. You just put them together.
| Reading | > 10? | < 30? | In the window? | What it probably is |
|---|---|---|---|---|
| 4 cm | no | yes | no | The edge of the pot, or the robot’s own arm. |
| 18 cm | yes | yes | YES | A plant. Water it. |
| 55 cm | yes | no | no | The far wall, or nothing at all. |
| 250 cm | yes | no | no | Empty air. That is the most the sensor can read. |
Look at the first and last rows. A rule of just “closer than 30” would water the edge of the pot. A rule of just “further than 10” would water empty air. You need both together to find a plant.
Measure. Do not guess. Put a plant where it will really be, and read the sensor. Then move the plant a little nearer, and a little further, and read it again. Pick a floor and a ceiling well outside those numbers. If the window is a tight fit, the robot will miss plants that are a bit out of place. And every plant is a bit out of place!
The Ultrasonic Sensor measures distance. It sends out a burst of sound too high for people to hear, listens for the echo, and works out how far away the surface is from how long the echo took — exactly how a bat finds a moth, and how a submarine uses sonar.
| Block | What it does |
|---|---|
([4 v] distance in [cm v] :: sensors) | Reports how far away the nearest thing in front of the sensor is, as a number in centimetres. |
wait until <([4 v] distance in [cm v] :: sensors) < (15)> | Holds the program until something comes closer than 15 cm. |
This is the important step up from the Touch Sensor. Touch gives you true or false; the Ultrasonic gives you a number, and the deciding is left to you. Pick a threshold below and watch where the robot ends up.
The black line on the bar is the threshold; the blue fill is the reading. The robot stops the instant the fill crosses the line.
Three different robots, and only one number is different between them. That is what having a number rather than a yes-or-no buys you: the behaviour is tuned by editing one slot, not by rebuilding the program. It also means the sensor can never tell you it is “close” — close is a decision you make about a reading.
Car parking sensors, automatic doors at a shopping centre, and the sensor that stops a lift door closing on somebody all work this way. Reacting before contact is what makes a machine feel safe.
The Home/Retail EV3 set (31313) ships an Infrared Sensor and a Beacon in place of the Ultrasonic and Gyro sensors. The Infrared Sensor also measures distance, so the programs in this module work with it — but it reports a rough 0–100 proximity rather than real centimetres, and it is affected by sunlight and by dark surfaces in ways the Ultrasonic is not.
A threshold splits the world in two. A window picks one thing out.
A sensor that reports a number cannot be used to make a decision on its own — 23 is neither true nor false. An operator turns that number into an answer by comparing it with something.
| Block | What it does |
|---|---|
<(x) > (50)> | True when the left value is bigger than the right. |
<(x) < (50)> | True when it is smaller. |
<<> and <>> | True only when both conditions are true. |
<<> or <>> | True when at least one of them is. |
Forget the symbols for a moment. A comparison is a question about position on a number line: is x to the left of the other number, or to the right? Left is smaller, right is bigger — and that is the whole of it.
Drag the orange x and the black marker, and change the comparison. The green stretch is every position of x that would make the answer true — so you can see where the answer flips before you get there. Turn not on and watch the green jump to the other side.
Drag either marker, or use the arrow keys.
is x to the LEFT of it?
The lab above asks one question at a time: is this x true? A robot never has just one x, though — a sensor reading slides up and down all the time, so what really matters is which stretch of the line makes the condition true. This one draws the whole answer at once.
Drag the circle to move the number you are comparing against, and change the comparison. Everything shaded green is a value of x that would make it true.
Drag the circle, or use the arrow keys. It moves in steps of 0.2.
Every number to the left of 0.2 — but not 0.2 itself, so the circle is hollow.
Watch the circle, because it carries the part everyone gets wrong:
Now turn not on with x > 2 selected and watch two things happen together. The shading jumps to the other side, and the circle fills in — because “not greater than 2” means 2 or less, and 2 has to be part of it. That pairing is the whole reason a hollow circle is worth drawing.
Why a robot cares. Two conditions that look almost identical — light < 30 and not (light > 30) — differ by exactly one value, the reading of precisely 30. A robot sitting right on its threshold behaves differently under the two, and that is the sort of bug that only shows up occasionally and looks like a broken sensor.
These three join answers together rather than numbers. The trap is that English is looser than a program: “stop if it is close and the bumper is pressed” sounds like it covers both situations, when it covers neither on its own.
Flip the two conditions and watch the table. There are only four possible situations in total, and and and or differ on exactly two of them.
| close | bumper | and | or |
|---|---|---|---|
| true | true | true | true |
| true | false | false | true |
| false | true | false | true |
| false | false | false | false |
and is fussy: it wants both. Three of the four rows are false.
Two sensors are running below: an Ultrasonic reporting a number, and a Touch Sensor reporting true or false. Watch the comparison turn the number into an answer, and watch and and or disagree.
and was true in one row out of four. or was true in three. That is the whole difference, and it is why one of them makes a robot look broken.
The comparison is doing one job: it takes a reading that is neither true nor false and, by holding it against a number you chose, produces something a decision can use. The moment the blue fill crosses the black marker is the moment the answer changes.
The number you compare against is a design decision, not a fact. “Close” for a parking sensor might be 15 cm; for a robot arm it might be 3. Pick it by measuring what the sensor actually reads in the situation you care about, then leave a margin.
and narrows: both must hold, so the robot acts less often but more certainly — stop only if something is close and the bumper is pressed. or widens: either will do, so the robot acts more readily — stop if something is close or the bumper is pressed.
In the four situations above, and was true in one of them and or in three. That is the practical difference: swapping one for the other does not adjust a robot slightly, it changes how often it reacts at all.
Say this back before you move on: “Not too near and not too far.”
| Part | What it is doing here |
|---|---|
| EV3 Intelligent Brick | Reads the sensor all the time. For each reading, it decides if it is looking at a plant. |
| Large Motor — the travel | Moves the robot along the row. Slowly! A fast robot drives past the window before it has time to notice it. |
| Medium Motor — the watering arm | Works the arm, tap or pump. It runs only while a plant is in the window. |
| Ultrasonic Sensor | Faces sideways, at the plants, not forwards. It looks across the row, not along it. |
Test without real water. Let the robot move an arm and beep when it finds a plant. That is much easier to fix than a robot that gets things wet. Once the program is right, you can add real water.
Sensors go in ports 1, 2, 3, 4. Motors go in ports A, B, C, D. You cannot swap them. If you do, nothing warns you. The robot just will not work.
| Part | Port | Why this one |
|---|---|---|
| Travel motor (Large) | A | Moves the robot along the row. |
| Watering (Medium) | D | The other end of the Brick. Its cable stays far away from where the sensor looks. |
| Ultrasonic Sensor | 4 | Ultrasonic is always port 4 in this course. |
Check your own build now:
Two routes, and either is fine. USB is the reliable one and the one to fall back on when a room’s Bluetooth is busy; Bluetooth leaves the robot free to move, which some models need.
Do these in order. Naming the Brick after you go looking for it in the list is how groups end up driving each other’s robots.
EV3 until somebody changes it.EV3.The two failures, every class, every time. The Brick has gone to sleep while you were building — press the centre button to wake it. Or you have paired with the group at the next table, which is why the name matters.
The long version, including Port View and how to read the port tiles, is in the Brick & Bluetooth guide.
Use Bluetooth. The robot drives along a row. A cable lying across the row is one more thing the sensor can see.
Use the same row of plants and the same starting point every run. Count how many plants got watered and how many did not. That is your score.
> (10) half. Now you only have closer than 30. Put your hand right in front of the sensor as it passes. It waters your hand.< (30) half instead. Now it waters all the way along, even the empty air at the end.Steps 3 and 4 together are the real lesson. Too small, and you miss real plants. Too big, and you water the wall. The right window fits your row, with some space to spare. The only way to find it is to measure, then try.
Every sensor rule should make you ask: what is on the other side of this number?

Build the model before you read any further. Everything after this is about making it do something, and none of it will make much sense with nothing on the table in front of you.
One page at a time — use Next and Previous, or the ← → keys. Fullscreen makes it big enough to build from.
The same build on Google Drive — sometimes a video, sometimes a scan:
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Check the finished build against the picture before you switch anything on. A motor mounted the wrong way round is far easier to spot now than it is to debug later, when it looks like a program fault.
Drive slowly along the row. Water only things that really are plants.
when program starts :: events hat
clear display :: display
write [GARDEN] at line (1) :: display
[A v] start motor at (20) % speed :: motors
repeat (60)
write ([4 v] distance in [cm v]) at line (3) :: display
if <<([4 v] distance in [cm v]) > (10)> and <([4 v] distance in [cm v]) < (30)>> then
write [WATERING ] at line (5) :: display
[D v] start motor at (60) % speed :: motors
play beep (70) for (0.1) seconds :: sound
else
write [SEARCHING] at line (5) :: display
[D v] stop motor :: motors
end
wait (0.2) seconds
end
[A v] stop motor :: motors
[D v] stop motor :: motors
write [DONE] at line (7) :: displayand. Both halves must say yes before anything gets watered.What success looks like: the robot rolls along. The watering motor runs in short bursts, one burst per plant. Each burst starts as the robot reaches a plant and stops as it leaves. Between plants, and at the end of the row, nothing happens.
Does it water all the time? Your ceiling is too high. The gaps between plants are inside the window. Read the screen as the robot drives between two plants. Set the ceiling below that number.
Work through them in order — each is harder than the last. The extra challenge comes after all three, and it is meant to make you plan before you build.
Water three plants in a row, and nothing in between. Set them out with clear gaps. Run the robot along the row. Count three squirts for three plants. There must be nothing at the gaps, and nothing at the end of the row.
Find your window by measuring, not guessing. A window is the range of readings that count as a plant. Write down the sensor reading next to a plant. Then between two plants. Then at the empty end of the row. Use those three numbers to choose a floor and a ceiling. The floor is the lowest reading that counts. The ceiling is the highest. Say why you chose each one.
Break it on purpose, twice. First make a window so narrow that it misses real plants. Then make one so wide that it waters the wall. Report the numbers for each one. Say what went wrong each time.
Water a garden where the plants are not all the same. Set out a row of plants of different sizes. Put them at different distances from the robot's path, like a real flower bed. One window will not catch all of them without also catching something it should not. Measure first. Write down the sensor reading for every plant and every gap. Put them in a table before you write any blocks. The table tells you if one window can work at all. Then build the best rule you can. It may need more than one window. It may need a window plus something else. You might find that no rule can tell your plants from your gaps. That is a fair answer, as long as your table proves it. Answer two questions when you show it. Which plant was hardest to catch, and why? Also, your robot only uses distance to decide. Name one other thing it could measure to tell plants from walls better.