#include <IRremote.h>
IRrecv irrecv(2); // Define IR receiver pin
bool isCW = false;
const int stepPin = 3;
const int dirPin = 4;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Enable IR receiver
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
if (irrecv.decode()) {
switch (irrecv.decodedIRData.command) {
case 48: // Code for button 1
if(isCW == false)
{
Serial.println("Moving clockwise");
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 400; x++)
{
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delay(5);
}
isCW = true;
}
else
{
Serial.println("Already Open");
}
break;
case 24: // Code for button 2
if(isCW == true)
{
Serial.println("Moving counterclockwise");
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 400; x++)
{
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delay(5);
}
isCW = false;
}
else
{
Serial.println("Already Close");
}
break;
default:
break;
}
irrecv.resume(); // Enable next IR signal detection
}
}