Controlling a Servo Motor Using Signal From the Ultrasonic Sensor
by theSTEMpedia in Circuits > Sensors
2306 Views, 14 Favorites, 0 Comments
Controlling a Servo Motor Using Signal From the Ultrasonic Sensor
Can an extremely popular video game be used for teaching STEM? Of course, it can, if you know-how!
This project will show you how you can control a servo using an ultrasonic sensor by making a Scratch Angry Birds project in PictoBlox, our Scratch based graphical programming software with advanced interaction abilities. This servomotor project, that can be made using the evive Starter Kit and other DIY material like chart paper, cardboard, glue, etc, is an interesting way to teach servo motor and ultrasonic sensor concepts to kids. And since it is based on Scratch, it also helps them learn a thing or two about coding as well!
You can download PictoBlox from HERE.
Now that you’re all set, let’s begin!
List of Supplies
Hardware
- evive
- Ultrasonic Sensor
- Servo Motor
- Jumper Cables
- Corrugated Sheet
- Hot Glue
- Icecream Stick
Software
Note: All the above electronic components can easily be found in evive Starter Kit. Where students can make a number of other projects too.
Taking the Cutouts
Before we starting the assembly of our Angry Birds theme project, let’s first collect all the necessary cutouts that we need in our project.
Take one corrugated sheet and cut it in the dimension of 30 cm x 30 cm as the base upon which we will place our entire assembly i.e. servo and ultrasonic sensor. (Fig 1)
Note: You can even use cardboard instead of the corrugated sheet.
A strip of the dimension 2.5 cm x 30 cm to fix the servo and the ultrasonic. (Fig 2)
And a small square of 15 cm x 15 cm to stick our angry bird to it.
Assembling the Base of Our Project
The main aim of this project is to show kids how can we trigger a servo motor using the signals from the Ultrasonic Sensor.
The Angry Birds theme is to add an extra pinch of edutainment to your STEM learning.
Take the base sheet and place the strip at a distance of 10 cm away from any one of the edges.
Once the place is finalized, glue it to the base using a Hot Glue Gun as shown in the fig above.
Attaching the Servo and the Ultrasonic Sensor
Once the basic structure of the base is ready. We will now focus on the main aim of the project i.e is to control the servo using an ultrasonic sensor. Thus, let's add them one after the other.
Attach the ultrasonic sensor on the red strip on one side of the base using Hot Glue. (Fig 1)
And attach the servo motor on the other side of the red strip using Hot glue. (Fig 2)
Setting the Servo Angle
We will first use the servo angle before bringing it in use. We are going to test it using evive's firmware. i.e. no special code is required to set the angle.
Just connect the servo to the Servo channel 1, switch ON evive, choose Controls, select Servo and then select Servo 1 from the option.
You can now change the servo angle using potentiometer 1 to 180 degrees. You can see the servo angle on evive’s TFT display.
Generally, set the servo angle to 90 degrees.
Making Our Angry Bird and It's Egg
Now take a square cutout of 15cm x 15cm and glue the angry bird cutout on it. Cut the base corrugated sheet such that resembles cutout of the angry bird. (Fig 1)
To make the game look real, let's add one more component into the project i.e. the bird's egg. :)
We want our angry bird to hit the person as soon as he/she tries to take the egg away. Let's attach the ice cream stick to it.
Now, at the other end of the ice cream stick, we will attach the servo horn as we need to attach it to the servo head. (Fig 2 and 3)
Now fix this entire assembly onto the servo head.
It's time to add the egg!
Cut an egg from the cardboard or the corrugated sheet and fix it on the base between the ultrasonic sensor and the servo motor. (Fig 4)
Yay! The assembly is now complete.
Making the Connections
Now, we need to connect them to the microcontroller, evive is the one in our case.
Connect Servo to channel 1 i.e S1 of evive
The ultrasonic sensor as:
- VCC of the servo to 5V of evive
- GND of the servo to Ground of evive
- Trig of the servo to digital pin 2 of evive
- Echo of the servo to digital pin 3 of evive
Writing the Script or the Code
To make the project simpler for kids and make them understand the logic more clearly. We will code or program the project in PictoBlox- a Scratch based programming platform. You can download PictoBlox from here.
Downloads
Conclusion
With this, your Scratch based Angry Birds project is all set. Enjoy!