Class 6 - Coding, AI & Robotics Course
-
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
Activity: Read Distance from Ultrasonic Sensor
So far, we’ve learned about ultrasonic sensors and assembled the Obstacle Avoidance Robot.
Here we’ll learn how to measure the distance from the target using ultrasonic sensors and Quarky. Hence, our next task would be to connect them and code for distance measurement.
Servo Connections to Quarky
Now we will connect the Ultrasonic Sensor to the Robot. The sensor and the robot have the following pins:
- Ultrasonic Sensor Pins:
- VCC
- GND
- Trig
- Echo
- Quarky Pins:
- GND
- V
- D1
- D2
We will start with connecting the ultrasonic sensor with Quarky using the 4 set wire provided in the kit. But, first, make the connection in the following way:
- First, connect the VCC of the ultrasonic sensor with the V pin on the Quarky.
- Connect the GND of the ultrasonic sensor with the Ground pin on the Quarky.
- Connect Trig of the ultrasonic sensor with D1 pin on the Quarky.
- Finally, connect the Echo of the ultrasonic sensor with the D2 pin on the Quarky.
Ultrasonic sensor blocks
The Sensors palette of PictoBlox allows us to utilize the ultrasonic sensor blocks. We have two blocks for the same:
- Connect Ultrasonic () to echo(), trig(): This block is used to do the Initialization of the Ultrasonic pins. It shows that the trigger pin is connected on D1 and Echo pin is on the D2 pin.
- Get Ultrasonic () distance: This block is used to get/see the Distance value in centimeters.
Activity: Read Distance from Ultrasonic Sensor
Our distance measurement will work like this: when an object comes in front of the sensor, we will be able to see the distance between the object and the Quarky.
Sounds Interesting? Let’s do the coding then!
Let’s Code!
Follow the steps:
- Open PictoBlox and create a New File.
- Select the coding environment as Block Coding.
- Go to the Events palette and add the when green flag clicked block.
- To initialize the pins go to the Sensors palette and add Connect Ultrasonic () to echo(), trig() below the when green flag clicked. Note: Select the proper pins for echo and trig in the above block with respect to your connections.
- Now, go to the Control palette and add a forever block below the Connect Ultrasonic () to trig (), echo(). Everything inside this block will run until you manually stop the code.
- Add say() block from the looks palette in the forever block.
- Lastly, drag the Get ultrasonic () distance from the Sensors palette and place it on the say () block. This will ensure that Toby will say the distance value every time you run the code.
- Save the file with the name Read Distance from Ultrasonic Sensor.
Code completed!!
But our task is not finished yet. So let’s test it out to see the operation.
Final Testing
To begin with, bring an object in front of the sensor and measure the distance.
Toby will say the distance value. The value will decrease as the hand approaches the sensor and increase as it moves away.
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.
Good luck!