Need help writing code for Uno to use a remote, micro switch and stepper motor.

I am attempting to automate lifting a painting 52" wide x 33.5" tall that is hinged at the top. I am open to suggestions as to the best way to accomplish this task. I saw a YouTube video on stepper motors controlled be Arduino and here I am.

I am trying to have an Arduino Uno control a Nema 17 stepper motor using a micro switch to home the motor and a remote control (NEC) to move the motor 90 degrees from home with CH+ and back to home with CH-

I know nothing about programming. I pieced together the code listed below and cannot find information to help troubleshoot. I would greatly appreciate help fixing the current code or an entirely different code if needed.

The code uploads without error. The motor will home and "Stepper is homing" will print on the serial monitor and then nothing else will happen.

Connections are as follows:
Nema 17 black and green wires to "A" and red and blue to "B" on EasyDr1ver HW-135.

Both EasyDr1ver grounds to Uno. EasyDr1ver power to 5v on Uno. EasyDr1ver Step to
digital pin 2, Dir to digital pin 3.

Micro switch C to ground and NO to Uno digital pin 9.

IR receiver VCC to Uno 5v, ground to ground and IN to Uno digital pin 4.


#include "AccelStepper.h"
// Library created by Mike McCauley at AccelStepper: AccelStepper library for Arduino

// AccelStepper Setup
AccelStepper stepperX(1, 2, 3); // 1 = Easy Driver interface
// NANO Pin 2 connected to STEP pin of Easy Driver
// NANO Pin 3 connected to DIR pin of Easy Driver

// Define the Pins used
#define home_switch 9 // Pin 9 connected to Home Switch (MicroSwitch)

// Stepper Travel Variables
long Travelx; // Used to store the X value entered in the Serial Monitor
int move_finished=1; // Used to check if move is completed
long initial_homing=-1; // Used to Home Stepper at startup

int receiver = 4; //Signal Pin of IR receiver to Arduino Digital Pin 4

IRrecv irrecv(receiver); // create instance of 'irrecv'

decode_results results; // create instance of 'decode_results'

void setup() {
Serial.begin(9600); // Start the Serial monitor with speed of 9600 Bauds

pinMode(home_switch, INPUT_PULLUP);

delay(5); // Wait for EasyDriver wake up

// Set Max Speed and Acceleration of each Steppers at startup for homing
stepperX.setMaxSpeed(100.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperX.setAcceleration(100.0); // Set Acceleration of Stepper

// Start Homing procedure of Stepper Motor at startup

Serial.print("Stepper is Homing . . . . . . . . . . . ");

while (digitalRead(home_switch)); { // Make the Stepper move CCW until the switch is activated
stepperX.moveTo(initial_homing); // Set the position to move to
initial_homing--; // Decrease by 1 for next move if needed; // Start moving the stepper

stepperX.setCurrentPosition(0); // Set the current position as zero for now
stepperX.setMaxSpeed(100.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepperX.setAcceleration(100.0); // Set Acceleration of Stepper

while (!digitalRead(home_switch)); { // Make the Stepper move CW until the switch is deactivated

irrecv.enableIRIn(); // Start the receiver


void loop(){
if (irrecv.decode(&results)); //IR signal received?
case 0xEE886D7F: //CH+ Pressed

stepperX.setSpeed(1000); //Set stepper speed




case 0xE318261B: //CH- Pressed

stepperX.setSpeed(1000); //Set stepper speed





irrecv.resume();// Receive next value



There is advice at the top of the topic headline telling how to post questions. Among others You are adviced to use cod tags, </>, for the code. Then more helpers can read it.

Hi Dinusa,
Welcome to the forum. To get the help you want, I'd suggest linking the parts you're using as well as a schematic or some other form of a wiring diagram to make it easier for people to understand your problem. As RailRoader already mentioned, you should also use code tags. A picture of your setup will also help answer such questions as "Is the stepper motor connected to anything?" among other important questions.
Good luck,
John Wolf
Progetto Company