Projects / Pendulum period with a photogate

Pendulum period with a photogate

Beginner2.5 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. UNO

    Build the pendulum

    A light string, a small heavy bob and a fixed pivot.

  2. UNO

    Add a tape mark

    A small strip of white tape on the bob facing the sensor.

  3. UNO

    Mount the sensor

    At the bottom of the swing, 1 to 2 centimetres from the tape.

  4. UNO

    Wire the sensor and display

    DO to D2, I2C on A4 and A5.

  5. UNO

    Measure the length

    Pivot to bob centre, then edit LENGTH_M.

  6. UNO

    Upload and swing gently

    The display says swing the pendulum.

  7. UNO

    Wait for 20 passes

    Period and g appear.

  8. UNO

    Change the length

    Repeat and compare T squared with L.

In short

How do you build a pendulum period with a photogate?

An infrared sensor measures the period of a swinging pendulum and compares it with theory. You need Arduino Uno R3, TCRT5000 IR reflective sensor module, SSD1306 OLED Display and Breadboard 830 Tie Points. It takes 8 steps and about 150 minutes.

Level
Beginner
Time
About 150 min
Parts
4

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Sensor VCCUno 5VPower
Sensor GNDUno GNDGround
Sensor DOUno D2Digital output, interrupt pin
OLED SDAUno A4I2C data
OLED SCLUno A5I2C clock
OLED VCC and GNDUno 5V and GNDPower

Code

A simple pendulum swings with a period T = 2 pi times the square root of L over g, for small angles, so measuring T lets you work out g, the acceleration of gravity, which should come out near 9.8 metres per second squared. The reflective sensor sits at the lowest point of the swing and a small piece of white tape on the bob passes in front of it twice in each full period, once in each direction. An interrupt records the time of each pass, ignoring anything closer than a tenth of a second. Timing about ten full swings and dividing, rather than timing one swing, spreads the small timing errors over many swings. Keep the swing angle under about ten degrees, use a light string and a heavy small bob, and measure the length from the pivot to the centre of the bob. Try several lengths and plot T squared against L, which should be a straight line. Check on the module whether its output goes low when it sees the tape, and change FALLING to RISING if it is the other way round.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 oled(128, 64, &Wire, -1);

const int SENSOR = 2;                 // DO output of the reflective sensor module
const float LENGTH_M = 0.50;          // measure from the pivot to the centre of the bob
const int PASSES_FOR_TEN = 20;        // each full swing passes the bottom twice
const unsigned long MIN_GAP_US = 100000UL; // ignore edges closer than 0.1 s

volatile unsigned long lastEdge = 0;
volatile unsigned long stamps[PASSES_FOR_TEN + 1];
volatile int passes = 0;
volatile bool done = false;

void onPass() {
  unsigned long t = micros();
  if (t - lastEdge < MIN_GAP_US) return;     // debounce
  lastEdge = t;
  if (done) return;
  stamps[passes] = t;
  passes++;
  if (passes > PASSES_FOR_TEN) done = true;
}

void show(const char* l1, float v1, const char* l2, float v2) {
  oled.clearDisplay();
  oled.setCursor(0, 0);  oled.print("Length "); oled.print(LENGTH_M, 2); oled.println(" m");
  oled.setCursor(0, 16); oled.print(l1); oled.println(v1, 3);
  oled.setCursor(0, 32); oled.print(l2); oled.println(v2, 2);
  oled.display();
}

void setup() {
  pinMode(SENSOR, INPUT);
  attachInterrupt(digitalPinToInterrupt(SENSOR), onPass, FALLING);
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  oled.setTextSize(1);
  oled.setTextColor(SSD1306_WHITE);
  oled.clearDisplay();
  oled.setCursor(0, 0);
  oled.println("Swing the pendulum");
  oled.display();
}

void loop() {
  if (done) {
    noInterrupts();
    unsigned long first = stamps[1];                    // skip the very first pass
    unsigned long last  = stamps[PASSES_FOR_TEN];
    interrupts();
    float tenSwings = (last - first) / 1e6;             // seconds for 9.5 swings
    float period = tenSwings / ((PASSES_FOR_TEN - 1) / 2.0);
    float g = 4.0 * PI * PI * LENGTH_M / (period * period);
    show("Period s ", period, "g m/s2  ", g);
    delay(8000);
    noInterrupts(); passes = 0; done = false; interrupts();
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Length 0.25 mPeriod about 1.0 s
Length 1.00 mPeriod about 2.0 s
Computed gClose to 9.8 within a few percent
Large swing angleSlightly longer period
Short stringFast swings, check the 0.1 s gap

If it does not work

No count

Check the sensor distance, and flip FALLING and RISING.

Period doubles

The sensor only sees one direction, set PASSES_FOR_TEN accordingly.

g far from 9.8

Re-measure LENGTH_M to the bob centre.

Extra counts

Ambient light or a moving hand, shield the sensor.

Display blank

Check I2C address 0x3C and the wiring.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the pendulum period with a photogate?

Arduino Uno R3, TCRT5000 IR reflective sensor module, SSD1306 OLED Display and Breadboard 830 Tie Points.

How long does the pendulum period with a photogate take to build?

About 150 minutes for a beginner maker, in 8 steps.

How do I know the pendulum period with a photogate works?

Length 0.25 m: Period about 1.0 s. Length 1.00 m: Period about 2.0 s. Computed g: Close to 9.8 within a few percent.

No count: what should I check?

Check the sensor distance, and flip FALLING and RISING.

Period doubles: what should I check?

The sensor only sees one direction, set PASSES_FOR_TEN accordingly.

g far from 9.8: what should I check?

Re-measure LENGTH_M to the bob centre.

Extra counts: what should I check?

Ambient light or a moving hand, shield the sensor.