Valiant Robots TinkerCAD Programming Challenges
Continuing with the Valiant robots through TinkerCAD, this workshop focuses on developing text programming skills. The challenges include adding functions to control motors, using if-statements to drive forward based on light, and integrating an ultrasonic sensor to drive the robot. Progress from bronze to silver and gold challenges for a comprehensive learning experience.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
Valiant robots Week 3 exercises
Building and Programming robots in TINKERCAD This week you be continuing with the Valiant robots through TinkerCAD. This workshop aims to develop your text programming skills. Continue editing your circuit from Week 2 You should have completed at least bronze from Week 2 before starting week 3 Please complete the bronze requirements before starting the silver, and complete the silver before starting the gold.
BRONZE Challenge: Aim: Adding functions to control the motors to drive in different directions Steps: 1. Define four variables at the start of your program to store the pins used by the motors. The variables should all be data type int Variable name Pin number leftForwardPin 10 leftReversePin 11 rightForwardPin 9 rightReversePin 6 e.g. int leftForwardPin = 10;
BRONZE Challenge: Steps: 2. In the setup() function, set the pin mode for each of the new pins to be output e.g. pinMode(leftForwardPin, OUTPUT);
BRONZE Challenge: Steps: 3. Define five functions before the setup() function in your program to drive the motors. These functions should be: void robotForward() void robotReverse() void robotLeft() void robotRight() void robotStop() e.g.
BRONZE Challenge: Steps: 4. Inside your loop() function, call the functions you have just written to perform the following actions: Drive forward for one second Stop for half a second Turn left for half a second Turn right for a second Turn left for half a second Stop for half a second Drive backwards for one second Stop for one second e.g.
SILVER Challenge: Aim: Use an if-statement to only drive forward if it is light Note, you may want to comment-out the existing code inside your loop function by adding /* and */ at the start and end
GOLD Challenge: Aims: Add a function to take readings from the ultrasonic sensor and use it to drive the robot Completing this challenge requires completion of silver from Week 2 Steps: Define the following variables for the ultrasonic pins, and set their pin modes Variable name Pin Pin mode ultrasonicTrigger 7 output ultrasonicEcho 8 input
GOLD Challenge: Steps: Add the following function for the ultrasonic to your program:
GOLD Challenge: The ultrasonic sensor on the real robot is mounted on top of the servo. Turning the servo left and right, we can take readings to measure distances then decide which way to drive the robot. Steps: 1. Turn the servo to the left (0 degrees), waiting for a second to complete the movement 2. Create a variable called left to store an int 3. Call the read ultrasonic function and assign the result to the left variable e.g. left = readUltrasonic();
GOLD Challenge: Steps: 4. Turn the servo to the left (180 degrees), waiting for a second to complete the movement 5. Create a variable called right to store an int 6. Call the read ultrasonic function and assign the result to the right variable 7. Add an if-statement to turn in the direction that has the greater distance (to avoid obstacles) Note: when simulating this, you will need to adjust the ultrasonic reading whilst the servo is turning. Adding extra delay between readings might be useful. You may also want to include a Serial.println( message ) to make it easier to check which way your robot turned.
Extension Challenge: What else can you add to this program? The map function can be used to scale values between different ranges int result = map(inputValue, inputMin, inputMax, outputMin, outputMax); Use the map function to adjust the LDR input to the range of servo angles (0-180 degrees) Use the map function to take input from the ultrasonic and play tones the piezo buzzer