Back to Course
Class 6 - Coding, AI & Robotics Course
0% Complete
0/0 Steps
-
Coding
Session 1: Introduction to Coding3 Topics -
Session 2: Backdrop, Costume, and Animation3 Topics|1 Quiz
-
Session 3: Basics of Algorithm and Flowchart3 Topics|1 Quiz
-
Session 4: Basics of Pseudocode3 Topics|1 Quiz
-
Session 5: Getting Started with Quarky3 Topics|1 Quiz
-
Session 6: Variables: The Multitaskers4 Topics|1 Quiz
-
Session 7: Arithmetic Operators4 Topics|1 Quiz
-
Session 8: Conditional Statements3 Topics|1 Quiz
-
Session 9: Logical Operators4 Topics|1 Quiz
-
Session 10: Nested Conditional Statements2 Topics|1 Quiz
-
Session 11: Loops3 Topics|1 Quiz
-
Session 12: Touch Based Piano2 Topics
-
Session 13: Criterial in Loops5 Topics|1 Quiz
-
Session 14: Catch the Fruit Game - Part 12 Topics
-
Session 15: Catch the Fruit Game - Part 22 Topics|1 Quiz
-
Artificial IntelligenceSection 16: Introduction to Artificial Intelligence3 Topics|1 Quiz
-
Session 17: Basics of Face Detection2 Topics|1 Quiz
-
Session 18: Face Expression Detection2 Topics|1 Quiz
-
Session 19: Mimic Face with Quarky1 Topic
-
Session 20: Face Filter - Part 12 Topics
-
Session 21: Face Filter - Part 22 Topics
-
RoboticsSession 22: Basics of Robotics2 Topics|1 Quiz
-
Session 23: Wirelessly Controlled Robot2 Topics
-
Session 24: Introduction to Sensors3 Topics|1 Quiz
-
Session 25: Introduction to Actuators3 Topics|1 Quiz
-
Session 26: Face Tracking with Robot2 Topics
-
Session 27: Obstacle Avoidance Robot - Part 13 Topics
-
Session 28: Obstacle Avoidance Robot - Part 22 Topics|1 Quiz
-
Session 29: Edge Detector Robot - Part 13 Topics
-
Session 30: Edge Detector Robot - Part 22 Topics|1 Quiz
-
Capstone ProjectCapstone Project
Lesson 30,
Topic 1
In Progress
Programming
Lesson Progress
0% Complete
Now that we’ve figured out the logic and how an edge detection robot works, let’s move to the coding phase of transforming our robot into an edge detector.
Let’s Code!
- Start your program by adding when green flag clicked block.
- After that, do the initialization by introducing connect ultrasonic() to trig(), echo() block.
- Set servo at 90 degrees angle by adding set servo on () to () angle below connect ultrasonic () to trig(), echo ().
- Now, drag and drop the forever block from the control palette.
- Next, we will add the conditional block to check the if-else condition. Drag and drop the if () then else block inside the forever loop.
- Within this if () then else condition, put the get ultrasonic () distance block in the first place and 10 in the second.
- This block will check whether the sensor value is coming out to be more than 10 or not.
- If the condition is satisfied the robot should move forward, so we will add go () at () speed. From the dropdown select the direction as forward speed as 40%.
- Add the stop robot from the robot palette inside the else statement. This block will stop the robot and set a different angle.
- After that, put the set servo () to () angle. Change the angle value to 174.
- Then, add 1 second of delay with the help of wait () block.
- Now get another if-else block with the same condition as before and place it inside the else branch, just after the wait() block.
- If the condition is satisfied the robot should go right, stop and change its angle to 90 degrees. For this logic, we will use the go () at () speed for () seconds block.
- From the dropdown select the directions as right, speed as 40%, and time as 1 second.
- Below it, drag and drop the stop the robot from the robot palette.
- To change the angle, place the set servo () to () angle block. Set angle to 90.
- After that, put the set servo () to () angle inside the else branch. Change the angle value to 0.
- Then, place the wait() block, with a delay of 1 second.
- Again, duplicate the previous if-else condition for 0 degrees angle.
- Put if () then else block after wait() block. Within this If () then else condition we can check the third condition; if the sensor value is less than 10.
- If the if-branch condition is satisfied the robot should go left, stop and change the angle to 90 degrees. For this, we will use the go () at () speed for () seconds, with the direction as left, speed as 40% and time 1 second.
- In the set servo on() to () angle, set the angle as 90 degrees.
- If the ‘if-branch’ condition is not satisfied, we want the robot to stop, display the red LED, go backward and turn left.
- So for that, replace the else-branch blocks with the stop robot from the robot palette.
- Then, add the display matrix as() and fill the red color in the matrix.
- After that, put the go () at () speed for () seconds block. Set the direction as backward with 40% speed for 2 seconds.
- Below that drag and drop the, go () at () speed for () seconds block. Set the direction as left with 40% speed for 2 seconds.
- Lastly, place the display matrix as () block from the display palette and set it blank. As, if no edge is detected, the robot shouldn’t display anything on its display.
Our robot is now ready to run! Click on the green flag to run the script.
Code completed!!!
Assignment
Before you move on to the next lesson, a small assignment awaits you!
You must upload the PictoBlox program you created in this activity to the website. Submitting the assignment is a must in order to receive the certificate after completing the course.
Follow the steps below to upload your assignment:
- Click on Browse.
- Search and Select your saved Project file(.sb3) and Click Open.
- Click on Upload to submit the assignment.
The file type allowed is the SB3 file generated from the PictoBlox program. The maximum file size allowed is 5 MB.
Good luck!