Mars has been under direct human observation since 1997 in order to see whether or not it has the capability of sustaining life. With these lessons, we are going to teach a Robit, powered by a Microbit, to travel across THE MAT to Mars and begin exploring the planet.
Part 1 Getting to Mars:
The starting point of our Robits on THE MAT is the floating mothership. We need to get our Robit to cross the black starting line, the the white starting line, cross space, and then stop at Mars.
Our Robits have sensors at the bottom of its chassis and these sense the reflected light from the surface beneath it. It only senses whether something is dark or light.
To get our Robit to understand the difference between both, we position our Robit so the sensor is above the starting black line. On Makecode, we’re going to need to import our Robit extension under Advanced > Extensions > search: Robit
When we’ve selected the extension, our workspace should load up like this:
The first thing we’ll want to do is remove our forever block and open Robit and drag out [init line follow pin] and change the J3 (P1, P2) to J2 (P15, P16) because our motors are plugged into Pin 15 and Pin 16. Init line follow pin should be put inside our on start block.
Next we’ll need to make a variable. We’ll press on our Variables tab in the side menu and select the make a variable button. We’ll name this variable ‘dark’. This is the variable that will save the value received from the light sensors at the bottom when we start, and we start on the black strip of the mothership. In order to do that, we need to go back to our Robit menu and drag out (left line follow digital pin) and place it in [set dark to ( )]. Our code will now look like this:
Next we’ll need to cross that dark stripe so we need to grab a while <true> loop from our Loops menu and put it under our set dark block.
Next we need to get an equals (=) comparison block from Logic and put it where our <true> is.
Next we need to get our round variable block for ‘dark’ and put it in the first bubble of our equals block.
The block we need to compare our dark variable to is (left line follow digital pin) so we need to get that block from our Robit menu and put it into the last bubble of our equals block. This code means that while our Robit sees ‘dark’, we want to do something. In our case, we want it to drive forward so we’ll grab our Left wheel/Right wheel block from Robit and put it inside our while loop. Our code should look like this now:
Our code will look like this now. First our Robit will cross what it knows is dark, then cross what it knows is not dark.
Next we want our Robit to cross space. Space is dark in colour so we can duplicate our dark while loop again and attach it to the very bottom. Our code will now look like this:
This last while loop will continue to work until our condition is false. In this case, our Robit should stop when it reaches Mars. Since Mars is bright compared to space, we can code our Robit to stop at the end of our last while loop by putting a Left wheel/Right wheel block in and setting both speeds to 0, or use a Motor Stop All block. Your code should look like this:
You’re done! Load your code into a Microbit and plug your Microbit into a Robit, then test it out on your mat.
So it’s not much use for our robit to explore around Mars with no way to contact earth about what it’s found. So in this lesson we will enable communication over radio waves from our microbit to another Microbit on earth.
We will inform earth about our Robit’s progress, say for when we bump into something, or we reach a dark spot. This code will be similar to Term 1’s Radio lesson, in fact the receiver on earth’s code is the exact same.
So we have two while loops nested in one another, below the while loop that controls us moving forward until we go somewhere dark or bump something we will add two Logic -> IF blocks.
Be sure that these if statements are AFTER the while loop, but before the reversing code.
Next we will want to determine why our microbit has decided to stop moving forward, either it has reached darkness, or it has been bumped.
So for darkness, we will need our dark variable, a = comparison block in logic and the left line follower digital pin block. And we will get our Radio send string block from the radio category and place that inside the IF block as well.
Then do the same for if the Robit has bumped something, so if notBumped is NOT equal to Digital read pin 13.
At the beginning the last thing we need is the Radio -> Radio Set Group ( ) block at the beginning of the code. Be sure the same group is the same between your Robit and the Mission Control Microbit.
Here we will be looking at implementing the use of the soil moisture sensor attached to the front of our Robit. It has two prongs with a strip of metal on the two sides. If electricity passes from one prong to the other then we know that it has touched something conductive.
Dry Soil itself isn’t conductive, but water is (Well, non-distilled water anyway (Distilled means without impurity)), when soil is wet/muddy it can conduct electricity, this is how the soil moisture sensor works. When placed in dry soil, the sensor will not detect electricity passing from one prong to the other, but when in damp soil it will. This is what we will code our Robits to detect and transmit to mission control on Earth.
We want our microbit to always be checking if we found moisture. In the section where we move our Robit forward we will need to make the following changes.
We will have a Logic -> IF block.
Inside the < > shaped part we will need a Logic -> “GREATER THAN >” block..
If Advanced -> Pins -> Analog Read Pin P1 is > 300 Then radio send string “Found Moisture”.
For the real Rover on Mars, it needs to be able to test many different conditions in the harsh environment on another planet. It has a retractable arm that allows the Rover to touch different surfaces with its devices in order to test things. The hinge that lets this arm move is called a servo. Basically, it’s a small motor that can rotate forward and back. For us, we want our Robits to be able to use a servo with our soil moisture detector attached to the end and accurately test soil without running into things. Think of the servo like our elbows: it allows our forearms and hands to rotate forward when we want to touch something and back when we’re done.
We want to put our servo together so our soil moisture sensor is perpendicular (at a right angle) to the paddle pop stick on the opposite side of the servo. Assemble the servo however you want so long as it has enough space for movement and nothing hinders its rotation. The soil moisture sensors should point down but if you can justify why they don’t, that’s fine too!
Once you’re happy with your servo arm, it’s time to code. Our neutral position for the servo arm is at 90 degrees. Think of a straight line - what is the angle of a straight line? The closer your number is to 90, the slower the servo arm will rotate which is really useful for carefully checking soil samples! So, if my servo arm rotates forward by 70 until it touches something, it should rotate back by 110 degrees the same amount of time in order to return to an upright position. Your code should look like this (in another project):