Pendulum Simulator
Build an app that simulates a simple pendulum β calculates time period, frequency, and angular velocity for different lengths and gravitational values.
π― Learning Goals
- βΉ Understand the parameters of Simple Harmonic Motion (SHM)
- βΉ Analyze how gravity (g) affects periodic movement
- βΉ Perform comparative studies across different planetary gravities
- βΉ Implement real-time physics simulators using Clock timers
π Why This Matters
Pendulums were our first way to accurately tell time and move toward modern synchronicity. Today, they are used in seismometers to detect earthquakes and in sensors that keep tall buildings from swaying too much in the wind.
πUnderstanding Simple Pendulum & SHM
Theory MasterclassA simple pendulum is a mass (called a bob) suspended from a fixed point by a string. When displaced and released, it swings back and forth β this is called Simple Harmonic Motion (SHM). Key Terms: Time Period (T): Time for one complete swing (back and forth). Measured in seconds. Frequency (f): Number of complete swings per second. f = 1/T. Measured in Hertz (Hz). Length (L): Length of the string from pivot to center of bob. g: Gravitational acceleration (9.8 m/sΒ² on Earth) The Formula: T = 2Οβ(L/g) Important Observations: β’ T depends on L and g only β NOT on the mass of the bob! β’ Longer string β slower swing (larger T) β’ Stronger gravity β faster swing (smaller T) β’ On the Moon (g = 1.62 m/sΒ²), a pendulum swings much slower β’ On Jupiter (g = 24.79 m/sΒ²), it swings much faster Angular Frequency: Ο = 2Ο/T = β(g/L) (in rad/s) Maximum Velocity: v_max = Ο Γ A (where A is amplitude) Restoring Force: F = -mg sin(ΞΈ) β -mgΞΈ (for small angles)
Mathematical Foundation
π¨Part A β Designer View (UI Design)
Open MIT App Inventor β Switch to Designer view. Follow each step below to build the interface.
Set up the screen
Title: "Pendulum Simulator" Dark background with physics theme.
Create input section
TextBox: "Length of string (m)" β Hint: "1.0" TextBox: "Amplitude (degrees)" β Hint: "10" (for small angle) TextBox: "Mass of bob (kg)" β Hint: "0.5" (to show it doesn't affect T)
Add gravity selector
Label: "Select Location" Add buttons: "Earth (9.8)", "Moon (1.62)", "Mars (3.72)", "Jupiter (24.79)", "Custom" When Custom is selected, show a TextBox for custom g value. Highlight the selected planet button.
Add Calculate button
Big "Calculate" button + "Compare All Planets" button.
Create results display
Labels: - PeriodLabel: "Time Period: β s" - FrequencyLabel: "Frequency: β Hz" - OmegaLabel: "Angular Frequency: β rad/s" - VmaxLabel: "Max Velocity: β m/s" - ForceLabel: "Max Restoring Force: β N"
Add Canvas for animation
Add a Canvas (300Γ250) to visually simulate the pendulum swing. Draw a circle (bob) and a line (string) that swings back and forth.
π§©Part B β Blocks View (Logic & Calculation)
Switch to Blocks view. Now add the logic that makes your app actually work.
Set gravity based on planet
Create a global variable "g" = 9.8 When EarthButton.Click β set g = 9.8 When MoonButton.Click β set g = 1.62 When MarsButton.Click β set g = 3.72 When JupiterButton.Click β set g = 24.79 When CustomButton.Click β show custom TextBox
Calculate Time Period
When CalculateButton.Click: 1. Read L = number(LengthInput.Text) 2. Validate L > 0 3. T = 2 Γ Ο Γ sqrt(L / g) In App Inventor: T = 2 Γ 3.14159 Γ sqrt(L / g) 4. Set PeriodLabel.Text = "Time Period: " + round(TΓ1000)/1000 + " s"
Calculate Frequency and Angular Frequency
f = 1 / T omega = 2 Γ Ο / T (or omega = sqrt(g / L)) Set FrequencyLabel.Text = "Frequency: " + round(fΓ1000)/1000 + " Hz" Set OmegaLabel.Text = "Ο = " + round(omegaΓ1000)/1000 + " rad/s"
Calculate Max Velocity and Force
Convert amplitude from degrees to radians: A_rad = amplitude Γ Ο / 180 v_max = omega Γ L Γ sin(A_rad) (approximately omega Γ L Γ A_rad for small angles) Read mass m, then: F_max = m Γ g Γ sin(amplitude) Display both values.
Show T is independent of mass
After calculation, add a note: "Notice: The time period is " + T + " seconds regardless of mass. Even if the bob weighed 100 kg, T would still be " + T + " s!" This drives home the key insight about pendulums.
Compare All Planets
When CompareButton.Click: Calculate T for the same length on all 4 planets: T_earth = 2Οβ(L/9.8) T_moon = 2Οβ(L/1.62) T_mars = 2Οβ(L/3.72) T_jupiter = 2Οβ(L/24.79) Display as a comparison table: "Earth: T = ...s Moon: T = ...s (slowest!) Mars: T = ...s Jupiter: T = ...s (fastest!)"
Animate the pendulum on Canvas (advanced)
Use a Clock component (Timer interval = 50ms): 1. Track time t that increments each tick 2. angle = amplitude Γ cos(omega Γ t) 3. Calculate bob position: pivotX = Canvas.Width / 2, pivotY = 30 bobX = pivotX + L_scaled Γ sin(angle) bobY = pivotY + L_scaled Γ cos(angle) 4. Clear Canvas, draw line from pivot to bob, draw circle at bob This creates a real-time swinging animation!
π§ͺTesting Your App
- βL=1m on Earth β T β 2.006s (the classic 1-meter pendulum)
- βL=0.25m on Earth β T β 1.003s (seconds pendulum)
- βMoon pendulum is ~2.46Γ slower than Earth
- βDoubling L multiplies T by β2 β 1.414
- βMass should have ZERO effect on T
πBonus Challenges
Extra credit β impress your instructor
- β Create a smooth pendulum animation using Canvas and Clock
- β Add a stopwatch to let students time a real pendulum and compare
- β Plot T vs L graph for different lengths on Canvas
- β Add a 'Find g' mode: enter T and L, calculate g (for lab experiments)