Team 6

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 Masterclass
"

A 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

fxTime Period: T = 2Ο€βˆš(L/g)
fxFrequency: f = 1/T
fxAngular Frequency: Ο‰ = 2Ο€/T = √(g/L)
fxMax Velocity: v_max = Ο‰ Γ— Amplitude
fxRestoring Force: F = -mg sin(ΞΈ)

🎨Part A β€” Designer View (UI Design)

Open MIT App Inventor β†’ Switch to Designer view. Follow each step below to build the interface.

1

Set up the screen

Title: "Pendulum Simulator" Dark background with physics theme.

2

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)

3

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.

4

Add Calculate button

Big "Calculate" button + "Compare All Planets" button.

5

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"

6

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.

1

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

2

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"

3

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"

4

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.

5

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.

6

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!)"

7

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)