A 45-Minute Review for Your NESA Exam, Bodhi!
Mechatronics boils down to one simple idea: writing software to control physical things. Think of it like a human body:
Microcontroller (e.g., an Arduino). It runs the code and makes all the decisions.
Sensors (e.g., a knob, a light sensor). They gather information from the world. This is your INPUT.
Actuators (e.g., a motor, an LED). They perform actions in the world. This is your OUTPUT.
Let's see this loop in action. Here's a virtual circuit with our three parts. Click "Start Simulation" and turn the knob (the potentiometer) to see the robot arm (the servo motor) move!
// Include the library for the servo motor
#include <Servo.h>
// Create a servo object to control a servo
Servo myServo;
// Define constants for the pins we are using
const int potPin = A0; // Potentiometer (sensor) is on Analog Pin 0
const int servoPin = 9; // Servo (actuator) is on Digital Pin 9
void setup() {
// Attach the servo object to its pin
myServo.attach(servoPin);
}
void loop() {
// 1. INPUT: Read the value from the sensor (0-1023)
int potValue = analogRead(potPin);
// 2. PROCESS: Convert the sensor reading to a servo angle (0-180)
int angle = map(potValue, 0, 1023, 0, 180);
// 3. OUTPUT: Tell the servo to move to the calculated angle
myServo.write(angle);
// Wait 15 milliseconds to allow the servo to reach its position
delay(15);
}
An open-loop system follows commands but does not use feedback to check if the job was done correctly. It's simple, but not very smart.
A closed-loop system is smarter. It acts, then uses a sensor to get feedback, and then corrects itself. This is the goal for most robotic systems.
How could we make our servo code better with Object-Oriented Programming? We could create a class RoboticArm.
servoPin, currentAngle..moveTo(angle), .readPosition().OOP helps organise complex hardware into reusable, logical blocks.
Q1: A smart cat feeder needs to dispense 1 cup of food at 8 AM. Describe the components it would need.
Brain (Microcontroller): To run the schedule and logic.
Sense (Sensor): A real-time clock to know when it's 8 AM. You could also have a weight sensor to measure 1 cup of food.
Muscle (Actuator): A motor to open and close the food flap.
Q2: A self-driving car must stay in its lane. Justify why it must use a closed-loop system.
It requires a closed-loop system because it needs constant feedback to make corrections.
Action: The car drives forward.
Feedback: Cameras (sensors) detect the lane markings.
Correction: If the car drifts, the microcontroller tells the steering (actuator) to adjust, keeping it centered. An open-loop system would drive straight without correcting for curves or wind, which would be unsafe.
If you remember nothing else, remember these four things: