Micro:bit Picosat Series - Sensor Module #1 - How-to

How to use the Sensor Module #1 for the Picosat kit.

picosat_kit_024.jpg
  1. Connect the Micro:bit and the Sensor Module into the slots as shown on the left.

  2. Place two AAA batteries into the battery holder making sure the orientation of the battery is correct.

  3. Using the USB cable and connec the Micro:bit to the computer. When connected in Windows for first time there will be a display for drivers install.

  4. Startup Google Chrome internet brower and go to the website https://makecode.microbit.org/#

  5. Time to code!

    1. In this basic first series of code, we will first identify we are receiving electrical signals from the analog input pins. This invovles using serial write to write out the values read from the analog pins. We will also incorporate LED display to show visually the program is looping.

      Click on menu item Basic -> drag and drop show icon to the forever loop.

1_animation.gif

5.2. Time to code the analog read and the serial write.

The sensors are linked to the following pins:

P0 - MQ4 Methane Gas sensor

P1 - Humidity sensor

P2 - Photodiode

First, lets add a serial write

2_serialWrite.gif

Then insert an analog read and reference P0 pin to read from. And let’s rename the variable to MQ4.

What does this line mean? On pin zero, there is an electrical signal being sent by our sensor to the Micro:bit. The Microbit will now interpret the electrical signals coming from P0 as MQ4.

We will return to this later as the values have a no human understandable meaning at the moment. They simply refer to voltages. The voltage value being read is varied as the sensor is affected by the environment and the internal resistance of the sensor is changed, which affects the voltage values.

3_analogRead.gif

Lets complete this section of coding by copy and pasting the serial write line just then, twice, so there is a serial write for our pin one and pin two. Copy/paste can work using Ctrl-C and Ctrl-V or Right Click and select Duplicate.

This completes the coding exercise and possibly your first use of the Graphical Style programming envrionment.

4_copypaste.gif

6. It’s time to upload the code to the Micro:bit and see some results.

Make sure the Micro:bit is connected to the computer. If you’re working with Google Chrome, pair the device by clicking on the cog wheel on the top right, and select “Pair Device”. A window will pop up with a list of the device to pair. Select the device and click ok.

Now click on download button on the bottom left. Several possiblities can arise depending on whether the computer can detect the Micro:bit.

It may pop up suggesting it is not connected, which means you will run into a dialog box to save a .hex file. This needs to be saved in the Micro:bit folder.

As seen below, it’s possible to save the .hex file to the Micro:bit which will appear as a drive in Explorer.

5_ShowConsole.gif

Once saved, the window will refresh and reveal a button “Show Console Device”. Click on this to reveal the next page which is a graph and text print out of the values from each of the pins which are also labelled now.

If you cover the photodiode, you will notice the value is increasing and if you shine the sensor into a ligh source such as a torch it will decrease.

7. Congrats on getting through this first part and also covering much of the basics of Micro:bit programming and file transfers. We will look at data translation in another how-to to convert these values to a human understandable number.