πŸ€– Lesson 9: Programming Mechatronics

Hardware + Software Working Together

⏱️ 30 minutes πŸ“š Year 11 Content 🎯 Optional Topic

🎯 MUST KNOW for HSC Exam

Focus your study on these 5 core areas:

  1. Sensors vs Actuators - What they are and examples
  2. Open Loop vs Closed Loop Control - Key differences
  3. Microcontrollers vs CPUs - Why we use microcontrollers
  4. Control Algorithms - Basic structure for mechatronic systems
  5. Accessibility Design - Considerations for people with disabilities

Everything else is "nice to know" but less likely to be examined.

🎯 What is Mechatronics?

Mechatronics

The combination of mechanical parts + electronics + software to create intelligent systems that can sense, decide, and act.

Simple Example: Robot vacuum cleaner

Real-World Applications NICE TO KNOW

Industry Example
Consumer Automatic doors, 3D printers, smart thermostats
Automotive Self-driving cars, parking sensors, cruise control
Medical Surgical robots, prosthetic limbs, automated wheelchairs
Manufacturing Robotic assembly lines, CNC machines, automated warehouses

πŸ’» Microcontrollers vs CPUs MUST KNOW

Microcontroller

A small, specialized computer designed to control hardware devices. Not as powerful as a regular computer, but perfect for specific control tasks.

Popular Example: Arduino Uno

Why Use Microcontrollers Instead of CPUs?

Feature Microcontroller (Arduino) Regular Computer (CPU)
Cost $20 $1000+
Size Fits in your palm Much larger
Power Can run on battery for hours Needs constant wall power
Purpose Dedicated to one task (controlling hardware) Multi-purpose (many programs at once)
Hardware Control Built-in pins for sensors/motors Needs USB adapters

Hardware Requirements NICE TO KNOW

Key Concept: Microcontrollers have limited resources (memory, speed) compared to regular computers. This affects how you write code:

πŸ‘€ Sensors: Input Devices MUST KNOW

Sensor

A device that detects physical properties (light, motion, temperature, distance) and converts them into electrical signals for the microcontroller.

Common Sensor Types

Sensor What It Measures Example Use
Ultrasonic Distance (using sound waves) Robot obstacle avoidance, parking sensors
PIR (Motion) Movement (detects infrared heat) Security alarms, automatic lights
LDR (Light) Light level Auto-dimming screens, streetlights
Temperature Heat/cold Thermostats, 3D printer control
πŸ“ Example: Reading an Ultrasonic Sensor
Arduino C++
// Measure distance to an object
int trigPin = 9;
int echoPin = 10;

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  // Send sound pulse
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Measure time for echo to return
  long time = pulseIn(echoPin, HIGH);

  // Calculate distance (speed of sound = 343 m/s)
  int distance = time * 0.034 / 2;

  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  delay(500);
}

How it works: Send a sound pulse, measure how long it takes to bounce back, calculate distance using the speed of sound.

πŸ’ͺ Actuators: Output Devices MUST KNOW

Actuator

A device that converts electrical signals into physical motion (rotation, linear movement, or force).

Common Actuator Types

Actuator What It Does Example Use
DC Motor Continuous rotation Robot wheels, fans
Servo Motor Precise angle control (0-180Β°) Robot arms, camera gimbals
Stepper Motor Moves in small, precise steps 3D printers, CNC machines
Hydraulic Cylinder High-force linear motion (fluid pressure) Excavators, car brakes

End Effectors / Manipulators NICE TO KNOW

End Effector: The "hand" at the end of a robotic arm that interacts with objects.

πŸ“ Example: Controlling a Servo Motor
Arduino C++
#include <Servo.h>

Servo myServo;

void setup() {
  myServo.attach(9);  // Connect servo to pin 9
}

void loop() {
  myServo.write(0);    // Turn to 0 degrees
  delay(1000);
  myServo.write(90);   // Turn to 90 degrees
  delay(1000);
  myServo.write(180);  // Turn to 180 degrees
  delay(1000);
}

πŸ”„ Control Systems MUST KNOW

Open Loop Control (No Feedback)

Open Loop

Execute a command and hope it worked. No sensor checks if the result is correct.

