Table of Contents

Objective

This lesson will show you how to program the mBot Neo to follow a line. It will then show you how test your program on the mBot Neo.

Parts Required

The parts below are required to complete this lesson. Note that all parts are included in the mBot Neo kit that can be purchased on Amazon.

  1. Assembled mBot Neo from Lesson 1
  2. USB Cable
  3. Line following paper
  4. Styrofoam Blocks that are at least 5in tall and 2in thick

Software Programming

  1. Connect the USB cable to the CyberPi on the mBot Neo and plug the cable into your computer

    This will charge up your mBot Neo while you create the program

  2. Open the mBlock app on your computer

    You can download the mBlock app from mBlock Download if it isn't already installed

    Open mBlock app

  3. Click on the Extension button

    Add new extension

  4. Click the Add button under the mBot2 shield

    Select mBot2 extension

  5. Click on the Extension button

    Add new extension

  6. Click the Add button under the Quad RGB Sensor

    Select quad RGB sensor extension

  7. Click on the Extension button

    Add new extension

  8. Click the Add button under the Ultrasonic Sensor 2

    Select ultrasonic sensor extension

  9. Click the Upload button under the Mode Switch section

    This allows you to write your program without having the mBot Neo connected to your computer

    Select Upload mode

  10. Perform steps 8 through 40 of Lesson 3
  11. Drag the “if < > then else” block to the coding pane and snap in inside the top of the forever block

    If-Then-Else block

  12. Click the Operators selector and drag the “( ) > 50” block to the coding pane and snap it into the if - then block

    Greater than block

  13. Click the Ultrasonic Sensor 2 selector and drag the “ultrasonic 2 1 distance to an object (cm)” block to the coding pane and snap it into the “( ) > 50” block

    Ultrasonic sensor block

  14. Change the “50” to “7” in the “( ) > 50” block

    Set distance value

  15. Click the mBot2 Chassis selector and drag the “turns left 90 until done” block to the coding pane and snap it inside the bottom section of the if-then-else block

    Turn left block

  16. Drag the “moves forward 100cm until done” block to the coding pane and snap it inside the bottom section of the if-then-else block

    Move forward block

  17. Change the 100 to 15 in the “moves forward 100cm until done” block

    Set distance to move

  18. Drag the “turns left 90 until done” block to the coding pane and snap it inside the bottom section of the if-then-else block

    Turn left block

  19. Change the “left” to “right” in the “turns left 90 until done” block

    Turn right

  20. Drag the “moves forward 100cm until done” block to the coding pane and snap it inside the bottom section of the if-then-else block

    Move forward block

  21. Change the 100 to 30 in the “moves forward 100cm until done” block

    Set distance to move

  22. Drag the “turns left 90 until done” block to the coding pane and snap it inside the bottom section of the if-then-else block

    Turn left block

  23. Change the “left” to “right” in the “turns left 90 until done” block

    Turn right

  24. Drag the “moves forward 100cm until done” block to the coding pane and snap it inside the bottom section of the if-then-else block

    Move forward block

  25. Change the 100 to 15 in the “moves forward 100cm until done” block

    Set distance to move

  26. Drag the “turns left 90 until done” block to the coding pane and snap it inside the bottom section of the if-then-else block

    Turn left block

  27. Change the name of the program in the upper left to “ObstacleLineFollow”

    Change Program Name

  28. Slide the power switch on the mBot2 Shield to the ON position and click the Connect button

    Connect to CyberPi

  29. Click the Upload button and wait for the upload to complete

    Upload program to mBot

  30. Slide the power switch on the mCore mainboard on the mBot to the OFF position and disconnect the USB cable from the mBot Neo

Robot Testing

Follow the steps below to test out the program you just created

  1. Place the line following map on the floor
  2. Place styrofoam blocks across the line to create obstacles
  3. Place the mBot on the line and slide the power switch on the mBot2 Shield on the mBot Neo to the ON position
  4. Press the B button on the CyberPi to start the mBot Neo moving
  5. When you're finished watching the mBot Neo follow the line, press the A button
  6. Change the distances in the else section to see how they change the mBot Neo obstacle avoidance

Which values need to be the same?

When you're ready to try out changes to your program, connect the USB cable to the CyberPi on the mBot Neo, plug the cable into your computer, and repeat steps 42 through 44 above

Return to Main mBot Neo page

"He has filled them with skill to do every sort of work done by an engraver or by a designer or by an embroiderer in blue and purple and scarlet yarns and fine twined linen, or by a weaver—by any sort of workman or skilled designer. - Exodus 35:35"