#include <Stepper.h>
#include <IRremote.h>
#define receiver 8
#define A 9
#define B 10
#define C 11
#define D 12
Stepper stepper(200, A, C, B, D); // Initialize stepper motor with 200 steps per revolution
void setup() {
Serial.begin(9600);
stepper.setSpeed(60); // Set the speed of the motor
IrReceiver.begin(receiver);
}
void loop() {
if (IrReceiver.decode()) {
int command = IrReceiver.decodedIRData.command;
Serial.println(command); // Print the received command for debugging
if (command == 9) { // Move forward when command is 9
for (int i = 0; i < 300; i++) {
stepper.step(1);
delay(10);
}
}
else if (command == 7) { // Move backward when command is 7
for (int i = 0; i < 300; i++) {
stepper.step(-1);
delay(10);
}
}
IrReceiver.resume(); // Prepare for the next IR signal
}
}