Week 7 Xu- IR remote control a Stepper Motor

 

I want to control the stepper motor by using the remote control.
Use IR sensor to control the motor run or stop.

Core components

IR sensor
remote control
Stepper Motor
Stepper Motor driver board
Wires & jumpwires
Arduino board
Breadboard power supply

Circuit

How it works

Press UP: do a full rotation one way
Press DOWN: stop

Code :

#include <boarddefs.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
#include <IRremoteInt.h>

#include <Stepper.h>

#define STEPS 32
int Steps2Take;
int receiver=6;

Stepper small_stepper(STEPS, 8,9,10,11);
IRrecv irrecv(receiver);
decode_results results;

void setup() {
// put your setup code here, to run once:
irrecv.enableIRIn();
}

void loop() {
// put your main code here, to run repeatedly:
if(irrecv.decode(&results))
{
switch(results.value)
{
case 0xFF629D:
small_stepper.setSpeed(500);
Steps2Take = 2048;
small_stepper.step(Steps2Take);
delay(2000);
break;
// case 0xFFA857:
// small_stepper.setSpeed(500);
// Steps2Take = -2048;
// small_stepper.step(Steps2Take);
// break;
}
irrecv.resume();

}}

Leave a Reply

Your email address will not be published. Required fields are marked *