using a photo interrupt sensor as a gate limiter

I am rebuilding a mighty mule gate opener, the electronics burned out. I am new at this arduino thing and I am having a hard time with the photo interrupt sensor. ( it is a Keyestudio and it work fine). I am trying to write a learn loop and can't us two limit switches in the opener because of space requirements. The unit had a photo sensor on it and I want to use that to count the number of times the opening in the wheel comes around to turn off the motor when it is completely open or closed. I think I figured the major portion of it out. It is the counting of the slots in the wheel where I am having trouble. there are all kinds of examples of RPM sketches. Nothing I can find that just has a simple counter that stores the value in another value and resets the sensor to zero.

This is what I cam up with but it does not seem right. What I you to look at is the first "if" statement. does it record the number of times the sensor is switched ?

Code:

void openGateLearn () { digitalWrite(openGate, HIGH); //turn on gate using H-bridge digitalWrite(pwm, 245); // send power level to motor

if(digitalRead(photoSensor == LOW) { sensorValue++; Serial.println("sensorValue"); //prints for debugging Serial.println(sensorValue); //prints for debugging } if (openLimit == LOW) { //looks for open limit button to be pressed digitalWrite(openGate, LOW); //stops gate from opening digitalWrite(pwm, 0); //shuts off power to the motor openSensorValue = sensorValue; //sends sensorValue to openSensorValue to be read later sensorValue = 0; // resets sensorValue to zero } }

if(digitalRead(photoSensor == LOW)This will be true when the input [u]is[/u] LOW so you could get several increments whilst it is LOW. Instead, you probably want to count how many times the input [u]becomes[/u] LOW as in the StateChangeDetection example in the IDE

Thanks, UKHeliBob looks like that will help me get started. I 'll post more when I get some time to rewrite