#include <IRremote.h>
#include <Stepper.h>
const int IRrecvPIN = 12; // Pin for IR receiver
const int stepsPerRevolution = 200; // Number of steps per revolution for your stepper motor
// Define the motor pins (Adjust these according to your wiring)
const int motorPin1 = 8; // Connect to IN1 of your motor driver
const int motorPin2 = 9; // Connect to IN2 of your motor driver
const int motorPin3 = 10; // Connect to IN3 of your motor driver
const int motorPin4 = 11; // Connect to IN4 of your motor driver
IRrecv irrecv(IRrecvPIN);
Stepper stepper(stepsPerRevolution, motorPin1, motorPin2, motorPin3, motorPin4);
int stepSize = 1; // Number of steps to move on each command
void setup() {
irrecv.enableIRIn();
stepper.setSpeed(60); // Set the speed of the motor (RPM)
}
void loop() {
if (irrecv.decode()) {
switch (irrecv.decodedIRData.command) {
case 2: // Increment position
stepper.step(stepSize); // Move motor by stepSize
break;
case 152: // Decrement position
stepper.step(-stepSize); // Move motor backward by stepSize
break;
default:
break;
}
irrecv.resume();
}
delay(15);
}