===== 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 [[https://www.makeblock.com/pages/mbot-neo-coding-robot|mBot Neo kit]] that can be purchased on Amazon. - Assembled mBot Neo from [[:mbotneo:lesson1|Lesson 1]] - USB Cable - Line following paper - Styrofoam Blocks that are at least 5in tall and 2in thick ===== Software Programming ===== - 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 - Open the mBlock app on your computer\\ \\ You can download the mBlock app from [[https://www.mblock.cc/en/download/|mBlock Download]] if it isn't already installed {{ :mbotneo:lesson4:s1.png |Open mBlock app}} - Click on the Extension button\\ \\ {{ :mbotneo:lesson4:s2.png |Add new extension}} - Click the Add button under the mBot2 shield\\ \\ {{ :mbotneo:lesson4:s3.png |Select mBot2 extension}} - Click on the Extension button\\ \\ {{ :mbotneo:lesson4:s4.png |Add new extension}} - Click the Add button under the Quad RGB Sensor\\ \\ {{ :mbotneo:lesson4:s5.png |Select quad RGB sensor extension}} - Click on the Extension button\\ \\ {{ :mbotneo:lesson4:s6.png |Add new extension}} - Click the Add button under the Ultrasonic Sensor 2\\ \\ {{ :mbotneo:lesson4:s7.png |Select ultrasonic sensor extension}} - 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 {{ :mbotneo:lesson4:s8.png |Select Upload mode}} - Perform steps 8 through 40 of [[:mbotneo:lesson3|Lesson 3]] - Drag the "if < > then else" block to the coding pane and snap in inside the top of the forever block\\ \\ {{ :mbotneo:lesson4:s9.png |If-Then-Else block}} - Click the Operators selector and drag the "( ) > 50" block to the coding pane and snap it into the if - then block\\ \\ {{ :mbotneo:lesson4:s10.png |Greater than block}} - 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\\ \\ {{ :mbotneo:lesson4:s11.png |Ultrasonic sensor block}} - Change the "50" to "7" in the "( ) > 50" block\\ \\ {{ :mbotneo:lesson4:s12.png |Set distance value}} - 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\\ \\ {{ :mbotneo:lesson4:s13.png |Turn left block}} - 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\\ \\ {{ :mbotneo:lesson4:s14.png |Move forward block}} - Change the 100 to 15 in the "moves forward 100cm until done" block\\ \\ {{ :mbotneo:lesson4:s15.png |Set distance to move}} - 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\\ \\ {{ :mbotneo:lesson4:s16.png |Turn left block}} - Change the "left" to "right" in the "turns left 90 until done" block\\ \\ {{ :mbotneo:lesson4:s17.png |Turn right}} - 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\\ \\ {{ :mbotneo:lesson4:s18.png |Move forward block}} - Change the 100 to 30 in the "moves forward 100cm until done" block\\ \\ {{ :mbotneo:lesson4:s19.png |Set distance to move}} - 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\\ \\ {{ :mbotneo:lesson4:s20.png |Turn left block}} - Change the "left" to "right" in the "turns left 90 until done" block\\ \\ {{ :mbotneo:lesson4:s21.png |Turn right}} - 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\\ \\ {{ :mbotneo:lesson4:s22.png |Move forward block}} - Change the 100 to 15 in the "moves forward 100cm until done" block\\ \\ {{ :mbotneo:lesson4:s23.png |Set distance to move}} - 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\\ \\ {{ :mbotneo:lesson4:s24.png |Turn left block}} - Change the name of the program in the upper left to "ObstacleLineFollow"\\ \\ {{ :mbotneo:lesson4:s25.png |Change Program Name}} - Slide the power switch on the mBot2 Shield to the ON position and click the Connect button\\ \\ {{ :mbotneo:lesson4:s26.png |Connect to CyberPi}} - Click the Upload button and wait for the upload to complete\\ \\ {{ :mbotneo:lesson4:s27.png |Upload program to mBot}} - 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 - Place the line following map on the floor - Place styrofoam blocks across the line to create obstacles - Place the mBot on the line and slide the power switch on the mBot2 Shield on the mBot Neo to the ON position - Press the B button on the CyberPi to start the mBot Neo moving - When you're finished watching the mBot Neo follow the line, press the A button - 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 [[:mbotneo:start|Return to Main mBot Neo page]]