Mexican Group Videos and PDFS

This is a video lesson on Scalars and Vectors – Lesson 1.

Video lesson on Displacement and Velocity – Lesson 2

This is a video on Relative Motion

Next up is acceleration:

After acceleration we jump into projectile motion:

Lets go through some projectile motion examples:

And another example problem:

Next one up is Gravitational force:

Next up is foces in general.

Next one is a discussion on the normal force:

Lets look at frictional force problems using symbols.

assessment documents

Question Document 1

PowerPoint Presentation

Question Document 2

PowerPoint Presentation

Solution Document

PowerPoint Presentation

Introduction to Arduino Programming

What is Arduino?

Arduino is a microcontroller board that can read inputs (sensors, buttons) and control outputs (LEDs, motors). Think of it as a tiny computer that can interact with the physical world.

Understanding Arduino Pins: Digital vs Analog

Digital Pins (0-13):

  • Can only be HIGH (5V) or LOW (0V) – like a light switch
  • Perfect for LEDs, buttons, motors (on/off control)

Analog Pins (A0-A5):

  • Can read a range of voltages from 0V to 5V
  • Perfect for sensors that give varying signals (light, temperature, distance)
  • Can measure 1024 different levels (0-1023)

Power Pins:

  • 5V: Provides 5 volts of power
  • 3.3V: Provides 3.3 volts of power
  • GND: Ground – the “return path” for electricity (like the negative terminal of a battery)

Think of electricity like water flowing through pipes – it needs a path to flow from positive to negative (or from power to ground).

Understanding the Arduino IDE

Open the Arduino IDE and explain the basic interface:

  • Code area: Where we write our instructions
  • Verify button: Checks our code for errors
  • Upload button: Sends code to the Arduino
  • Serial Monitor: Shows messages from our Arduino

The Basic Structure

Every Arduino program (called a “sketch”) has two main parts:

void setup() {
  // This runs once when Arduino starts
  // Used for initial settings
}

void loop() {
  // This runs over and over forever
  // Main program logic goes here
}

Key Concept: Arduino programs are like giving someone a set of instructions. We need to be very specific and clear about what we want to happen.

Understanding Code Elements

Before we start, let’s understand the building blocks:

Comments: Lines starting with // are ignored by Arduino – they’re notes for humans

// This is a comment - it explains what the code does

Functions: Pre-written pieces of code that do specific jobs

  • pinMode() – sets up a pin
  • digitalWrite() – turns a digital pin on/off
  • delay() – pauses the program

Semicolons: Every instruction must end with ; (like periods in sentences)

Curly Braces: { } group instructions together

Activity 1: Your First Blinking LED (25 minutes)

Learning Goals

  • Understand digital output
  • Learn about pinMode() and digitalWrite()
  • Practice modifying code values

Step 1: Using the Built-in LED

Start with this simple code:

void setup() {
  pinMode(13, OUTPUT);  // Tell Arduino pin 13 is an output
}

void loop() {
  digitalWrite(13, HIGH);  // Turn LED on
  delay(1000);             // Wait 1 second
  digitalWrite(13, LOW);   // Turn LED off
  delay(1000);             // Wait 1 second
}

Upload this code and watch the built-in LED blink!

Understanding the Code Line by Line

void setup() {
  pinMode(13, OUTPUT);
}
  • void setup() – This function runs once when Arduino starts
  • pinMode(13, OUTPUT) – Tells Arduino that pin 13 will send out signals (not receive them)
    • 13 is the pin number
    • OUTPUT means we’re sending power TO something (like an LED)
    • If we were reading FROM something (like a button), we’d use INPUT
void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}
  • void loop() – This function repeats forever
  • digitalWrite(13, HIGH) – Sends 5V to pin 13 (LED turns on)
    • HIGH means “turn on” or “5 volts”
    • LOW means “turn off” or “0 volts”
  • delay(1000) – Makes Arduino wait for 1000 milliseconds (1 second)
    • Arduino can’t do anything else during this time
    • 1000 milliseconds = 1 second

Step 2: Connect an External LED

Physical Circuit Setup:

  1. Get your components: 1 LED, 1 resistor (220Ω – red/red/brown bands), jumper wires
  2. Identify LED parts:
    • Long leg = positive (anode) – connects to Arduino pin
    • Short leg = negative (cathode) – connects toward ground
  3. Build the circuit:
    • Insert LED into breadboard with legs in different rows
    • Connect jumper wire from Arduino pin 8 to LED’s long leg row
    • Insert 220Ω resistor: one end in LED’s short leg row, other end in ground rail
    • Connect jumper wire from Arduino GND to breadboard ground rail

