2 Replies - 443 Views - Last Post: 19 May 2019 - 09:38 PM Rate Topic: -----

#1 Roneet   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-May 19

Calculating the Period of a Pendulum

Posted 19 May 2019 - 01:54 PM

Hi! I am very new to C++ but thought it would be cool to use a SparkFun kit and a Photogate that my school had laying around. I ended up attempting to calculate the period of a pendulum I created using the Photogate.
I connected a Digital Protoboard to the Redboard then the Photogate. I used this code below I found from the Vernier Photogate Tutorial Page to use in the Arduino IDE. Though this code works it only outputs the time of time when the photogate was blocked.

So in essence I need to track the time it takes the pendulum to first block the photogate, then block again moving to the left, and finally just blocking the gate one last time as it comes back to center.
So I believe I need a section of code that captures the first time stamp, a section of code that waits until a second blocked event happens, then captures the second time stamp and finally collects the difference? I can't seem to wrap my head around this and I can't even begin to understand how to code it. I was hoping maybe this forum could provide some insight on this personal project.
This is not a homework assignment but something I'm doing during my off periods in School.


/* VernierTutorialPhotogate (v2018)
* This sketch will send a status message to the Serial
* Monitor on whether the Photogate is blocked or unblocked.
* It lists the time that the photogate is blocked in microseconds since the program started running or
* since the last time the counter overflowed.
* It will also turn on the LED (pin D13) when the
* photogate is blocked.
*
* Plug the Photogate into the Digital 1 port on the
* Vernier Arduino Interface Shield or into a Digital Protoboard
* Adapter wired to Arduino pins 2, 3, 4, and 5.
*/
int photogatePin =2;//create global variable for pin assignment to sensor
intLEDpin=13;//create global variable for pin assignment to LED
int photogateStatus;//create global variable for photogate status: LOW=blocked, HIGH=unblocked
int oldStatus = HIGH;
unsignedlong timeus =0;//Time in us
void setup()
{
Serial.begin(9600);// set up Serial library at 9600 bps
   pinMode(LEDpin, OUTPUT);
Serial.println("Vernier Format 2");
Serial.println("Photogate blocked times taken using Ardunio");
Serial.print("Time");
Serial.print("us");
};// end of setup
void loop ()
{
 photogateStatus = digitalRead(photogatePin);//low when blocked
if(photogateStatus == LOW)
{
   digitalWrite(LEDpin, HIGH);// turn on LED
if(oldStatus == HIGH)
{
         timeus = micros();
Serial.println(timeus);
}
}
else digitalWrite(LEDpin, LOW);// turn off LED
  oldStatus = photogateStatus;
};// end of loop



Is This A Good Question/Topic? 0
  • +

Replies To: Calculating the Period of a Pendulum

#2 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7105
  • View blog
  • Posts: 24,123
  • Joined: 05-May 12

Re: Calculating the Period of a Pendulum

Posted 19 May 2019 - 05:29 PM

Perhaps I'm missing something, but my reading of this documentation is that the device has built in pendulum timing:

Quote

Pendulum Timing
Posted Image
Pendulum Timing mode uses a photogate connected to an interface. The timing begins when the photogate is first interrupted. The timing continues until the photogate is interrupted twice more, so that you get the time for a complete swing of a pendulum or other oscillating object.

Was This Post Helpful? 0
  • +
  • -

#3 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2389
  • View blog
  • Posts: 4,523
  • Joined: 30-May 10

Re: Calculating the Period of a Pendulum

Posted 19 May 2019 - 09:38 PM

Also here -> https://cboard.cprog...d-pendulum.html
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1