STEMpedia
Published © CC BY

Measuring Time Period of a Pendulum Using IR Sensor

This project teaches you how to calculate the time period of a simple pendulum using an IR sensor and evive.

IntermediateFull instructions provided2 hours999
Measuring Time Period of a Pendulum Using IR Sensor

Things used in this project

Hardware components

evive
STEMpedia evive
×1
evive Starter Kit
STEMpedia evive Starter Kit
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing Diagram for Simple Pendulum

Code

Arduino Code to calculate Time Period of Pendulum

Arduino
#include<evive.h>
// These pins will also work for the 1.8" TFT shield

unsigned long pretime;
unsigned long currtime;
int pin = 2;
unsigned long timePeriod;
boolean flag = true;

void setup(){
  Serial.begin(9600);
  pinMode(pin, INPUT);
  pretime = micros();
  tft.init(INITR_GREENTAB);              // initialize a ST7735S chip, black tab
  tft.setRotation(1);
  Serial.println("Initialized");
  tft.fillScreen(ST7735_BLACK);
    tft.drawRoundRect(20, 30, 120, 68, 10, ST7735_WHITE);
  tft.setTextColor(ST7735_WHITE);
  tft.setTextSize(1);
  tft.setCursor(48,40);
  tft.println("TIME PERIOD");
}
void loop(){
  if (digitalRead(pin) == 0)
  {
    if (flag == true)
    {
    currtime = micros();
    timePeriod = currtime-pretime;
    pretime = currtime;
    flag = !flag;
    tft.setCursor(47,65);
    tft.drawRoundRect(20, 30, 120, 68, 10, ST7735_WHITE);
      tft.setTextColor(ST7735_GREEN,ST7735_BLACK);
      tft.setTextSize(2);
      tft.print(timePeriod/1000);
      tft.print(" ms");
      tft.print(" ");
      Serial.println(timePeriod/1000);
      delay(100);
    }
    else{
      flag = !flag;
      delay(100);
    }
  }
}

evive Library

C/C++
No preview (download only).

Credits

STEMpedia

STEMpedia

42 projects • 169 followers
STEMpedia blends theory with experiential learning by offering state-of-the-art technology, projects, tutorials, courses, and much more.

Comments