Why do we need the resistor? LEDs are like water flowing through a pipe. Without a resistor, too much “electrical current” flows through and burns out the LED. The 220Ω resistor acts like a valve that limits the flow to a safe amount.

How to read resistor values:

  • 220Ω resistor has colored bands: Red (2), Red (2), Brown (×10) = 22 × 10 = 220Ω

Modify the code:

void setup() {
  pinMode(8, OUTPUT);  // Now using pin 8
}

void loop() {
  digitalWrite(8, HIGH);
  delay(1000);
  digitalWrite(8, LOW);
  delay(1000);
}

Experiment Time!

Try changing the delay values:

  • What happens with delay(100)?
  • What about delay(2000)?
  • Can you make it blink very fast?

Coding Challenge

Make the LED blink in a pattern: on for 2 seconds, off for 0.5 seconds.

Activity 2: Controlling LED Brightness

Learning Goals

  • Understand the difference between digital and analog
  • Learn about PWM (Pulse Width Modulation)
  • Practice using variables and loops

Digital vs Analog

  • Digital: Like a light switch – either ON or OFF
  • Analog: Like a dimmer switch – can be anywhere from OFF to fully ON

Step 1: Fading LED

Use the same LED circuit from Activity 1. Try this code:

void setup() {
  pinMode(8, OUTPUT);
}

void loop() {
  // Fade in
  for(int brightness = 0; brightness <= 255; brightness++) {
    analogWrite(8, brightness);
    delay(10);
  }
  
  // Fade out
  for(int brightness = 255; brightness >= 0; brightness--) {
    analogWrite(8, brightness);
    delay(10);
  }
}

Understanding the New Concepts

Variables: Think of variables like labeled boxes that store information.

int brightness = 0;
  • int means “integer” (whole numbers like 0, 1, 2, 255)
  • brightness is the name of our box
  • = 0 puts the number 0 into the box
  • We can change what’s in the box anytime: brightness = 100;

For Loops: These repeat code while changing a value each time.

for(int brightness = 0; brightness <= 255; brightness++) {
  // code to repeat
}

Breaking this down:

  • int brightness = 0 – Start with brightness box containing 0
  • brightness <= 255 – Keep going while brightness is 255 or less
  • brightness++ – After each loop, add 1 to brightness (++ means “add 1”)
  • The code inside { } runs once for each value: 0, 1, 2, 3… up to 255

analogWrite(): Instead of just ON/OFF, this gives us 256 different brightness levels:

  • analogWrite(8, 0) – completely off
  • analogWrite(8, 127) – half brightness
  • analogWrite(8, 255) – full brightness
  • Works on pins marked with ~ (PWM pins): 3, 5, 6, 9, 10, 11

How PWM Works: PWM rapidly switches the pin on/off. More “on time” = brighter LED.

  • 0 = always off
  • 127 = on 50% of the time (looks half bright)
  • 255 = always on (full brightness)

Step 2: Understanding the Loop

Let’s break down the first for loop:

  • Start with brightness = 0
  • Keep going while brightness is less than or equal to 255
  • After each loop, increase brightness by 1
  • Each time through, set LED to that brightness level

Experiment Time!

  1. Change delay(10) to delay(50) – what happens?
  2. Change the starting and ending values
  3. Try making it fade only to half brightness (127)

Coding Challenge

Make the LED pulse 3 times quickly, then stay off for 2 seconds.

Hint: You’ll need to repeat the fade in/out code 3 times, then add a long delay.

Activity 3: Button-Controlled LED

Learning Goals

  • Understand digital input
  • Learn about if statements
  • Practice reading sensors

Step 1: Add a Button

Physical Circuit Setup: Keep your LED circuit from Activity 2 and add these components:

Components needed: 1 push button, 1 × 10kΩ resistor (brown/black/orange bands), jumper wires

Building the button circuit:

  1. Insert the button: Push buttons have 4 legs. Insert it across the center divide of the breadboard so two legs are on each side
  2. Connect power side:
    • Connect jumper wire from Arduino 5V to one leg of the button
    • Connect 10kΩ resistor from the SAME button leg to a different row
    • Connect jumper wire from the resistor’s other end to Arduino GND
  3. Connect input side:
    • Connect jumper wire from Arduino pin 7 to the OTHER leg of the button (opposite side)
    • This same point connects to the resistor going to GND

Understanding Pull-up Resistors (Very Important!)

