Photogate for Fidget spinner

Hello

I’m working on a science fair type project an I built a Photogate to measure the rotations per second, and period in Hz. Arduino coding is not my skill set, but I didn’t try to run the arduino in Matlab but I run into the same coding problem… (I have a basic understanding but I still don’t know all the ropes), and I read online that matlab doesn’t take data points fast enough…? i don’t really know…

I have a 4 weight fidget spinner spinning on a rod with a photogate measuring the space between the center and weight ( so that the photogate is on when the spinner is between the weight connections and off when the spinner connection blocks the light, the distance or time on and off is close to equal).

I have my code working, as far as the photogate turning on and off, but I don’t know how to code the calculations to convert the high points or low points to a measurable rotation, or some type of graph to represent the rotations per second in a live plot.

one rotation will consist of 4 high or low values…

here’s what I have…

int led= 13;
int counter;
void setup() {
// put your setup code here, to run once:

pinMode(led,OUTPUT);
Serial.begin(19200);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(led, HIGH);
int sensorValue= analogRead(A0);
Serial.println(sensorValue);

}

open to any suggestions… thanks

You are reading the "photogate", and getting a value. Surely, you see that the values increase and decrease, with relatively sharp slopes. It is easy to determine when the value exceeds some threshold (the photogate is not blocked by a weight) or is below some other threshold (the photogate is blocked).

Count the transitions, to get the number of times that a weight has interfered. Divide by 4 to get the number of rotations.

To determine the speed, divide by time.

What time? Well, you need to define that. See the blink without delay example to make something happen periodically (calculate RPM) without using delay.

ok so how do I define a time stamp to a data point? or where could I go to see or learn more about that?

and how do i count the transitions? I was thinking of some type of find the last 4 Max(voltage values) and divide that by the change in time.. I'll search for the blink without delay example...

ok so how do I define a time stamp to a data point?

You don't need to.

Suppose that you wanted to count the number of cars that drove by your house in one hour. Would you need to record when each drove by? I don't think so. All you need to know is when the measuring interval starts and ends. It can start at any time, as shown in the blink without delay example, and end at any time. But, if you know when the interval starts, and how long the interval is to be, you can easily reset the start time, and calculate RPM.