Back to Course

Class 6 - Coding, AI & Robotics Course

0% Complete
0/0 Steps
  1. Coding

    Session 1: Introduction to Coding
    3 Topics
  2. Session 2: Backdrop, Costume, and Animation
    3 Topics
    |
    1 Quiz
  3. Session 3: Basics of Algorithm and Flowchart
    3 Topics
    |
    1 Quiz
  4. Session 4: Basics of Pseudocode
    3 Topics
    |
    1 Quiz
  5. Session 5: Getting Started with Quarky
    3 Topics
    |
    1 Quiz
  6. Session 6: Variables: The Multitaskers
    4 Topics
    |
    1 Quiz
  7. Session 7: Arithmetic Operators
    4 Topics
    |
    1 Quiz
  8. Session 8: Conditional Statements
    3 Topics
    |
    1 Quiz
  9. Session 9: Logical Operators
    4 Topics
    |
    1 Quiz
  10. Session 10: Nested Conditional Statements
    2 Topics
    |
    1 Quiz
  11. Session 11: Loops
    3 Topics
    |
    1 Quiz
  12. Session 12: Touch Based Piano
    2 Topics
  13. Session 13: Criterial in Loops
    5 Topics
    |
    1 Quiz
  14. Session 14: Catch the Fruit Game - Part 1
    2 Topics
  15. Session 15: Catch the Fruit Game - Part 2
    2 Topics
    |
    1 Quiz
  16. Artificial Intelligence
    Section 16: Introduction to Artificial Intelligence
    3 Topics
    |
    1 Quiz
  17. Session 17: Basics of Face Detection
    2 Topics
    |
    1 Quiz
  18. Session 18: Face Expression Detection
    2 Topics
    |
    1 Quiz
  19. Session 19: Mimic Face with Quarky
    1 Topic
  20. Session 20: Face Filter - Part 1
    2 Topics
  21. Session 21: Face Filter - Part 2
    2 Topics
  22. Robotics
    Session 22: Basics of Robotics
    2 Topics
    |
    1 Quiz
  23. Session 23: Wirelessly Controlled Robot
    2 Topics
  24. Session 24: Introduction to Sensors
    3 Topics
    |
    1 Quiz
  25. Session 25: Introduction to Actuators
    3 Topics
    |
    1 Quiz
  26. Session 26: Face Tracking with Robot
    2 Topics
  27. Session 27: Obstacle Avoidance Robot - Part 1
    3 Topics
  28. Session 28: Obstacle Avoidance Robot - Part 2
    2 Topics
    |
    1 Quiz
  29. Session 29: Edge Detector Robot - Part 1
    3 Topics
  30. Session 30: Edge Detector Robot - Part 2
    2 Topics
    |
    1 Quiz
  31. Capstone Project
    Capstone Project
Lesson Progress
0% Complete

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:

  1. Ultrasonic Sensor Pins:
    1.  VCC
    2. GND
    3. Trig
    4. Echo
  2. Quarky Pins:
    1. GND
    2. V
    3. D1
    4. 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: 

  1. 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.
  2. 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:

  1. Open PictoBlox and create a New File.
  2. Select the coding environment as Block Coding.
  3. Go to the Events palette and add the when green flag clicked block.
  4. 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.
  5. 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.
  6. Add say() block from the looks palette in the forever block.
  7. 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.
  8. 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:

  1. Click on Browse.
  2. Search and Select your saved Project file(.sb3) and Click Open.
  3. Click on Upload to submit the assignment.
evive Alert
The file type allowed is the SB3 file generated from the PictoBlox program. The maximum file size allowed is 5 MB.

Good luck!