The Problem: Without a pull-up resistor, an input pin “floats” between HIGH and LOW, giving random readings.

How Pull-up Resistors Work:

  1. When button is NOT pressed:
    • Pin 7 connects through 10kΩ resistor to 5V
    • Pin 7 reads HIGH (5V)
    • Current flows: 5V → resistor → pin 7
  2. When button IS pressed:
    • Pin 7 connects directly to GND (0V) through button
    • Pin 7 reads LOW (0V)
    • Current flows: 5V → resistor → button → GND

Why 10kΩ? This resistor is large enough to limit current but small enough to ensure a clear HIGH signal. It “pulls up” the pin to HIGH when nothing else is connected.

Think of it like: A spring-loaded lever that’s normally pushed UP (HIGH) by the spring (resistor), but when you press the button, it connects directly DOWN (LOW) to ground.

Step 2: Basic Button Reading

void setup() {
  pinMode(8, OUTPUT);  // LED
  pinMode(7, INPUT);   // Button
  Serial.begin(9600);  // Start serial communication
}

void loop() {
  int buttonState = digitalRead(7);
  Serial.println(buttonState);  // Show button state
  delay(100);
}

Open the Serial Monitor (Tools menu) to see the button values!

Understanding Digital Input

pinMode(7, INPUT);
  • This tells Arduino that pin 7 will READ signals (not send them)
  • INPUT means we’re receiving information FROM something
int buttonState = digitalRead(7);

digitalRead(7) checks if pin 7 is HIGH or LOW

The result gets stored in the buttonState variable

buttonState will contain either HIGH (1) or LOW (0)

Serial.begin(9600);
Serial.println(buttonState);

Serial.begin(9600) starts communication with your computer at 9600 bits per second

Serial.println() sends information to the Serial Monitor window

This lets us see what the Arduino is “thinking”

Step 3: Control LED with Button

void setup() {
  pinMode(8, OUTPUT);
  pinMode(7, INPUT);
}

void loop() {
  int buttonState = digitalRead(7);
  
  if(buttonState == LOW) {  // Button is pressed
    digitalWrite(8, HIGH);  // Turn LED on
  } else {                  // Button is not pressed
    digitalWrite(8, LOW);   // Turn LED off
  }
}

Understanding If Statements

if(buttonState == LOW) {
  digitalWrite(8, HIGH);
} else {
  digitalWrite(8, LOW);
}

Breaking this down:

  • if(condition) – Check if something is true
  • buttonState == LOW – Is the button pressed? (Remember: pressed = LOW)
  • == means “is equal to” (different from = which means “assign”)
  • { } – Code inside runs if condition is true
  • else – What to do if condition is false

Logic Flow:

  1. Check: Is button pressed (LOW)?
  2. If YES: Turn LED on
  3. If NO: Turn LED off

Think of it like: “IF it’s raining, take an umbrella, ELSE wear sunglasses.”

Step 4: Toggle Mode

Make the button toggle the LED on/off instead of just controlling it while pressed:

bool ledOn = false;  // Variable to remember LED state
bool lastButtonState = HIGH;

void setup() {
  pinMode(8, OUTPUT);
  pinMode(7, INPUT);
}

void loop() {
  int buttonState = digitalRead(7);
  
  // Check if button was just pressed (went from HIGH to LOW)
  if(buttonState == LOW && lastButtonState == HIGH) {
    ledOn = !ledOn;  // Flip the LED state
    digitalWrite(8, ledOn);
    delay(50);  // Small delay to avoid multiple readings
  }
  
  lastButtonState = buttonState;
}

New Concepts Explained

Boolean Variables:

bool ledOn = false;

bool stands for “boolean” – a variable that can only be true or false

Like a yes/no question or on/off switch

false = 0, off,

no true = 1, on, yes

State Detection:

if(buttonState == LOW && lastButtonState == HIGH)

&& means “AND” – both conditions must be true

This detects the moment when button goes from not-pressed to pressed

Prevents multiple triggers from one button press

The NOT operator:

ledOn = !ledOn;

! means “NOT” or “opposite”

If ledOn is true, !ledOn makes it false

If ledOn is false, !ledOn makes it true

This “flips” or “toggles” the value

Activity 4: Multiple LED Patterns

Learning Goals

  • Practice with arrays
  • Create more complex patterns
  • Understand how to control multiple outputs

Step 1: Set Up 4 LEDs

Physical Circuit Setup: Components needed: 4 LEDs, 4 × 220Ω resistors, jumper wires

