Arduino ;photo interrupter;stepper motor

hi everyone; I am using a photo interrupter to count the number of paper that pass throught my photo interupter then turn a stepper motor

I have the photo interrupter working good and successfully connected to my arduino.

The following code lights an LED anytime something blocks the interrupter


int ledPin = 13; // LED connected to digital pin 13 int photoPin = 2; // int val = 0; unsigned int count = 0;

void setup() // run once, when the sketch starts { pinMode(ledPin, OUTPUT); // sets the digital pin as output pinMode(photoPin, INPUT); }

void loop() // run over and over again { val = digitalRead(photoPin); if (val==LOW) { digitalWrite(ledPin, LOW); } else { digitalWrite(ledPin, HIGH); count ++; } }


Any recommendations on how to make the loop to count for 5 paper passed then turn the stepper motor

It should be obvious that I am new to the arduino. Great community.

Thanks!!

Maybe something like

if (count % 5 == 0) {
   // move stepper
}

OR if you never need count to go above 4 (0-4 = 5 pages)

if (count == 4) {
    count = 0;
    //  move stepper
}

This Simple Stepper Program may be helpful. And maybe also Stepper Motor Basics

...R

I have the photo interrupter working good and successfully connected to my arduino.

That's hardly "working good". You need to determine when the interrupter BECOMES blocked, and when it BECOMES unblocked. Look at the state change detection example.

Increment the counter when the interrupter changes state. I would count when it became unblocked, indicating that the paper had left.

When the count gets to 5, step some number of times and reset the counter to 0.