Overview, Introduction & Prerequisites:
AI Workshop - Teaching In The Age Of AI - STEAM Clown -Β πΌοΈ PresentationΒ
Join us for an engaging workshop on using Artificial Intelligence in STEAM education in ways that support learning, creativity, and critical thinking. This session will explore practical strategies for using AI tools like ChatGPT and Claude to enhance curriculum development, create labs and classroom materials, and help students become stronger problem-solvers rather than passive users of technology. Learn how to teach students to use AI responsibly, ask better questions, develop engineering and coding skills, and leverage AI as a tool for learning instead of simply getting answers. Teachers will leave with practical examples, classroom-ready ideas, and a better understanding of how AI can be integrated into modern STEAM and CTE classrooms.
Prerequisites:
No explicit prerequisite course work, AI Prompt Engineering techniques, Electronics, Logic, or Coding knowledge is helpful. Come as you are. π§ Β
Topics:
Introduction to the Ai in Education
The Perfect Prompt For Curriculum CreationΒ
How to be Awesome
I'm a huge supporter of Open Source and Creative Commons resources.Β This is another way of saying Free, Equitable and Accessible resources...Β π½οΈ π§ π° π ππ οΈ πΌοΈ - Want to Support Me on this endeavor?
Let's get started... Its going to be a wild, fun, awesome ride...
Web Site: WWW.STEAMCLOWN.ORG | Contact: TopClown@STEAMClown.org | LinkedIn: Jim Burnham | You Tube: jimTheSTEAMClown | TikTok: STEAM Clown
Consider Supporting my Open Source STEAM Curriculum Development -- Check Out My How To Help Page -Β Patreon, PayPal, Venmo, My Amazon WishlistΒ
Note: TEACHERS!!!! If you are going to use any of these lessons or labs, please let me know.Β I would really like to understand how you are using this material.Β I want to know what works, what does not work, what would you like me to add, and how I can make it better.Β If you changed something, let me know, because it's probably a good idea and you should share it with me, so I can add it and share with everyone else.Β
This Module or lesson is how I teach in my class. Many of the lessons might be specific to my class, but you could probably adjust them for your class.Β I'll try to make them a neutral as I can, so they can be used in any Mathematics, Physics, Computer Science, or any other Engineering / Technology class.Β Let me know how I can make that better. I'll try to keep this unit current and relevant.Β Please let me know if any resource links are broken or not accessible.
Send me email at TopClown@STEAMClown.org Β You can also Join the STEAM Clown's Mailing List.Β If you want to Unsubscribe, click my Unsubscribe From Mailing List link
Author: Jim Burnham - TopClown@STEAMClown.org. License: Distributed as Open Source.Β
Primer: Β "Aaron, I can imagine no way in which this thing could be considered anywhere remotely close to safe. All I know is I spent six hours in there and I'm still alive... You still want to do it?"
As with any activity, please make sure you are using appropriate safety equipment. Β If you are coding, writing, reading, or working a lab, make sure you stand up and stretch every hour or so,Β Please consider any safety issues connecting to a Raspberry Pi, Arduino, computers and other electronic equipment.
βHow do we preserve authentic learning when students can instantly generate answers with AI?β
AI Workshop - Teaching In The Age Of AI - STEAM Clown -Β πΌοΈ PresentationΒ
AI Documentation Rules - πΈοΈ Web Links - GitHub - Use these rules when specifying how AI should document and report results
AI Rules For Study Guide Prompt - πΈοΈ Web Links - GitHub - Use this link to describe the AI role and expected output for a study guide
The biggest mistake teachers make is using prompts that are too short and too vague.
Arduino C++ Code:
/**
Β * Photoresistor (LDR) + LED Demo
Β *Β
Β * Reads analog light level from a photoresistor voltage divider on A0.
Β * Turns on an LED connected to Pin 13 when the reading exceeds 1000.
Β *
Β * Wiring:
Β * Β Photoresistor (LDR):
Β * Β Β - One legΒ β 5V
Β * Β Β - Other leg β A0 AND one end of a 10kΞ© pull-down resistor
Β * Β Β - Other end of 10kΞ© resistor β GND
Β *
Β * Β LED:
Β * Β Β - Anode (+) β 220Ξ© resistor β Pin 13
Β * Β Β - Cathode (-) β GND
Β *
Β * Analog range: 0 (dark) to 1023 (bright)
Β * Threshold: 1000 β adjust LIGHT_THRESHOLD to tune sensitivity
Β */
// ββββββββββββββββββββββββββββββββββββββββββββββ
// Pin definitions
// ββββββββββββββββββββββββββββββββββββββββββββββ
const int LDR_PIN = A0; Β // Analog input: photoresistor voltage divider
const int LED_PIN = 13; Β // Digital output: LED (built-in LED on most boards)
// ββββββββββββββββββββββββββββββββββββββββββββββ
// Configuration
// ββββββββββββββββββββββββββββββββββββββββββββββ
const int LIGHT_THRESHOLD = 1000;Β // 0β1023; LED turns ON above this value
const int SAMPLE_DELAY_MS = 100; Β // Milliseconds between readings
// ββββββββββββββββββββββββββββββββββββββββββββββ
// setup() β runs once on power-up or reset
// ββββββββββββββββββββββββββββββββββββββββββββββ
void setup() {
Β Β pinMode(LED_PIN, OUTPUT);Β Β Β Β // Configure LED pin as output
Β Β digitalWrite(LED_PIN, LOW);Β Β Β // Ensure LED starts OFF
Β Β Serial.begin(9600);Β Β Β Β Β Β Β // Open serial monitor for debugging
Β Β Serial.println("Photoresistor monitor started.");
Β Β Serial.print("Threshold: ");
Β Β Serial.println(LIGHT_THRESHOLD);
}
// ββββββββββββββββββββββββββββββββββββββββββββββ
// loop() β runs repeatedly after setup()
// ββββββββββββββββββββββββββββββββββββββββββββββ
void loop() {
Β Β // Read the analog voltage from the LDR voltage divider (0β1023)
Β Β int lightLevel = analogRead(LDR_PIN);
Β Β // Determine LED state based on threshold
Β Β if (lightLevel > LIGHT_THRESHOLD) {
Β Β Β Β digitalWrite(LED_PIN, HIGH); Β // Bright enough β turn LED ON
Β Β } else {
Β Β Β Β digitalWrite(LED_PIN, LOW);Β Β // Too dark β turn LED OFF
Β Β }
Β Β // Print reading to Serial Monitor for debugging / calibration
Β Β Serial.print("Light level: ");
Β Β Serial.print(lightLevel);
Β Β Serial.print("Β |Β LED: ");
Β Β Serial.println(lightLevel > LIGHT_THRESHOLD ? "ON" : "OFF");
Β Β delay(SAMPLE_DELAY_MS);Β Β Β Β Β // Short pause before next sample
}
Key points to note:
The voltage divider is what makes this work. The 10kΞ© pull-down resistor and the photoresistor share the same node that feeds A0. As light increases, the LDR's resistance drops, more voltage appears at A0, and the reading climbs toward 1023.
Calibration tip β the right threshold depends on your specific LDR and ambient lighting. Upload the sketch, open Serial Monitor at 9600 baud, and watch the live readings. In your target "bright" condition, note the reading and set LIGHT_THRESHOLD just below it.
Adjustable constants at the top:
Constant Β Β Β Β Β Β Β Β Β Β Β Β Β Default Β Β Β Β Β Β Β Β Β Β Β Purpose
LIGHT_THRESHOLDΒ Β Β Β 1000 Β Β Β Β Β Β Β Β Β Β Β Β Trigger point (0β1023)
SAMPLE_DELAY_MS Β Β Β 100 Β Β Β Β Β Β Β Β Β Β Β Β Β Loop rate in milliseconds
LED_PINΒ Β Β Β Β Β Β Β Β Β Β Β Β Β 13 Β Β Β Β Β Β Β Β Β Β Β Β Β Β Change if using an external LED pin
βA good AI Prompt is like a well-planned garden β the more carefully you prepare the soil, structure, and boundaries, the more meaningful the growth will be.β - Claude
A strong AI prompt for teachers should do more than just ask for βlesson content.β The best prompts establish "Who" the AI is, "What" are your goals, and the Pedagogy of how you want the results represented
GitHub: AI Rules For Study Guide Prompt
The educational role of the AI
Student age/skill level
Course context
Learning objectives
Teaching philosophy
Required outputs
Formatting rules
Assessment depth
Real-world relevance
Differentiation and scaffolding
Hands-on lab integration
Misconceptions students may have
Safety considerations
Extension pathways
The biggest mistake teachers make is using prompts that are too short and too vague.
Preparing the Prompt Rules for an Engineering or STEAM based "chat" - πΈοΈ GitHub Web LinksΒ
pull the documentation rules from https://raw.githubusercontent.com/jimTheSTEAMClown/Robots-Rovers-Project-Template/refs/heads/main/AI-Rules/AI-Rules-Documentation-Projects.mdΒ
please generate a template for a prompt I might use for generating a study guide for students.Β Please have to following prompt input options headings with an example prompt rule for each based on my Mechatronics class:
The Educational Role Of The AI
Student Age/Skill Level
Course Context
Learning Objectives
Teaching Philosophy
Required Outputs
Formatting Rules
Assessment Depth
Real-World Relevance
Differentiation And Scaffolding
Hands-On Lab Integration
Misconceptions Students May Have
Safety Considerations
Extension Pathways Add the prompt heading for each bullet section with a 1-2 lines specifying the "rule". I'm targeting high school students in Mechatronics Engineering, please add some generic engineering focused context for each of these bullets. I will then use this to edit a specific prompt for a specific engineering topic.
Ask any questions to clarify what I want if you need to.
Edit this Prompt for your specific topic, career focus
Preparing the Prompt Rules for an Engineering or STEAM based "chat" - πΈοΈ GitHub Web LinksΒ
--- BEGIN PROMPT ---
## The Educational Role of the AI
You are an experienced Mechatronics Engineering instructor and industry mentor.
Write in a clear, direct, encouraging voice aimed at high school students.
Explain the "why" behind every concept before the "how." Use analogies to
everyday systems (cars, bikes, appliances) to ground abstract engineering ideas.
## Student Age and Skill Level
Students are 10th through 12th graders enrolled in a Mechatronics Engineering
pathway at a California CTE high school. They have completed introductory
Arduino programming (digital I/O, analogWrite, Serial monitor) and basic
electronics (voltage, current, resistance, Ohm's Law). They are comfortable
reading simple schematics but have limited experience with motor control or
PWM signals.
## Course Context
Course: SVCTE Mechatronics Engineering β Robots and Rovers Unit
Unit 7: Motor Control and Drive Systems
This study guide follows the PWM and analogWrite lab and precedes the
closed-loop PID control unit. Students have wired and tested an L298N
motor driver but have not yet written speed-ramping code.
## Learning Objectives
By the end of this study guide, students will be able to:
1. Explain how PWM signals control motor speed using duty cycle.
2. Identify the role of the H-bridge in controlling motor direction.
3. Read and interpret an L298N motor driver wiring diagram.
4. Write Arduino C++ code to control a differential drive rover's speed and direction.
5. Debug a non-moving rover by systematically checking power, signal, and code.
6. Explain why motor speed ramping prevents mechanical stress and current spikes.
## Teaching Philosophy
Hands-on before theory: introduce what students will build first, then explain why it works.
Use annotated code examples with # LEARN: comments explaining key decisions.
Prefer real wiring diagrams described in text over abstract block diagrams.
Depth over breadth: cover differential drive motor control thoroughly rather
than surveying all motor types.
## Required Outputs
- A student study guide in Markdown with the following sections:
Β Β - Overview (what this guide covers and why it matters)
Β Β - Key Vocabulary (table: term, definition, example)
Β Β - Concept Explanations (PWM, H-bridge, differential drive, speed ramping)
Β Β - Wiring Reference (L298N to Arduino Mega pin mapping table)
Β Β - Annotated Arduino Code Example (forward, reverse, turn, stop)
Β Β - Common Mistakes and How to Fix Them
Β Β - Check for Understanding (5 questions: 2 recall, 2 application, 1 debug scenario)
Β Β - Safety Notes
Β Β - Extension Pathways
Β Β - Sources
## Formatting Rules
Follow all STEAM Clown Documentation Rules:
- Single H1 (document title only)
- Labeled code fences (arduino for .ino code, text for pin tables)
- No raw HTML
- Mermaid diagrams where applicable
- No bare URLs β all links as [text](url)
- No Master/Slave terminology β use Controller/Peripheral or Primary/Secondary
- Source citations at the bottom in a Sources section
- No em dashes, no emojis in headings
## Assessment Depth
Include recall questions (define PWM duty cycle, identify H-bridge pins) and
application questions (predict motor behavior given a specific duty cycle,
identify the bug in a provided code snippet). Include one "debug this rover"
scenario where the motor spins in only one direction.
## Real-World Relevance
Connect differential drive to electric wheelchairs, warehouse robots (Amazon
Kiva), autonomous lawn mowers, and FIRST Robotics drive trains. Explain
why industry uses speed ramping to protect gearboxes and reduce inrush current.
## Differentiation and Scaffolding
Tier 1 (Foundational): Define PWM with a light dimmer analogy. Show a simple
forward/stop code example only.
Tier 2 (Standard): Full differential drive code with direction control.
Tier 3 (Challenge): Add speed ramping with a for-loop and explain the
relationship between ramp rate and motor current draw.
## Hands-On Lab Integration
Suggest a bench activity: students measure PWM frequency and duty cycle on
an oscilloscope at analogWrite values of 64, 128, and 255, then correlate
measured duty cycle to observed motor speed. Connect to the upcoming PID lab.
## Misconceptions Students May Have
- "Higher voltage always means faster motor" β address that PWM controls
Β Β speed at a fixed supply voltage by varying on-time, not voltage level.
- "The L298N controls the motor directly" β clarify that the driver
Β Β amplifies the Arduino's logic signal; the Arduino does not power the motor.
- "analogWrite outputs a real analog voltage" β explain that it outputs a
Β Β digital PWM signal that averages out to appear analog to the motor.
## Safety Considerations
- Maximum 12V supply for L298N in student lab configurations.
- Always connect motor ground and Arduino ground (common ground) or the
Β Β motor will not respond.
- Disconnect power before rewiring. Motors can draw high inrush current
Β Β on startup β never hold wires by hand while powering on.
- Include a software E-Stop: always provide a stop() function students
Β Β can call in an emergency.
## Extension Pathways
- Implement closed-loop speed control using wheel encoders (leads into PID unit).
- Explore the Adafruit Motor Shield v2 as a higher-level abstraction.
- Research FIRST Robotics drive train options (tank drive, swerve drive, mecanum).
- Investigate brushless DC motors (BLDC) and ESC control as used in drones.
--- END PROMPT ---
GitHub Study Guide Prompt TemplateΒ - πΈοΈ GitHub Web LinksΒ
GitHub Project Template - AI Rules - πΈοΈ GitHub Web LinksΒ
AI Assist Disclosure: This document was generated with AI assistance (Claude), reviewed and refined by Jim The STEAM Clown, and validated against STEAM Clown documentation rules. Content accuracy has not yet been fully verified β use with appropriate judgment.
You have wired an L298N motor driver and made a motor spin. Now it is time to understand exactly why it spins, how to control how fast and in what direction it spins, and how to get two motors working together to steer a rover. This guide connects the circuits on your bench to real engineering concepts used in electric wheelchairs, warehouse robots, and FIRST Robotics drive trains.
By the end of this guide you will be able to write Arduino code that drives your rover forward, backward, and through turns, and you will know how to debug it when something goes wrong.
Term
Definition
Example
PWM (Pulse Width Modulation)
A digital signal that switches rapidly between HIGH and LOW to simulate a variable output level
analogWrite(ENA, 128) sends a 50% duty cycle signal
Duty Cycle
The percentage of time a PWM signal is HIGH in one period
128 out of 255 = roughly 50% duty cycle
H-Bridge
A circuit that can send current through a motor in either direction, allowing forward and reverse
The L298N chip contains two H-bridges
Motor Driver
An IC that uses small logic signals from a microcontroller to switch high-current paths to a motor
L298N takes 5V logic from the Arduino and switches up to 2A to the motors
Differential Drive
A drive system where two independently controlled wheels steer the vehicle by spinning at different speeds
A robot turns left by slowing the left motor and speeding the right motor
Speed Ramping
Gradually increasing or decreasing motor speed instead of jumping immediately to full speed or stop
Using a for-loop to step speed from 0 to 255 over 500ms
Inrush Current
A large spike of current drawn by a motor the instant it starts from rest
Jumping a motor from 0 to 255 instantly can draw 5 to 10 times normal current
Enable Pin
The L298N pin that accepts a PWM signal to control motor speed
ENA controls Motor A speed; ENB controls Motor B speed
Input Pins
The L298N pins that set motor direction (IN1/IN2 for Motor A, IN3/IN4 for Motor B)
IN1 HIGH and IN2 LOW = Motor A spins forward
Back-EMF
Voltage generated by a spinning motor that pushes back against the supply voltage
Back-EMF is why a motor slows down when it hits a load
Imagine a light switch you flip on and off very fast, 1000 times per second. If it is on half the time and off half the time, the bulb appears half as bright. If it is on 75% of the time, it appears 75% as bright. Your eye averages out the flicker.
A DC motor works the same way. Its spinning mass averages out the rapid on/off pulses. The longer the signal stays HIGH each cycle, the faster the motor spins. That percentage of on-time is the duty cycle.
On the Arduino, analogWrite(pin, value) controls duty cycle:
analogWrite Value
Duty Cycle
Motor Behavior
0
0%
Motor stopped
64
25%
Slow
128
50%
Medium
192
75%
Fast
255
100%
Full speed
Important: analogWrite does not output a real analog voltage. It outputs a digital pulse train that averages to that voltage level. You can verify this with an oscilloscope.
graph LR
Β Β Β Β A["Arduino Pin\n(5V digital)"] -->|PWM Signal| B["L298N Enable Pin"]
Β Β Β Β B -->|Switched current| C["DC Motor"]
Β Β Β Β C -->|Speed proportional\nto duty cycle| D["Rover Wheel"]
A plain transistor switch can only turn a motor on or off. An H-bridge uses four switches arranged in an H shape to route current through the motor in either direction.
graph TD
Β Β Β Β PWR["12V Supply"]
Β Β Β Β GND["Ground"]
Β Β Β Β S1["Switch 1"]Β
Β Β Β Β S2["Switch 2"]
Β Β Β Β S3["Switch 3"]
Β Β Β Β S4["Switch 4"]
Β Β Β Β M["Motor"]
Β Β Β Β PWR --> S1
Β Β Β Β PWR --> S3
Β Β Β Β S1 --> M
Β Β Β Β M --> S4
Β Β Β Β S3 --> M
Β Β Β Β M --> S2
Β Β Β Β S2 --> GND
Β Β Β Β S4 --> GND
Close S1 and S4: current flows left-to-right through the motor. Forward. Close S3 and S2: current flows right-to-left through the motor. Reverse. Close S1 and S3 at the same time: short circuit. Never do this.
The L298N IC handles all of this internally. You control it with logic signals from the Arduino.
IN1
IN2
Motor A Direction
HIGH
LOW
Forward
LOW
HIGH
Reverse
LOW
LOW
Stop (coast)
HIGH
HIGH
Brake (avoid)
Your rover has no steering wheel. It turns the same way a tank does: by spinning the two drive wheels at different speeds.
Left Motor
Right Motor
Rover Movement
Forward
Forward (same speed)
Straight forward
Reverse
Reverse (same speed)
Straight backward
Forward fast
Forward slow
Gradual left turn
Forward
Stopped
Pivot left
Forward
Reverse
Spin in place left
This is called differential drive because the difference in wheel speeds determines the turn radius. Electric wheelchairs, the Roomba, Amazon Kiva warehouse robots, and most FIRST Robotics tank-drive robots all use this principle.
When you tell your motor to jump from 0 to 255 instantly, the motor draws a huge inrush current spike and the gearbox experiences a sharp mechanical jolt. Over time this cracks gear teeth and wears out motor brushes.
Speed ramping gradually increases or decreases speed using a loop:
// LEARN: This for-loop steps speed up in small increments.
//Β Β Β Β Each step adds 5 to the duty cycle and waits 10ms.
//Β Β Β Β The motor accelerates smoothly instead of lurching.
for (int speed = 0; speed <= 255; speed += 5) {
Β Β Β Β analogWrite(ENA, speed);
Β Β Β Β analogWrite(ENB, speed);
Β Β Β Β delay(10);
}
Industry uses speed ramping to protect gearboxes, reduce inrush current, and comply with motor controller specifications. The same principle appears in electric vehicle accelerator curves and industrial servo drives.
Connect your L298N motor driver to the Arduino Mega using the following pin assignments. Always double-check polarity before powering on.
L298N PinΒ Β Arduino Mega PinΒ Β Purpose
---------Β Β ----------------Β Β -------
ENAΒ Β Β Β Β Pin 2 Β Β Β Β Β Β Β Motor A speed (PWM)
IN1Β Β Β Β Β Pin 3 Β Β Β Β Β Β Β Motor A direction control
IN2Β Β Β Β Β Pin 4 Β Β Β Β Β Β Β Motor A direction control
IN3Β Β Β Β Β Pin 5 Β Β Β Β Β Β Β Motor B direction control
IN4Β Β Β Β Β Pin 6 Β Β Β Β Β Β Β Motor B direction control
ENBΒ Β Β Β Β Pin 7 Β Β Β Β Β Β Β Motor B speed (PWM)
GNDΒ Β Β Β Β GND Β Β Β Β Β Β Β Β Common ground (REQUIRED)
+12V Β Β Β Β External 12V supply Motor power supply
+5V (out)Β Β OptionalΒ Β Β Β Β Β Can power Arduino if jumper set
Motor A OutΒ Left motorΒ Β Β Β Β Motor A terminals
Motor B OutΒ Right motor Β Β Β Β Motor B terminals
Critical: The Arduino GND and the L298N GND must be connected together (common ground). Without this, the L298N will not respond to the Arduino's logic signals.
// =============================================================
// Differential Drive Motor Control
// SVCTE Mechatronics β Robots and Rovers Unit 7
// =============================================================
// LEARN: Defining pin numbers as constants makes the code easier
//Β Β Β Β to read and update. If you rewire, change it here once.
const int ENA = 2; Β // Motor A (left) speed
const int IN1 = 3; Β // Motor A direction
const int IN2 = 4; Β // Motor A direction
const int IN3 = 5; Β // Motor B direction
const int IN4 = 6; Β // Motor B direction
const int ENB = 7; Β // Motor B (right) speed
// LEARN: Using a constant for speed lets you tune behavior in
//Β Β Β Β one place. 180 out of 255 = about 70% duty cycle.
const int CRUISE_SPEED = 180;
// -------------------------------------------------------
// E-STOP: Call stop() immediately if anything goes wrong.
// This is your emergency brake. Always write it first.
// -------------------------------------------------------
void stop() {
Β Β Β Β analogWrite(ENA, 0);
Β Β Β Β analogWrite(ENB, 0);
Β Β Β Β digitalWrite(IN1, LOW);
Β Β Β Β digitalWrite(IN2, LOW);
Β Β Β Β digitalWrite(IN3, LOW);
Β Β Β Β digitalWrite(IN4, LOW);
}
// -------------------------------------------------------
// Drive forward at a given speed (0-255)
// -------------------------------------------------------
void forward(int speed) {
Β Β Β Β // LEARN: IN1 HIGH and IN2 LOW tells the H-bridge to
Β Β Β Β //Β Β Β Β send current through Motor A in the forward direction.
Β Β Β Β digitalWrite(IN1, HIGH);
Β Β Β Β digitalWrite(IN2, LOW);
Β Β Β Β digitalWrite(IN3, HIGH);
Β Β Β Β digitalWrite(IN4, LOW);
Β Β Β Β analogWrite(ENA, speed);
Β Β Β Β analogWrite(ENB, speed);
}
// -------------------------------------------------------
// Drive in reverse at a given speed (0-255)
// -------------------------------------------------------
void reverse(int speed) {
Β Β Β Β digitalWrite(IN1, LOW);
Β Β Β Β digitalWrite(IN2, HIGH);
Β Β Β Β digitalWrite(IN3, LOW);
Β Β Β Β digitalWrite(IN4, HIGH);
Β Β Β Β analogWrite(ENA, speed);
Β Β Β Β analogWrite(ENB, speed);
}
// -------------------------------------------------------
// Turn left: right motor drives, left motor stops
// -------------------------------------------------------
void turnLeft(int speed) {
Β Β Β Β // LEARN: Differential drive turns by slowing or stopping
Β Β Β Β //Β Β Β Β one side. This pivots around the stopped wheel.
Β Β Β Β digitalWrite(IN1, LOW);
Β Β Β Β digitalWrite(IN2, LOW); Β // Left motor stopped
Β Β Β Β digitalWrite(IN3, HIGH);
Β Β Β Β digitalWrite(IN4, LOW); Β // Right motor forward
Β Β Β Β analogWrite(ENA, 0);
Β Β Β Β analogWrite(ENB, speed);
}
// -------------------------------------------------------
// Turn right: left motor drives, right motor stops
// -------------------------------------------------------
void turnRight(int speed) {
Β Β Β Β digitalWrite(IN1, HIGH);
Β Β Β Β digitalWrite(IN2, LOW); Β // Left motor forward
Β Β Β Β digitalWrite(IN3, LOW);
Β Β Β Β digitalWrite(IN4, LOW); Β // Right motor stopped
Β Β Β Β analogWrite(ENA, speed);
Β Β Β Β analogWrite(ENB, 0);
}
// -------------------------------------------------------
// Ramp up to speed smoothly to protect the gearbox
// -------------------------------------------------------
void rampForward(int targetSpeed) {
Β Β Β Β // LEARN: Stepping in increments of 5 with a 10ms delay
Β Β Β Β //Β Β Β Β gives a 0.5 second ramp to full speed.
Β Β Β Β //Β Β Β Β Increase the delay to ramp more slowly.
Β Β Β Β for (int s = 0; s <= targetSpeed; s += 5) {
Β Β Β Β Β Β Β Β digitalWrite(IN1, HIGH);
Β Β Β Β Β Β Β Β digitalWrite(IN2, LOW);
Β Β Β Β Β Β Β Β digitalWrite(IN3, HIGH);
Β Β Β Β Β Β Β Β digitalWrite(IN4, LOW);
Β Β Β Β Β Β Β Β analogWrite(ENA, s);
Β Β Β Β Β Β Β Β analogWrite(ENB, s);
Β Β Β Β Β Β Β Β delay(10);
Β Β Β Β }
}
void setup() {
Β Β Β Β pinMode(ENA, OUTPUT);
Β Β Β Β pinMode(IN1, OUTPUT);
Β Β Β Β pinMode(IN2, OUTPUT);
Β Β Β Β pinMode(IN3, OUTPUT);
Β Β Β Β pinMode(IN4, OUTPUT);
Β Β Β Β pinMode(ENB, OUTPUT);
Β Β Β Β // LEARN: Always start in a known safe state.
Β Β Β Β stop();
Β Β Β Β Serial.begin(9600);
Β Β Β Β Serial.println("Rover ready.");
}
void loop() {
Β Β Β Β rampForward(CRUISE_SPEED); Β // Smooth start
Β Β Β Β delay(2000); Β Β Β Β Β Β Β Β // Drive forward 2 seconds
Β Β Β Β stop();
Β Β Β Β delay(500);
Β Β Β Β turnLeft(CRUISE_SPEED);Β Β Β // Pivot left
Β Β Β Β delay(600);
Β Β Β Β stop();
Β Β Β Β delay(500);
Β Β Β Β rampForward(CRUISE_SPEED); Β // Forward again
Β Β Β Β delay(2000);
Β Β Β Β stop();
Β Β Β Β delay(5000); Β Β Β Β Β Β Β Β // Pause before repeating
}
Symptom
Likely Cause
Fix
Motor does not move at all
Missing common ground between Arduino and L298N
Connect L298N GND to Arduino GND
Motor spins in only one direction
IN pins swapped or wired to wrong Arduino pins
Verify IN1/IN2 wiring against the pin table; test each pin with digitalWrite in isolation
Motor runs but ignores analogWrite speed
ENA or ENB pin not defined as OUTPUT, or jumper still installed on EN pins
Call pinMode(ENA, OUTPUT) in setup; remove the enable jumper if present
Both motors spin but rover drives in a circle
One motor wired in reverse polarity
Swap the two motor terminal wires on the backwards motor
Arduino resets when motors start
Motors pulling too much current through Arduino's 5V
Power L298N from an external supply, not the Arduino's 5V pin
Speed feels the same at 100 and 255
Motor stall torque threshold: below a minimum duty cycle the motor does not overcome friction
Find your motor's minimum effective analogWrite value experimentally (typically 80 to 100)
1. What is duty cycle, and what analogWrite value produces a 50% duty cycle on an Arduino?
2. Fill in the table: what direction does Motor A spin for each combination of IN1 and IN2?
IN1 Β Β IN2 Β Β Motor A Direction
----- Β ----- Β -----------------
HIGHΒ Β LOW Β Β ?
LOW Β Β HIGHΒ Β ?
LOW Β Β LOW Β Β ?
3. Your rover needs to turn right with a wider arc (gradual curve, not a sharp pivot). You are currently using turnRight() which stops the right motor completely. How would you modify the code to make the right motor run at 30% speed instead of stopping? Write the two lines you would change.
4. A classmate claims that setting analogWrite(ENA, 255) on an L298N powered by 9V will make the motor run at 9V. A different classmate says it will run faster than at 6V because the duty cycle is higher. Who is right, and why?
5. You upload the code below. The rover's right motor spins forward correctly, but the left motor spins in reverse when it should go forward. The wiring looks correct on the breadboard. What is the bug in the code, and how do you fix it?
void forward(int speed) {
Β Β Β Β digitalWrite(IN1, LOW); Β // Left motor
Β Β Β Β digitalWrite(IN2, HIGH);Β // Left motor
Β Β Β Β digitalWrite(IN3, HIGH);Β // Right motor
Β Β Β Β digitalWrite(IN4, LOW); Β // Right motor
Β Β Β Β analogWrite(ENA, speed);
Β Β Β Β analogWrite(ENB, speed);
}
Electrical safety.
Maximum supply voltage for the L298N in student lab configurations is 12V. Do not exceed this.
Never connect motor power directly to the Arduino's 5V or VIN pins. Motors draw far more current than the Arduino can supply safely.
Always establish common ground between the Arduino and the L298N before powering on.
Wiring safety.
Disconnect power before changing any wiring. Motors draw a high inrush current spike at startup, and live rewiring can damage components or cause burns.
Double-check polarity on the motor supply before powering on. Reversed polarity can destroy the L298N.
Software safety.
Always write your stop() function first, before any other motor function. Test it before testing forward or reverse.
Include a Serial command or physical button that calls stop() so you can halt the rover instantly during testing.
Never run a rover on a desk or workbench without a tether or a clear perimeter. A rover at full speed will reach the edge of a table in under one second.
Think of PWM like a ceiling fan with a speed dial. The dial does not change the voltage to the fan motor. Instead, it pulses power on and off very rapidly. More on-time means faster spinning. analogWrite(pin, 128) means the signal is HIGH exactly half the time.
Try this minimal example to confirm your motor responds:
const int ENA = 2;
const int IN1 = 3;
const int IN2 = 4;
void setup() {
Β Β Β Β pinMode(ENA, OUTPUT);
Β Β Β Β pinMode(IN1, OUTPUT);
Β Β Β Β pinMode(IN2, OUTPUT);
Β Β Β Β digitalWrite(IN1, HIGH);
Β Β Β Β digitalWrite(IN2, LOW);
Β Β Β Β analogWrite(ENA, 180); Β // Forward at 70% speed
}
void loop() {
Β Β Β Β // Motor runs continuously β no loop code needed for this test
}
Use the full code example above. Get all four functions (forward, reverse, turnLeft, turnRight) working reliably before adding speed ramping.
Add speed ramping to both the ramp-up and ramp-down phases. Then measure the motor's current draw (with a multimeter in series) at:
Instant start (no ramp)
Ramp over 500ms
Ramp over 1500ms
Record your results and explain the relationship between ramp rate and peak inrush current. Why does this matter for battery life on a mobile robot?
Equipment: Oscilloscope, Arduino Mega, L298N, DC motor, jumper wires.
Procedure:
Connect the oscilloscope probe to the ENA pin and ground.
Upload a simple sketch that calls analogWrite(ENA, 64) in setup.
Measure and record the frequency and duty cycle.
Repeat for analogWrite values of 128 and 255.
Observe the motor speed at each setting.
Record your results:
analogWrite ValueΒ Β Measured Duty CycleΒ Β Observed Motor Speed
-----------------Β Β -------------------Β Β --------------------
64 Β Β Β Β Β Β Β Β Β ?Β Β Β Β Β Β Β Β Β Β Β ?
128Β Β Β Β Β Β Β Β Β ?Β Β Β Β Β Β Β Β Β Β Β ?
255Β Β Β Β Β Β Β Β Β ?Β Β Β Β Β Β Β Β Β Β Β ?
Connect forward: In the upcoming PID control unit, you will use a wheel encoder to measure actual speed and close the loop between what you command and what the motor actually does. This lab gives you the open-loop baseline.
Electric wheelchairs use differential drive because it allows precise, responsive steering with no mechanical linkage. The joystick sends different speed commands to left and right motors.
Amazon Kiva (now Amazon Robotics) warehouse robots navigate using differential drive and QR codes on the floor. Speed ramping is essential because they carry loads up to 1,000 lbs and cannot lurch to a start.
Autonomous lawn mowers (Husqvarna Automower, Roomba) use differential drive combined with GPS or boundary wire to navigate yard obstacles.
FIRST Robotics tank drive trains use the same H-bridge and differential drive principles you are learning now. Teams tune speed ramping constants to prevent brownouts during match play, where six motors starting simultaneously can overwhelm the robot's battery.
Closed-loop speed control with encoders. Add wheel encoders to your rover and implement a simple proportional controller that maintains a target speed regardless of load. This leads directly into the PID unit.
Adafruit Motor Shield v2. Explore this library-based abstraction that hides the H-bridge details and adds I2C control. Compare the tradeoffs versus direct L298N control.
FIRST Robotics drive train research. Compare tank drive, swerve drive, and mecanum drive. Explain the tradeoffs in terms of mechanical complexity, software complexity, and maneuverability.
Brushless DC motors and ESCs. Research how ESCs (Electronic Speed Controllers) replace the H-bridge in drone and RC car applications. Why can an ESC handle much higher currents than an L298N?
This Lesson is coming soon - click here to be notified when it's available - Professional Development Newsletter
GitHub Project Template - AI Rules - πΈοΈ Web Links :octocat: π Lesson Tutorial
Mechatronics - <topic> - π½οΈ Video / Podcast
Mechatronics - <topic> - π° Slide Presentation (Coming Soon)
Mechatronics - <topic> - LAB #1 - π οΈ LAB Activity
Mechatronics - <topic> - LAB #2 - π οΈ LAB Activity
Mechatronics - <topic> - LAB #3 - π οΈ LAB Activity
This Lesson is coming soon - click here to be notified when it's available - Professional Development Newsletter
GitHub Project Template - AI Rules - πΈοΈ Web Links :octocat: π Lesson Tutorial
Mechatronics - <topic> - π½οΈ Video / Podcast
Mechatronics - <topic> - π° Slide Presentation (Coming Soon)
Mechatronics - <topic> - LAB #1 - π οΈ LAB Activity
Mechatronics - <topic> - LAB #2 - π οΈ LAB Activity
Mechatronics - <topic> - LAB #3 - π οΈ LAB Activity
If you are a teacher and want to connect and teach this Lesson or Module, discuss how I teach it, give me feedback, please contact me at TopClown@STEAMClown.orgΒ
To access this Lesson Plan and the Teacher collaboration area, you will have needed to connect with me so I can Share the content with you.Β Please go toΒ the Teachers & Partner Page, check out my Licensing and fill out my Collaboration and Curriculum Request Form.Β I'll review and then grant you access to the requested areas and lesson plans if they exist.
If you have questions or feedback on how I can make a presentation, lesson, lab better please give use my Feedback Form.
Iβll work on getting these in, but itβs the last thing I want to work on :-) When I have them updated, Iβll move to the top of the Lesson Plan.Β
NGSS: <list standard numbers>
California CTE Standards: <list standard numbers>
Related Instructional Objectives (SWBAT):Β <list standard numbers>
CCSS: nnn, RSIT: nnn, RLST: nnn, WS: nnn, WHSST: nnn, A-CED: nnn, ETS: nnnΒ <list standard numbers>
Main Standard:
Priority standards:
National Standards:
Reference Text Book - Basic College Mathematics with Early Integers 4th edition - Elayn Martin-Gay - University of New Orleans - Pearson
Reference Sites -Β
https://imgbin.com/png/ZJtzkYZZ/under-construction-png
Key: π° Slides / Audio π§ / π½οΈβΆοΈ Video/YouTube / π§βΆοΈπ½οΈ Audio/Video / β¨ Resources /Β πΌοΈ Tutorial / π Reading Activity / π Writing Activity / π π Reading/Writing / π Coding / π οΈ LAB Activity / π Quiz /Β π Review /Β βοΈ Mastery Check / βοΈ Sign Up /π Extra Credit / πΈοΈ Web Links / π©π½βππ§π½βππ§πΏβππ©βπ« Class / π΅οΈππ Certificate / ποΈ π Collecting Survey Data
/π§ Review / π¦Ύ Practice / πLevel Up /
ποΈπ¦π€π―Β π§
- π¦ Special Project -
Assignment Type: β Establishing (Minimum Standard) / βοΈ Developing (Digging Deeper) / π Aspiring (Putting It Together)
This is an β Establishing Assignment (Minimum Standard)Β - "Everyone Do" Assignment
This is an βοΈ Developing (Digging Deeper) - "Everyone Should Do, To Stretch" Assignment
This is an π Aspiring (Putting It Together)Β - "When you have done the β Establishing andβοΈ Developing" Assignment
π«πFormative Quiz - π Review
π Formative Quiz - π Review
1οΈβ£ Quiz -π Mastery Path
1οΈβ£π Summative Quiz -βοΈ Skills Mastery Check
Quiz - verify that they are all listed as a "Formative", "Mastery Path", or "Summative"Β
π Formative Quiz - These are quizzes that the students can take a few times. I have them either set for unlimited times, or 3-5 times, where the final score is their average. The idea is that these Formative Quizzes are designed for students to learn and master a skill.Β while I want them to ger 100%, and when it's set to unlimited tries, the student should get 100% eventually.Β When the quiz is set to 3-5 tries with an average, then they should be prepared and should take the quiz seriously. I set the quiz to not show the right answer, but I do let them see their wrong answer.Β I also put the explanation of the right and wrong answer in the right and wrong answer prompt for each question.Β That way they can see why they got the answer wrong and learn from that experience.Β Β
8.1.0.3.2.4 - Python - Ch 3 - Functions - Quiz #2 -Built-In Functions - π Formative Quiz
π Quiz -π Mastery Path - These Mastery path quizzes are to be presented after the student has had a chance to do some labs and some Formative quizzes. Β The goal is to let students have 2 chances to take this quiz, and take the average of the 2 attempts.Β Based on the average, they will be presented with a Canvas Mastery Path, where they will have an option for take additional quiz and assignments to help with remediation.Β This will get them ready to take the Summative Quizzes.
8.1.0.3.3.1 -Β Python - Ch 3 - Functions - Mastery Quiz #1 - π Quiz -π Mastery Path
π Summative Quiz -βοΈ Skills Mastery Check - These Mastery path quizzes are to be presented after the student has had a chance to do some labs and some Formative quizzes. Β The goal is to let students have 2 chances to take this quiz, and take the average of the 2 attempts. That will be their final module/subject topic grade.
8.1.0.3.3.1 -Β Python - Ch 3 - Functions - Skills Mastery Check Quiz #1 - π Summative Quiz -βοΈ Skills Mastery Check