Lego Walker controlled by a TV remote controller
This is a Lego robot with a geared Stepper Motor 28BYJ-48 5V with
ULN2003 driver board which is controlled by a television remote control.
/*
Stepper Motor controlled by arduino and tv remote controller
This sketch controls a geared stepper motor wirelessly using tv remote control
The motor will revolve one revolution forward when left arrow is pressed.
The motor will revolve one revolution backward when right arrow is pressed.
The motor is attached to digital pins 8 - 11.
An indicator red led is attached to pin 13.
An indicator blue led is attached to pin 7.
An infrared receiver (IR) is attached on pin 6.
*/
#include <IRremote.h>
#include <Stepper.h>
int Pin0 = 8;
int Pin1 = 9;
int Pin2 = 10;
int Pin3 = 11;
int IR_PIN = 6;
int redLed = 13;
int bluLed = 7;
int i=0;
int m=4;
const long ledON = 0x4EB338C7; //see code extractor below
const long ledOFF = 0x4EB312ED; //see code extractor below
IRrecv irrecv(IR_PIN);
decode_results results;
void setup()
{
//Serial.begin(9600);
irrecv.enableIRIn(); // turn on the receiver
pinMode(redLed, OUTPUT);
pinMode(bluLed, OUTPUT);
pinMode(IR_PIN, INPUT);
pinMode(Pin0,OUTPUT);
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
}
void loop() {
if (irrecv.decode(&results))
{
irrecv.resume();
long int decCode = results.value;
Serial.println(decCode);
if (results.value == ledON)
{
digitalWrite(bluLed,HIGH);
digitalWrite(redLed,LOW);
for(i=0;i<512;i++)
{
forward();
}
}
if (results.value == ledOFF)
{
digitalWrite(redLed,HIGH);
digitalWrite(bluLed,LOW);
for(i=0;i<512;i++)
{
backward();
}
}
}
}
void forward()
{
step1();
step2();
step3();
step4();
step5();
step6();
step7();
step8();
}
void backward()
{
step8();
step7();
step6();
step5();
step4();
step3();
step2();
step1();
}
void step1()
{
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(m);
}
void step2()
{
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(m);
}
void step3()
{
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(m);
}
void step4()
{
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(m);
}
void step5()
{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(m);
}
void step6()
{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
v
}
void step7()
{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(m);
}
void step8()
{
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(m);
}
Sketch to extract the codes in your TV remote controller:
/* TV Remote Code Extractor */
Stepper Motor controlled by arduino and tv remote controller
This sketch controls a geared stepper motor wirelessly using tv remote control
The motor will revolve one revolution forward when left arrow is pressed.
The motor will revolve one revolution backward when right arrow is pressed.
The motor is attached to digital pins 8 - 11.
An indicator red led is attached to pin 13.
An indicator blue led is attached to pin 7.
An infrared receiver (IR) is attached on pin 6.
*/
#include <IRremote.h>
#include <Stepper.h>
int Pin0 = 8;
int Pin1 = 9;
int Pin2 = 10;
int Pin3 = 11;
int IR_PIN = 6;
int redLed = 13;
int bluLed = 7;
int i=0;
int m=4;
const long ledON = 0x4EB338C7; //see code extractor below
const long ledOFF = 0x4EB312ED; //see code extractor below
IRrecv irrecv(IR_PIN);
decode_results results;
void setup()
{
//Serial.begin(9600);
irrecv.enableIRIn(); // turn on the receiver
pinMode(redLed, OUTPUT);
pinMode(bluLed, OUTPUT);
pinMode(IR_PIN, INPUT);
pinMode(Pin0,OUTPUT);
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
}
void loop() {
if (irrecv.decode(&results))
{
irrecv.resume();
long int decCode = results.value;
Serial.println(decCode);
if (results.value == ledON)
{
digitalWrite(bluLed,HIGH);
digitalWrite(redLed,LOW);
for(i=0;i<512;i++)
{
forward();
}
}
if (results.value == ledOFF)
{
digitalWrite(redLed,HIGH);
digitalWrite(bluLed,LOW);
for(i=0;i<512;i++)
{
backward();
}
}
}
}
void forward()
{
step1();
step2();
step3();
step4();
step5();
step6();
step7();
step8();
}
void backward()
{
step8();
step7();
step6();
step5();
step4();
step3();
step2();
step1();
}
void step1()
{
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(m);
}
void step2()
{
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(m);
}
void step3()
{
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(m);
}
void step4()
{
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(m);
}
void step5()
{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(m);
}
void step6()
{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
v
}
void step7()
{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(m);
}
void step8()
{
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(m);
}
Sketch to extract the codes in your TV remote controller:
/* TV Remote Code Extractor */
#include <IRremote.h> int RECV_PIN = 12; IRrecv irrecv(RECV_PIN); decode_results results; void setup() { Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver } void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, HEX); irrecv.resume(); // Receive the next value } }
Comments
Post a Comment