Program is made using tsop sensor.problem is ,it receives one value for the switch and enters in that loop.but it does not come out of that loop untill that loop is complited.so we need is,if we give another input it should interrupt the working loop and enter in the loop of which button is pressed.
include.pdf (74.6 KB)
Posting your program as an attached PDF is highly unlikely to get help.
#include <Stepper.h>
#include <IRremote.h>//ir library ...you must import it... Go to Sketch->Include Library->Add .ZIP Library
int RECV_PIN = 12;//pin to which connect TSOP output pin
IRrecv irrecv(RECV_PIN);
decode_results results;
int statusled = 13;
// change this to fit the number of steps per revolution
// for your motor
const int stepsPerRevolution = 300; // change this to fit the number of steps per revolution
const int stepsPerRevolution1 = 400; // change this to fit the number of steps per revolution
const int stepsPerRevolution2 = 200; // change this to fit the number of steps per revolution
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
// set the speed at 50 rpm:
myStepper.setSpeed(50);
// initialize the serial port:
irrecv.enableIRIn();
pinMode(statusled,OUTPUT);
digitalWrite(statusled,LOW);
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
if (irrecv.decode(&results))
{
digitalWrite(statusled,HIGH);
Serial.println(results.value, HEX);//This will show HEX code from Remote in Serial Monitor
delay(100);
irrecv.resume();
if (results.value == 0x1FEC03F) // type your remote FORWARD robot control button hex value.
{
for(;;)
{
Serial.println("clockwise");
myStepper.step(stepsPerRevolution1);
delay(3000);
}
}
else if (results.value == 0x1FE40BF) // type your remote FORWARD robot control button hex value.
{
for(;;)
{
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution2);
delay(4000);
}
}
}}