An Ultrasonic Sensor detects approaching objects. It does this by measuring the distance to the object. Look at the two eyes on the front of your robot. One of the “eyes” transmits a sound, and the other waits for the echo of the sound to return. This is how the distance to the object from the sensor can be calculated. You enter the distance and the sensor will detect any object in front of it within that range.The ultrasonic sensor has a range of 3-400cm. If an object is outside this range, the sensor will return a value of 400.
Task #1: Ultrasonic Sensor_ Test the Sensor
Just like we did for the Line Sensor, lets test the Ultrasonic Sensor to see if it works. Write a program that does the following:
Model Video: Mobile or You Tube.
- The robot should be sitting on its battery pack.
- When the robot is turned on, there should be a 1 second delay
- First, look at the code you wrote for Line Sensor Task #1B.
- Rewrite this program so that the robot wheels will stop moving forward when an object appears approximately 10 cm. above the Ultrasonic Sensor.
- Note: in order for the wheels to be moving, place the "Wheel Move Block" prior to the "Forever" block.
- Delete the "Line Sensor" Operator that you used in Task #1B and instead use the Operator shown below (insert it into the "If/Then" block.)
Task #1B: Ultrasonic Sensor_ Comparing Similar Programs
- View this program: Program A. Now on the Ultrasonic Sensor Gradesheet, state what you think will happen when it is uploaded to the robot and the robot is turned on.
- View this program: Program B. Now on the Ultrasonic Sensor Gradesheet, state what you think will happen when it is uploaded to the robot and the robot is turned on. Then explain what is the difference between how the lines of code in the program were written.
- Write Program A code and Upload it to the robot. Explain on the Gradesheet what actually occurred when it was turned on.
- Write Program B code and Upload it to the robot. Explain on the Gradesheet what actually occurred when it was turned on.
- Finally, which of the two lines of code functions better and why?
Task #2: Ultrasonic Sensor_ Robot Stop At Object
Write a program that does the following:
Model Video: Mobile or You Tube.
- When the robot is turned on, there should be a 1 second delay.
- The robot will move directly forward and when 25 cm. from the object, the robot should stop.
Task #3: Ultrasonic Sensor_ Robot Drive in a Circle Around a Center Object
Write a program that does the following:
Model Video: Mobile or You Tube.
- The course has 4 walls and a center object.
- The robot is to proceed around the center object and return to its starting point without touching the walls and the center object.
- There should be a 1 second delay each time the robot turns or proceeds forward.
- Hint #1: (This is a very simple program. Remember that the Goal is for the Robot to complete one circle in one direction around an object...thats it...so go write it!).
- Note: It took me a while to find a balance between the amount of time and speed in order for the robot to make a perfect 90 degree turn.
- Hint #2: Programming - "If/Then/Else"
- Up to this point, you have used "If/Then" statements. Now you will use an "If/Then/Else" statement. Write the code so that "If" some thing occurs such as the ultrasonic sensor recognizing an object, "Then" something should occur like stopping or turning. "Else", it should just continue driving.
Light Sensor |
|
A Light Sensor monitors the amount of surrounding light. Your robot's "Brain" has a built in light sensor (View the image above, it is between the numbers 2 & 3). You will program your robot to react to the changing amount of light.
Task #1: Light Sensor_ Test the Sensor
Just like we did for the Ultrasonic Sensor, lets test the Light Sensor to see if it works. Write a program that does the following:
Model Video: Mobile or You Tube.
- The robot should be elevated off the ground so that when the wheels spin, they do not touch the ground and the Brain/Light Sensor needs to be pointing up (towards the light).
- First, look at the code you wrote for "Task #1 Ultrasonic Sensor_Test the Sensor."
Hint: To save time, I would "SaveAs"
the program you wrote for "Task #1 Ultrasonic Sensor_Test the Sensor," and title it..."Task #1 Light Sensor_Test the Sensor." Then start making the changes recommended below.
Note: The Light Sensor Value Range 0-1000
; Exposed under sunshine (>500); Exposed at night (0-100); Indoor lighting (100-500).
- Rewrite this program so that the robot wheels will stop moving forward when the intensity of the light reaching the Light Sensor on the robot in the classroom drops to 200.
- Note: in order for the wheels to be moving, place the "Wheel Move Block" prior to the "Forever" block.
- Delete the "UltrasonicSensor" Operator that you used in "Task #1 Ultrasonic Sensor_Test the Sensor." and instead use the Operator shown below - insert it into the "If/Then" block.
- Test it! Download this program to your robot. The wheels should turn forward. But...when the light reaching the light sensor on the Brain is blocked, the wheels will "Stop Moving."
Task #2: Light Sensor_ Park My Robot.
Write a program that does the following:
Model Video: Mobile or You Tube.
- When the robot is turned on, there should be a 1 second delay.
- The robot will move directly forward.
- When the robot enters a container that blocks the light from reaching the Light Sensor, the robot should stop, back up to the original position, turn 90 degrees to the left and do it all over again.
- The robot should repeat this sequence four times, entering and leaving the boxes four times.
Hint:
- Review and copy the code you wrote for "Task #3: Ultrasonic Sensor_ Robot Drive in a Circle Around a Center Object." Edit it so that your robot will now successfully complete the new task using a Light Sensor instead of an Ultrasonic Sensor.
- It will take some trial and error, but to succeed, you need to balance the speed of the robot with the amount of time you allow it to complete a task.
- You are allowed to move the boxes to positions that will let you succeed, but only after a run and not while the robot is actually moving.
- Good Luck and Have Fun Parking Your Robot!
Ultrasonic Sensor & Light Sensor
Task #1: Ultrasonic Sensor & Light Sensor: Guide Robot Thru Maze
Write a program that does the following:
Model Video: Mobile or You Tube
- The course is a maze made up of 4 walls. Watch the Model Video above.
- Your robot will rely on the Ultrasonic Sensor to turn right and the Light Sensor to turn left.
- You may not touch the robot or else you will need to start over.
- The robot should not touch a wall or else it will need to start over.
- After the robot completes an unsuccessful run, you may shift the boxes and walls to increase the chance that it does have a successful run.
- Hint: Inside a Forever Loop, first slide a Motion block that drives your Left & Right wheels separately (I set mine to 45% Left & 45% Right.). Follow this block with two If/Then statements - copy one from your "Task #2: Light Sensor_Park My Robot." and copy the other from your "Task #3: Ultrasonic Sensor_Robot Drive in a Circle Around a Center Object". You no longer need to have an Else Statement since you moved the Motion code to the start of this Forever block...so just used the "If/Then" portion of the code!
- Now all you have to do is adjust the time and speed. Also, look at the shadow created by the boxes from the ceiling lights - the shadow is different depending upon the direction the robot enters the box. You might have to adjust the Light Sensor intensity and/or the Ultrasonic Sensor distance values in your program. Note: I set my Light Intensity to "<300".