stepper motor ,arduino, optical encoder

hi every one
am now building a little project based on arduino uno ,stepper motor , and encoder
and i need a programm
so when somthing pass througt the optical encoder for 5 time or high the stepper make 1 or 2 steps
please help me i need this code and thanks you

This section of the forum is intended for you to get help with your code. Have you written any ?

no i have not writ any code , i dont have any ideas about it :confused:

in generale the code that i want it is to count for 5 time via the ir encoder in order to turn the stepper fot 1 or 2 steps

const int encoderIn = 8; // input pin for the interrupter
const int statusLED = 13; // Output pin for Status indicator
const int pulseOutput = 12; // Pulse output pin for external interfacing
int detectState=0; // Variable for reading the encoder status
void setup()
{
pinMode(encoderIn, INPUT); //Set pin 8 as input
pinMode(statusLED, OUTPUT); //Set pin 13 as output
pinMode(pulseOutput, OUTPUT); // Set Pin 12 as output
}
void loop() {
detectState=digitalRead(encoderIn);
if (detectState == HIGH) { //If encoder output is high
digitalWrite(statusLED, HIGH); //Turn on the status LED
digitalWrite(pulseOutput,HIGH); // Give a logic-High level output
}
else {
digitalWrite(statusLED, LOW); //Turn off the status LED
digitalWrite(pulseOutput,LOW); // Give a logic-Low level output
}
}

i have wrote this one but i dont know how to integrate my stepper motor in this code

Have you written any code to move the stepper ?

no , i don’t

What sort of stepper driver are you using?
If it takes step and direction signals this Simple Stepper Program may get you started.

Also have a look at Planning and Implementing a Program.

…R
Stepper Motor Basics

am using esy driver and simple smaal stepper motor

void loop() {
detectState=digitalRead(encoderIn);
if (detectState == HIGH) { //If encoder output is high
digitalWrite(statusLED, HIGH); //Turn on the status LED
digitalWrite(pulseOutput,HIGH); // Give a logic-High level output
}
else {
digitalWrite(statusLED, LOW); //Turn off the status LED
digitalWrite(pulseOutput,LOW); // Give a logic-Low level output
}
}

What crappy formatting. That aside, you probably want to pay attention to when the encoder output BECOMES high, not IS high. See the state change detection example.

And use Tools + Auto Format to fix that mess.

any help

wizkhalifa:
any help

Have you tried any of the 3 "helps" in Reply #7 ?
With what result ?

...R

i have not understand anything from thar reply .am not an exper in arduino program .am just beigner in this file .for that i need help
all i know that i want a little program
i have an photo interupter so when somthing pass in the the photo interupter for 5 time the stepper do 1step or 2
this is it
but i have no ideas about this , and i cant do any thing

First, learn to write meaningful comments. The ones you have
are just redundant statements of the code you have.
They are just a waste of time.
Comments should be about what you are intending to do and
why you are doing it.
For your program:
You need to detect when the input just
changes from 1 to 0 or from 0 to 1.

You'll need a variable to keep track of which way it was changing
since the last loop. The loop needs a change history variable.

Each time it makes a transition
you need to increment a counter.

When the counter reaches 5 step the stepper motor and rest the counter.

Now, just make code to do the things I've just made you.
These could even be your useful comments in the code.
Dwight

You also should read the two posts by Nick Gammon that appear at the top of this Forum. After almost 30 posts, you should at least be following the rules suggested there, including using code tags when posting source code.

wizkhalifa:
i have not understand anything from thar reply .am not an exper in arduino program .am just beigner in this file .for that i need help

Take one item from that reply - perhaps the Simple Stepper Program and read through it carefully a number of times. Then tell us exactly what parts you don't understand and I will try to explain.

When you only say "i have not understand anything" I don't know how to help.

Have you tried many of the example programs that come with the Arduino IDE?

...R