Start here if you're new to robotics! This folder now includes a complete curriculum from beginner to advanced:
- Lessons 01-03: Linear Motion (forward/backward)
- Lessons 04-06: Rotational Motion (turning)
- Lessons 07-08: Ultrasonic Sensing
- Lessons 09-10: Servo Control & Obstacle Avoidance
- Lessons 11-12: Obstacle Courses
- Lessons 13-14: Line Following
- Lessons 15-16: Autonomous Robot Design (Final Project)
📖 See: LESSON_PLAN.md and COMPLETE_LESSON_GUIDE.md in the root folder for full curriculum.
🎯 Quick Ref: QUICK_REFERENCE.md for command cheat sheet
The Car Control Library provides you with a suite of functions to control the car's movements with ease.
-
Move Forward
car.moveForward(speed, duration);- Description: Moves the car forward.
- Parameters:
speed: Speed of the car.duration: Duration in milliseconds.
- Example:
car.moveForward(255, 2000);moves the car forward at maximum speed for 2 seconds.
-
Move Backward
car.moveBackward(speed, duration);- Description: Moves the car backward.
- Parameters:
speed: Speed of the car.duration: Duration in milliseconds.
- Example:
car.moveBackward(200, 1500);moves the car backward at speed 200 for 1.5 seconds.
-
Turn Left
car.turnLeft(speed, duration);- Description: Turns the car left.
- Parameters:
speed: Speed of the turn.duration: Duration in milliseconds.
- Example:
car.turnLeft(180, 1000);turns the car left at speed 180 for 1 second.
-
Turn Right
-
Stop Motors
car.stopMotors();- Description: Stops all of the car's motors.
- Example:
car.stopMotors();stops the car.
-
Stop Time
car.stopTime(mS);- Description: Places the car in standby for a specified duration.
- Parameters:
mS: Standby time in milliseconds.
- Example:
car.stopTime(1000);puts the car in standby for 1 second.
-
Turn Around
car.turnAround(speed);- Description: Turns the car around 180 degrees.
- Parameters:
speed: Speed of the turn.
- Example:
car.turnAround(200);turns the car 180 degrees at speed 200.
-
Move Slow Forward
car.moveSlowForward(duration);- Description: Moves the car forward at a slow speed.
- Parameters:
duration: Duration in milliseconds.
- Example:
car.moveSlowForward(3000);moves the car forward slowly for 3 seconds.
-
Follow Line
- Signature:
car.followLine(threshold); - Description: Adjusts the car's movement to follow a line based on sensor readings.
- Parameters:
threshold: Value against which sensor readings are compared to detect the line.
- Example:
car.followLine(1000);adjusts the car's movement to follow a line, assuming sensor values above 1000 indicate the line's presence.
- Signature:
-
Stop At Line
- Signature:
car.stopAtLine(threshold); - Description: Stops the car when a line is detected by any sensor.
- Parameters:
threshold: Value against which sensor readings are compared to detect the line.
- Example:
car.stopAtLine(1000);stops the car when any sensor detects a line with a value below 1000.
- Signature:
The followLine and stopAtLine functions are essential for tasks like line following and stopping at specific points. Here's a detailed description of each function's behavior:
Follow Line
This function makes the car continuously adjust its direction to stay on a line. The car moves forward if all sensors detect the line. If a sensor detects the line is veering off to one side (indicated by a value lower than the threshold), the car will adjust its direction by turning slightly towards the opposite side. This function is particularly useful in situations where the line may curve or not be perfectly straight.
Stop At Line
stopAtLine is used for scenarios where the car needs to halt upon encountering a line, such as at an intersection or a designated stopping point. The function checks if any of the line sensors detect a value below the specified threshold, which indicates the presence of a line. Upon detection, the car's motors are stopped, bringing the car to a halt.
Both functions rely on accurate sensor readings and may require calibration of the threshold value based on the specific characteristics of the line and the sensors.
- Signature:
car.customMovement(forwardA, forwardB, speedA, speedB, duration) - Description: Executes a custom movement pattern.
- Parameters:
forwardA: Boolean flag to set motor A's direction (forward iftrue, backward iffalse).forwardB: Boolean flag to set motor B's direction.speedA: Speed setting for motor A (0-255).speedB: Speed setting for motor B (0-255).duration: Time for which the movement should last in milliseconds.
- Example:
car.customMovement(true, false, 200, 150, 2500);will make motor A move forward and motor B move backward, creating a custom motion for the car.
-
Check for Obstacle
car.checkObstacleInFront();- Description: Checks if there is an obstacle in front of the car.
- Example:
car.checkObstacleInFront();updates the_obstacleInFrontvariable based on whether an obstacle is detected.
-
Get Distance to Obstacle
-
Attach Claw
car.attachClaw(pin);- Description: Attaches the claw mechanism to the specified pin.
- Parameters:
pin: The pin where the servo for the claw is connected.
- Example:
car.attachClaw(9);attaches the claw servo to pin 9.
-
Open Claw
car.openClaw();- Description: Opens the claw.
- Example:
car.openClaw();opens the claw.
-
Close Claw
car.closeClaw();- Description: Closes the claw.
- Example:
car.closeClaw();closes the claw.
BasicMovements.ino: Demonstrates the basic movements of the car.LoopMovements.ino: Demonstrates looped sequences of actions.

