Basic IR Remote and this frustrating step motor.... ( 28BYJ-48 )

Hello. :slight_smile:

I have a project that I built with a 28BYJ-48 Step Motor on it. I have a basic Xinda IR remote that I have with it. I am trying to use 12 of the keys on the remote to move the Step Motor to 12 different spots. ( basically just like the 12 spots on a clock )

My code is working with the remote but I cant seem to get the Step motor to move in different spots when I touch the remote buttons.

Is there a simple way to just digital write the step motor to each spot?
Is there a way to loop the digital write compared to how far each spot is from the step motor starting point?

Any help is greatly appreciated. THANKS

[/#include <IRremote.h>

const int a1 = 8;     // Stepper Motor IN1
const int a2 =  9;     // Stepper Motor IN2
const int b1 =  10;     // Stepper Motor IN3
const int b2 =  11;     // Stepper Motor IN4

int RECV_PIN = 12; 

  IRrecv irrecv(RECV_PIN); 
  decode_results results; 
 
void setup() 
 { 
   Serial.begin(9600); 
   irrecv.enableIRIn(); // Start the receiver 
  
  pinMode(a1, OUTPUT);
  pinMode(a2, OUTPUT);
  pinMode(b1, OUTPUT);
  pinMode(b2, OUTPUT);
  
  digitalWrite(a1, LOW);
  digitalWrite(a2, LOW); 
  digitalWrite(b1, LOW); 
  digitalWrite(b2, LOW); 
 } 
 
 
 void loop() { 
  
    if (irrecv.decode(&results)) { 
    if(results.value==0xff629d){ 
      Serial.println("UP = No Function");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25); 
    } 
    if(results.value==0xff22dd){ 
      Serial.println("LEFT = No Function");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
    if(results.value==0xffc23d){ 
      Serial.println("RIGHT = No Function");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25); 
    } 
    if(results.value==0xff02fd){ 
      Serial.println("OK = No Function");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
    if(results.value==0xFF6897){ 
      Serial.println("1 = Move to position 1");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
    if(results.value==0xFF9867){ 
      Serial.println("2 = Move to position 2");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    if(results.value==0xffB04F){ 
      Serial.println("3 = Move to position 3");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
    if(results.value==0xff30CF){ 
      Serial.println("4 = Move to position 4");
       
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
    if(results.value==0xFF18E7){ 
      Serial.println("5 = Move to position 5");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
    if(results.value==0xff7A85){ 
      Serial.println("6 = Move to position 6");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
    if(results.value==0xff10EF){ 
      Serial.println("7 = Move to position 7");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
    if(results.value==0xff38C7){ 
      Serial.println("8 = Move to position 8");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
    if(results.value==0xff5AA5){ 
      Serial.println("9 = Move to position 9");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
   if(results.value==0xff4AB5){ 
      Serial.println("0 = Move to position 10");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
    if(results.value==0xff42BD){ 
      Serial.println("* = Move to position 11");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25);
    } 
    if(results.value==0xff52AD){ 
      Serial.println("# = Move to position 12");
      
      //....MOVE STEPPER MOTOR???
      
      delay(25); 
       
    } 
     irrecv.resume(); // Receive the next value 
   } 
 } code]

Have a look at the AccelStepper library. It can keep track of the position of the motor.

You will need some code (probably in setup() ) to move the motor to the ZERO position when you start your Arduino.

...R

Hi,

As Robin2 has said, you need to setup an initial position for the stepper, its doesn't know where it is, it only steps on command.

You will need a sensor or switch that the stepper can be moved to, to establish a reference point.

Tom...... :slight_smile:

Installing a reference point is my second step... But first I need to move the step motor to that reference point to start at zero. Then I will be able to move my step motor to all 12 positions. The reference point will be zero for button 1, 30 degrees for button 2, 60 degrees for button 3, 90 degrees for button 4 and so on.... 120 for 5, 150 for 6, 180 for 7, 210 for 8, 240 for 9, 270 for 10, 300 for 11 and 330 for button 12. I am moving a servo in a circle that manually pushes 12 buttons. The servo is easy to code but I need to get the step motor to all twelve spots first. Mistakenly I built my project(time consuming LOL) without learning to code this particular step motor.

Is there a way to code a step motor like you code a servo?

Let me know if anyone knows some code to direct my step motor.

Thanks for any help.

thefourguy4444:
Is there a way to code a step motor like you code a servo?

I suspect you have not studied the link I gave you to the AccelStepper library.

Installing a reference point is my second step... But first I need to move the step motor to that reference point to start at zero

I think you you have the logic of this back to front. How can you move to a reference point before you install it? Unlike a servo, a stepper motor has no natural ZERO position.

...R