Example: Traffic lights on a timer (don't check if cars are actually there)

Pros: Simple, cheap, no extra sensors needed

Cons: Can't detect failures or adapt to changes

Open Loop Example
// Just blink LED, don't check if it's working
digitalWrite(LED_PIN, HIGH);
delay(1000);
digitalWrite(LED_PIN, LOW);
delay(1000);

Closed Loop Control (Feedback-Driven)

Closed Loop

Use sensors to continuously monitor the output and adjust if needed. The system "closes the loop" by feeding results back to the controller.

Example: Thermostat (measures temperature and turns heater on/off to maintain 21Β°C)

How It Works:

  1. Set target (e.g., 21Β°C)
  2. Read sensor (current temperature)
  3. Compare: Is it too hot or too cold?
  4. Adjust actuator (turn heater on/off)
  5. Repeat constantly

Pros: Adapts to changes, can detect errors

Cons: More complex, requires sensors

πŸ“ Example: Closed Loop Line-Following Robot
Arduino C++
// Robot that follows a black line on white surface
int leftSensor = A0;
int rightSensor = A1;

void loop() {
  int left = analogRead(leftSensor);
  int right = analogRead(rightSensor);

  // CLOSED LOOP: Check sensors and adjust
  if (left < 500 && right < 500) {
    // Both on black β†’ go straight
    goStraight();
  } else if (left > 500) {
    // Left on white β†’ turn left to find line
    turnLeft();
  } else if (right > 500) {
    // Right on white β†’ turn right
    turnRight();
  }
}

Why closed loop? The robot constantly checks sensors and corrects itselfβ€”much smarter than blindly moving forward!

🧠 Control Algorithms MUST KNOW

Autonomous Control

Autonomous System

A mechatronic system that can make decisions and adapt without human intervention.

Key Features:

  • Perception: Uses sensors to understand environment
  • Decision: Processes data and determines actions
  • Action: Controls actuators to execute commands

Simple Algorithm Pattern:

Control Algorithm Structure
void loop() {
  // 1. SENSE: Read sensors
  int distance = readUltrasonicSensor();

  // 2. DECIDE: Determine action
  if (distance < 20) {
    // Obstacle detected
    action = TURN_RIGHT;
  } else {
    // Path clear
    action = MOVE_FORWARD;
  }

  // 3. ACT: Control actuators
  executeAction(action);
}

πŸ› οΈ Testing with TinkerCAD NICE TO KNOW

πŸ’» TinkerCAD Circuits

What is it? A free online simulator where you can build and test Arduino projects without buying hardware.

Website: tinkercad.com/circuits

Quick Start:

  1. Create free account at tinkercad.com
  2. Click "Circuits" β†’ "Create new Circuit"
  3. Drag Arduino Uno onto workspace
  4. Add sensors (ultrasonic, PIR) and outputs (LEDs, motors)
  5. Wire components by clicking and dragging
  6. Click "Code" β†’ Write your program
  7. Click "Start Simulation" to test!

Pro Tip: Click on sensors during simulation to manually change their readings (e.g., make distance sensor detect something closer).

β™Ώ Accessibility Design MUST KNOW

Accessibility in Mechatronics

Designing systems that people with disabilities can use effectively. Consider different types of impairments when designing input/output mechanisms.

Design Considerations

User Need Design Solution Example Technology
Limited Mobility Voice control, large buttons, automated systems Powered wheelchairs, automatic doors
Vision Impairment Audio feedback (beeps, speech), tactile buttons Talking thermometers, navigation aids with sound
Hearing Impairment Visual alerts (LEDs, screens), vibration feedback Vibrating alarms, visual doorbell systems
Cognitive Impairment Simple interfaces, clear indicators, fail-safe design Medication reminders, one-button emergency alerts

Power and Battery Considerations NICE TO KNOW

Why it matters: Assistive mechatronic devices must have reliable powerβ€”running out of battery could be dangerous.

Key Considerations:

🎯 HSC Exam Focus

What to Memorize for the Exam

  1. Sensor vs Actuator:
    • Sensor = INPUT (detects environment)
    • Actuator = OUTPUT (creates movement)
  2. Open vs Closed Loop:
    • Open = No feedback (simple, can't adapt)
    • Closed = Uses feedback (smarter, self-correcting)
  3. Microcontroller vs CPU:
    • Microcontroller: Small, cheap, low power, dedicated task
    • CPU: Powerful, expensive, high power, multi-purpose
  4. Examples of Each Component:
    • Sensors: Ultrasonic (distance), PIR (motion), LDR (light)
    • Actuators: DC motor, servo motor, hydraulic cylinder
  5. Accessibility Features:
    • Vision: Audio feedback, tactile buttons
    • Hearing: Visual alerts, vibration
    • Mobility: Voice control, automation
πŸ’‘ Common Exam Questions
  • "Identify whether X is a sensor or actuator and justify"
  • "Explain the difference between open and closed loop control with examples"
  • "Why would you use a microcontroller instead of a regular computer for a robot?"
  • "Suggest accessibility features for a mechatronic system designed for [specific disability]"
  • "Write pseudocode for a simple control algorithm that uses sensor input"
← Back to Ulrich's Course Home