// This one has the easiest logic of all #include #define HALFSTEP 8 #define rightButton 8 //the adjust pin // Change the pin defination if you want to #define motorPin1 9 // IN1 on the ULN2003 driver 1 #define motorPin2 10 // IN2 on the ULN2003 driver 1 #define motorPin3 11 // IN3 on the ULN2003 driver 1 #define motorPin4 12 // IN4 on the ULN2003 driver 1 // Initialize construtor with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48 AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4); void setup() { Serial.begin(4800); //Remember from the Serial communication tutorial stepper1.setMaxSpeed(1000); stepper1.setAcceleration(1000); stepper1.setSpeed(1000); stepper1.moveTo(4096); // 4096*10 steps for 10 rotations in 28BYJ-48 – 5V Stepper Motor //I hope you all to adjut the direction again within 10 rotations.....if no plzz feel free to disconect and connect again the microcontroller }//--(end setup )--- void loop() { while(Serial.available() == 0); //Loops in this line until the funtion gets any data from the Serial buffer char data = Serial.read(); if(data == 'g') // 'g' means GO ......to switch on the Stepper after data is recieved from Atmega 3 to Atmega 2 trigger_go_go_go(); if(data == 's') // 's' will be sent which signifies STOP .......this lets you syncronize the stepper { stepper1.stop(); // First stop the motor plzz adjust(); // lets you syncronize the stepper } } void trigger_go_go_go() // Check out adjust() first, then you can easily understand { stepper1.move(4096); while(Serial.available()==0) { if(stepper1.distanceToGo() == 0) trigger_go_go_go(); // recursion to call itself until something is caught in the Serial Monitor go_go_go(); // Runs the stepper step by step } loop(); // loop() is called when some thing is sent through Serial communication } void go_go_go() // just required to move the stepper { stepper1.run(); // Moves 1 step per call } void adjust() // Executes if and only iff there is no Serial data coming in { stepper1.move(4096); while(Serial.available() == 0) { if(stepper1.distanceToGo() == 0) // when the stepper reaches step 4096 calls adjust() [recursion] adjust(); if(digitalRead(rightButton) == HIGH) //when the right switch is pressed the stepper moves when unpressed stops automatically go_go_go(); } loop(); // this actually means a if statement.....i.e. if(Serial.available!=0) } /////////// thats it for the 1st Atmega /////////////