#include <IRremote.h> // Include IRremote library
#include <Stepper.h>
const int stepsPerRevolution = 200;
int Receiver = 7; // Define the pin for IR receiver
IRrecv irrecv(Receiver); // Create IR receiver object
decode_results results;
Stepper stepper(stepsPerRevolution, 8, 9, 10, 11); // Create stepper motor object
int previous = 0;
int stepperSteps = 0;
void setup() {
stepper.setSpeed(200); // Set the speed at 200 rpm
Serial.begin(9600); // Initialize serial communication
irrecv.enableIRIn(); // Start receiving IR signals
}
void loop() {
if (irrecv.decode()) {
IRremote(); // Handle IR remote commands
irrecv.resume(); // Receive the next value
stepper.step(stepperSteps - previous); // Move stepper motor by the specified number of steps
previous = stepperSteps; // Update previous steps
}
}
void IRremote() {
int IRinput = irrecv.decodedIRData.command; // Get IR remote command
if (IRinput == 152) { // If '-' button is pressed
stepperSteps -= 1; // Decrease stepper steps
if (stepperSteps < 0) {
stepperSteps = 0; // Ensure stepper steps don't go below 0
}
}
if (IRinput == 2) { // If '+' button is pressed
stepperSteps += 1; // Increase stepper steps
if (stepperSteps > 200) {
stepperSteps = 200; // Ensure stepper steps don't exceed 200
}
}
}