Building the circuit:

  1. Place LEDs: Insert 4 LEDs into breadboard, each in a different row
  2. Connect positive sides: Connect jumper wires from Arduino pins 5, 6, 7, 8 to the long legs of each LED
  3. Connect negative sides: For each LED:
    • Connect short leg to one end of a 220Ω resistor
    • Connect other end of resistor to the ground rail
  4. Connect ground: Connect Arduino GND to the breadboard ground rail

Step 2: Simple Sequence:

void setup() {
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
}

void loop() {
  // Turn on LEDs one by one
  digitalWrite(5, HIGH);
  delay(200);
  digitalWrite(6, HIGH);
  delay(200);
  digitalWrite(7, HIGH);
  delay(200);
  digitalWrite(8, HIGH);
  delay(200);
  
  // Turn off all LEDs
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  delay(500);
}

Step 3: Using Arrays (Smarter Approach)

int ledPins[] = {5, 6, 7, 8};  // Array of pin numbers

void setup() {
  for(int i = 0; i < 4; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
}

void loop() {
  // Knight Rider effect
  // Forward
  for(int i = 0; i < 4; i++) {
    digitalWrite(ledPins[i], HIGH);
    delay(150);
    digitalWrite(ledPins[i], LOW);
  }
  
  // Backward
  for(int i = 3; i >= 0; i--) {
    digitalWrite(ledPins[i], HIGH);
    delay(150);
    digitalWrite(ledPins[i], LOW);
  }
}

Understanding Arrays

What is an Array?

int ledPins[] = {5, 6, 7, 8};

Think of an array like a row of numbered mailboxes:

  • ledPins[0] = first mailbox (contains 5)
  • ledPins[1] = second mailbox (contains 6)
  • ledPins[2] = third mailbox (contains 7)
  • ledPins[3] = fourth mailbox (contains 8)

Important: Arrays start counting from 0, not 1!

Using Arrays in Loops:

for(int i = 0; i < 4; i++) {
  pinMode(ledPins[i], OUTPUT);
}
  • i is a counter that goes 0, 1, 2, 3
  • ledPins[i] uses the counter to access each mailbox
  • When i=0: pinMode(ledPins[0], OUTPUT)pinMode(5, OUTPUT)
  • When i=1: pinMode(ledPins[1], OUTPUT)pinMode(6, OUTPUT)
  • And so on…

This is much shorter than writing four separate pinMode lines!

Coding Challenge

Create a pattern where:

  1. All LEDs blink together 3 times
  2. Then do the Knight Rider scanning pattern
  3. Repeat

Activity 5: Light-Responsive System (30 minutes)

Learning Goals

  • Understand analog input
  • Learn about sensor reading and mapping
  • Practice using the Serial Monitor for debugging

Step 1: Add Light Sensor

Physical Circuit Setup: Keep one LED connected from previous activities and add:

Components needed: 1 photoresistor (LDR), 1 × 10kΩ resistor, jumper wires

Building the light sensor circuit:

  1. Insert photoresistor: Place one leg in a breadboard row, other leg in a different row
  2. Create voltage divider:
    • Connect jumper wire from Arduino 5V to one leg of photoresistor
    • Connect jumper wire from Arduino A0 to the SAME leg of photoresistor
    • Connect 10kΩ resistor from the OTHER leg of photoresistor to ground rail
    • Connect Arduino GND to ground rail

How the Voltage Divider Works:

  • Bright light: Photoresistor has low resistance → more voltage at A0 (higher reading)
  • Dark conditions: Photoresistor has high resistance → less voltage at A0 (lower reading)
  • The 10kΩ resistor creates a reference point so voltage changes as light changes

Why Analog Pin A0?

  • Digital pins can only detect ON/OFF (HIGH/LOW)
  • Analog pins can detect different voltage levels
  • Light sensors give varying voltages, not just on/off signals

Step 2: Reading Light Values

void setup() {
  pinMode(8, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int lightLevel = analogRead(A0);
  Serial.println(lightLevel);
  delay(100);
}

Watch the Serial Monitor – cover the sensor with your hand and see the values change!

Step 3: Light-Controlled LED Brightness

void setup() {
  pinMode(8, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int lightLevel = analogRead(A0);
  
  // Convert sensor reading (0-1023) to LED brightness (0-255)
  int brightness = map(lightLevel, 0, 1023, 0, 255);
  
  analogWrite(8, brightness);
  
  // Show values for debugging
  Serial.print("Light: ");
  Serial.print(lightLevel);
  Serial.print(" Brightness: ");
  Serial.println(brightness);
  
  delay(50);
}

Understanding New Concepts

analogRead():

int lightLevel = analogRead(A0);
  • Reads the voltage on an analog pin
  • Returns a number between 0 and 1023
  • 0 = 0 volts, 1023 = 5 volts
  • 512 = 2.5 volts (middle)

Why 0-1023? Arduino uses a 10-bit ADC (Analog-to-Digital Converter):

  • 10 bits can represent 2^10 = 1024 different values (0 to 1023)

map() function: Converts one range of numbers to another:

int brightness = map(lightLevel, 0, 1023, 0, 255);

Takes lightLevel (which ranges 0-1023)

Maps it to brightness (which needs to range 0-255)

If lightLevel = 0, brightness = 0

If lightLevel = 1023, brightness = 255

If lightLevel = 512, brightness = 127 (middle)

Serial Monitor for Debugging:

Serial.print("Light: ");
Serial.println(lightLevel);

  • Serial.print() displays text without starting a new line
  • Serial.println() displays text and starts a new line
  • Lets you see what values your sensors are actually reading
  • Essential for troubleshooting!

Step 4: Smart Night Light

void setup() {
  pinMode(8, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int lightLevel = analogRead(A0);
  
  if(lightLevel < 300) {  // If it's dark
    digitalWrite(8, HIGH);  // Turn LED on
    Serial.println("Dark - LED ON");
  } else {  // If it's bright
    digitalWrite(8, LOW);   // Turn LED off
    Serial.println("Bright - LED OFF");
  }
  
  delay(100);
}

Coding Challenge

Create an “automatic dimmer” that:

  • In bright light: LED is off
  • In medium light: LED is dim
  • In dark conditions: LED is bright

Hint: Use if/else if/else statements with different light level thresholds.

Putting It All Together: Mini Project (15 minutes)

Challenge: Smart Room Controller

Combine everything you’ve learned to create a system that:

  1. Uses the button to switch between 3 modes:
    • Mode 1: Normal light (always on)
    • Mode 2: Night light (automatic based on light sensor)
    • Mode 3: Party mode (blinking pattern)
  2. Uses the Serial Monitor to show the current mode

Starter Code Structure

int mode = 1;  // Start in mode 1
bool lastButtonState = HIGH;

void setup() {
  // Set up pins and serial
}

void loop() {
  // Read button and change mode if pressed
  
  // Execute current mode
  if(mode == 1) {
    // Normal light mode
  } else if(mode == 2) {
    // Night light mode
  } else if(mode == 3) {
    // Party mode
  }
}

Guide to Building Arduino Buggies.

PowerPoint Presentation

Help with CODE FOR BUGGY

// ============================================================================
// ARDUINO BUGGY CONTROL 


// ============================================================================
// STEP 1: PIN DEFINITIONS
// TODO: Fill in the correct pin numbers for your buggy
// Hint: Check your wiring diagram and fill in the missing pin numbers
// ============================================================================

// Motor A (Left motor) pins
int A1A = 7;        // Motor A direction pin 1
int A1B = 6;        // Motor A direction pin 2  
int enA = 5;        // Motor A speed control (PWM)

// Motor B (Right motor) pins
int B1A = _;        // TODO: Fill in Motor B direction pin 1
int B2A = _;        // TODO: Fill in Motor B direction pin 2
int enB = _;        // TODO: Fill in Motor B speed control pin

// Sensor pins
int leftSensor = _;    // TODO: Fill in left line sensor pin
int rightSensor = _;   // TODO: Fill in right line sensor pin

// Ultrasonic sensor pins
int trig = _;          // TODO: Fill in trigger pin
int echo = _;          // TODO: Fill in echo pin

// ============================================================================
// STEP 2: SETUP FUNCTION
// TODO: Set the correct pinMode for each pin
// ============================================================================

void setup() {
  // Motor pins - Set as OUTPUT
  pinMode(A1A, OUTPUT);
  pinMode(A1B, OUTPUT);
  // TODO: Set pinMode for B1A, B2A, enA, enB
  
  // Sensor pins - Set as INPUT
  // TODO: Set pinMode for leftSensor, rightSensor, echo
  
  // Trigger pin - Set as OUTPUT  
  // TODO: Set pinMode for trig
  
  Serial.begin(9600);
  Serial.println("Buggy initialized!");
}

// ============================================================================
// STEP 3: MOVEMENT FUNCTIONS
// TODO: Complete each movement function
// Hint: Think about which pins need to be HIGH/LOW for each direction
// ============================================================================

void forward() {
  // Example for Motor A (left motor)
  digitalWrite(A1A, LOW);
  digitalWrite(A1B, HIGH);
  analogWrite(enA, 200);
  
  // TODO: Complete for Motor B (right motor)
  // What should B1A be? ____
  // What should B2A be? ____
  // Don't forget to set the speed with analogWrite!
}

void stop() {
  // TODO: Set all motor pins to LOW to stop both motors
  // Hint: Set A1A, A1B, B1A, B2A all to LOW
}

void left() {
  // For left turn: stop left motor, run right motor forward
  digitalWrite(A1A, LOW);
  digitalWrite(A1B, LOW);    // Left motor stopped
  
  // TODO: Make right motor go forward
  // What should B1A be? ____
  // What should B2A be? ____
  // Set both motor speeds to 200
}

void right() {
  // For right turn: run left motor forward, stop right motor
  // TODO: Complete this function
  // Make left motor go forward, stop right motor
}

void reverse() {
  // TODO: Make both motors go backwards
  // Hint: This is opposite of forward()
  // For Motor A: A1A should be HIGH, A1B should be LOW
  // What about Motor B?
}

// ============================================================================
// STEP 4: SENSOR READING FUNCTIONS
// TODO: Complete the sensor reading functions
// ============================================================================

int readUltrasonicDistance() {
  // TODO: Complete the ultrasonic sensor reading
  // Hint: Send a pulse, measure the echo time, convert to distance
  
  // Step 1: Send trigger pulse
  digitalWrite(trig, LOW);
  delay(2);
  // TODO: Send HIGH pulse for 10 microseconds
  
  // Step 2: Read echo pulse
  // TODO: Use pulseIn() to measure the echo duration
  long duration = _____;
  
  // Step 3: Convert to distance in cm
  // TODO: Convert duration to distance (duration * 0.034 / 2)
  int distance = _____;
  
  return distance;
}

// ============================================================================
// STEP 5: MAIN LOOP LOGIC
// TODO: Complete the decision-making logic
// ============================================================================

void loop() {
  delay(100);  // Small delay for stability
  
  // Read sensors
  int leftState = digitalRead(leftSensor);
  int rightState = digitalRead(rightSensor);
  int distance = readUltrasonicDistance();
  
  // Debug output
  Serial.print("Left: ");
  Serial.print(leftState);
  Serial.print(" Right: ");
  Serial.print(rightState);
  Serial.print(" Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  
  // =========================================================================
  // OBSTACLE AVOIDANCE (Priority #1)
  // TODO: If obstacle is too close, what should the buggy do?
  // =========================================================================
  
  if (distance < 10) {
    // TODO: What should happen when obstacle is detected?
    // Should it stop? Reverse? Turn?
    return;  // Exit loop iteration
  }
  
  // =========================================================================
  // LINE FOLLOWING LOGIC (Priority #2)
  // TODO: Complete the line following decision tree
  // Remember: LOW = on line, HIGH = off line
  // =========================================================================
  
  if (leftState == LOW && rightState == LOW) {
    // Both sensors on line
    // TODO: What direction should buggy go?
  }
  else if (leftState == HIGH && rightState == LOW) {
    // Left sensor off line, right sensor on line
    // TODO: Which way should buggy turn?
  }
  else if (leftState == LOW && rightState == HIGH) {
    // Left sensor on line, right sensor off line  
    // TODO: Which way should buggy turn?
  }
  else if (leftState == HIGH && rightState == HIGH) {
    // Both sensors off line - maybe at end of line?
    // TODO: What should buggy do? Maybe reverse and try again?
  }
}

// ============================================================================
// CHALLENGE EXTENSIONS (For advanced students)
// ============================================================================

/*
CHALLENGE 1: Add speed control
- Make the buggy go slower when turning
- Make it go faster on straight lines

CHALLENGE 2: Improve obstacle avoidance  
- When obstacle detected, turn left or right instead of just stopping
- Add logic to find a way around obstacles

CHALLENGE 3: Add LED indicators
- Add LEDs to show which direction the buggy is turning
- Add different colored LEDs for different states

CHALLENGE 4: Smooth turning
- Instead of sharp left/right turns, try gradual turns
- Vary the motor speeds instead of stopping one motor completely

CHALLENGE 5: Memory and learning
- Keep track of which directions work better
- Remember successful paths
*/

RUBRIC FOR ASSESSING THE BUGGY PRESENTATION