Table of Contents

setultrasonicpins()

Function Definition: setultrasonicpins(sensor_number = 1, trig_pin = "D1", echo_pin = "D2")

Parameters

NameTypeDescriptionExpected ValuesDefault Value
sensor_numberintThe specific ultrasonic sensor label.1 or 21
trig_pinstringThe specific GPIO pin where the trig pin of the ultrasonic sensor is connected."D1","D2","D3","A1","A2", "S1", or "S2""D1"
echo_pinstringThe specific GPIO pin where the trig pin of the ultrasonic sensor is connected."D1","D2","D3","A1","A2", "S1", or "S2""D2"

Description

The function initializes the ultrasonic sensor with specified echo and trig pins.

Example

The example demonstrates how to use an ultrasonic sensor with Quarky.

Connections

Now we will connect the Ultrasonic Sensor to the Robot. The sensor and the robot have the following pins:

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.

Code

sprite = Sprite('Tobi')
quarky = Quarky()

quarky.setultrasonicpins(1, 18, 19)
while True:
  sprite.say(quarky.getdistance(1))

 

Output

Read More
All articles loaded
No more articles to load