Lego Walker controlled by android app via Bluetooth
This is a Lego robot with a geared Stepper Motor 28BYJ-48 5V with ULN2003 driver board which is controlled by a Bluetooth using an android app that the author has developed.
/*
Stepper Motor controlled by android app via bluetooth
This sketch controls a geared stepper motor wirelessly using a phone
The motor will revolve one revolution forward when green button is pressed.
The motor will revolve one revolution backward when red button is pressed.
The motor is attached to digital pins 8 - 11.
An indicator red led is attached to pin 13.
*/
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2,3);
int i=0;
int m=4
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(13, OUTPUT);
}
void loop(){
if (BTserial.available())
data=BTserial.read();
{
if(data == 1)
{
digitalWrite(13, HIGH);
for(i=0;i<512;i++)
{
forward();
}
}
if(data == 0)
{
digitalWrite(13, 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);
}
Stepper Motor controlled by android app via bluetooth
This sketch controls a geared stepper motor wirelessly using a phone
The motor will revolve one revolution forward when green button is pressed.
The motor will revolve one revolution backward when red button is pressed.
The motor is attached to digital pins 8 - 11.
An indicator red led is attached to pin 13.
*/
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2,3);
int i=0;
int m=4
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(13, OUTPUT);
}
void loop(){
if (BTserial.available())
data=BTserial.read();
{
if(data == 1)
{
digitalWrite(13, HIGH);
for(i=0;i<512;i++)
{
forward();
}
}
if(data == 0)
{
digitalWrite(13, 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);
}
Comments
Post a Comment