About Bluetooth Arduino Carro Robot
Controlar Arduino mediante bluetooth para cuatro principales movimientos. Puede servir para gruas, carros, Brazos y más.
Datos que envia el APP
Flecha N "Norte" = 'n'
Flecha S "Sur" = 's'
Flecha O "Oeste" = 'o'
Flecha E "Este" = 'e'
Flecha P "Parar" = 'p'
Boton Verde "Encender" = 'h'
Boton Rojo "Apagar" = 'l'
// INICIO DEL CÓDIGO
int Pecho = 4; // define Pecho como (echo) para el Ultrasonido
int Ptrig = 5; // define Ptrig como (trig) para el Ultrasonido
int LaIzAn = 6; // Giro Lado Izquierdo AntiHorario
int LaIzHo = 7; // Giro Lado Izquierdo Horario
int LaDeHo = 8; // Giro Lado Derecho Horario
int LaDeAn = 9; // Giro Lado Derecho AntiHorario
int Mov = 255; // Movimiento de motor (0-255)
int estado = 'l'; // inicia detenido
int duracion, distancia; // Para Calcular distacia
void setup() {
Serial.begin(9600); // inicia el puerto serial para comunicacion con el Bluetooth
pinMode(LaDeHo, OUTPUT);
pinMode(LaDeAn, OUTPUT);
pinMode(LaIzHo, OUTPUT);
pinMode(LaIzAn, OUTPUT);
pinMode(Pecho, INPUT); // define el pin 4 como entrada (echo)
pinMode(Ptrig,OUTPUT); // define el pin 5 como salida (trig)
}
void loop() {
if(Serial.available()>0){ // lee el bluetooth y almacena en estado
estado = Serial.read();
}
if(estado=='n'){ // Desplazar hacia Adelante "Norte"
analogWrite(LaDeAn, 0);
analogWrite(LaIzAn, 0);
analogWrite(LaDeHo, Mov);
analogWrite(LaIzHo, Mov);
}
if(estado=='s'){ // Desplazar hacia Atras "Sur"
analogWrite(LaDeAn, Mov);
analogWrite(LaIzAn, Mov);
analogWrite(LaDeHo, 0);
analogWrite(LaIzHo, 0);
}
if(estado=='o'){ // Desplazar hacia LadDerecha "Oeste"
analogWrite(LaDeAn, 0);
analogWrite(LaIzAn, 0);
analogWrite(LaIzHo, 0);
analogWrite(LaDeHo, Mov);}
if(estado=='e'){ // Desplazar hacia LadIzquierdo "Este"
analogWrite(LaDeAn, 0);
analogWrite(LaIzAn, 0);
analogWrite(LaIzHo, Mov);
analogWrite(LaDeHo, 0);
}
if(estado=='p'){ // Detenerse; Detiene los motores
analogWrite(LaDeAn, 0);
analogWrite(LaIzAn, 0);
analogWrite(LaDeHo, 0);
analogWrite(LaIzHo, 0);
}
if (estado =='h'){ // Boton Verde Modo automatico con sensor Ultrasonido
digitalWrite(Ptrig, HIGH); // genera el pulso de trigger por 10us
delay(0.01);
digitalWrite(Ptrig, LOW);
duracion = pulseIn(Pecho, HIGH); // Lee el tiempo del Echo
distancia = (duracion/2) / 29; // calcula la distancia en centimetros
delay(10);
if (distancia <= 15 && distancia >=2){ // si la distancia es menor de 15cm
analogWrite(LaDeAn, 0); // Parar los motores por 1/4 de segundo
analogWrite(LaIzAn, 0);
analogWrite(LaDeHo, 0);
analogWrite(LaIzHo, 0);
delay (250);
analogWrite(LaDeHo, 0);
analogWrite(LaIzHo, 0);
analogWrite(LaDeAn, Mov); // Reversa durante 1/2 de segundo
analogWrite(LaIzAn, Mov);
delay(500);
analogWrite(LaDeAn, 0); // Girar durante 1 segundo
analogWrite(LaIzAn, 0);
analogWrite(LaDeHo, 0);
analogWrite(LaIzHo, Mov);
delay(1000);
}
else{ // Si no hay obstaculos se desplaza al frente
analogWrite(LaDeAn, 0);
analogWrite(LaIzAn, 0);
analogWrite(LaDeHo, Mov);
analogWrite(LaIzHo, Mov);
}
}
if(estado=='l'){ // Boton OFF, detiene los motores.
analogWrite(LaDeAn, 0);
analogWrite(LaIzAn, 0);
analogWrite(LaDeHo, 0);
analogWrite(LaIzHo, 0);
}
}
//FIN DEL CÓDIGO
Más Manuales en http://manual.netandino.net Controlling Arduino via Bluetooth to four major movements. It can serve for cranes, trucks, Brazos and more.
Data that sends the APP
Arrow N 'North' = 'n'
Arrow S 'South' = 's'
Arrow O 'West' = 'or'
Arrow E "This" = 'e'
Arrow P "Stop" = 'p'
Pin Green "Power" = 'h'
Red Button "Off" = 'l'
HOME // CODE
Chest int = 4; // Define Chest and (echo) for Ultrasound
Ptrig int = 5; // Define Ptrig as (trig) for Ultrasound
LaIzAn int = 6; // Left Side Giro counter
Laizhou int = 7; // Left Side Giro Hours
LaDeHo int = 8; // Right Side Giro Hours
They turn int = 9; // Right Side Giro counter
Mov int = 255; // Movement motor (0-255)
int status = 'l'; // Starts arrested
int duration, distance; // To Calculate distacia
void setup () {
Serial.begin (9600); // Start the serial port for communication with Bluetooth
pinMode (LaDeHo, OUTPUT);
pinMode (They turn, OUTPUT);
pinMode (Laizhou, OUTPUT);
pinMode (LaIzAn, OUTPUT);
pinMode (Chest, INPUT); // I define as input pin 4 (echo)
pinMode (Ptrig, OUTPUT); // Define the output pin 5 (trig)
}
void loop () {
if (Serial.available ()> 0) {// read the bluetooth and stored in state
status = Serial.read ();
}
if (state == 'n') {// Move Forward "North"
analogWrite (They turn, 0);
analogWrite (LaIzAn, 0);
analogWrite (LaDeHo, Mov);
analogWrite (Laizhou, Mov);
}
if (state == 's') {// Move Back "South"
analogWrite (They turn, Mov);
analogWrite (LaIzAn, Mov);
analogWrite (LaDeHo, 0);
analogWrite (Laizhou, 0);
}
if (state == 'o') {// Move LadDerecha "West"
analogWrite (They turn, 0);
analogWrite (LaIzAn, 0);
analogWrite (Laizhou, 0);
analogWrite (LaDeHo, Mov);}
if (state == 'e') {// Move LadIzquierdo "This"
analogWrite (They turn, 0);
analogWrite (LaIzAn, 0);
analogWrite (Laizhou, Mov);
analogWrite (LaDeHo, 0);
}
if (state == 'p') {// Stop; Stops engines
analogWrite (They turn, 0);
analogWrite (LaIzAn, 0);
analogWrite (LaDeHo, 0);
analogWrite (Laizhou, 0);
}
if (state == 'h') {// Button Green Mode Automatic Ultrasonic sensor
digitalWrite (Ptrig, HIGH); // Trigger pulse generated by 10us
delay (0.01);
digitalWrite (Ptrig, LOW);
duration = pulseIn (Chest, HIGH); // Read the Echo time
distance = (length / 2) / 29; // Calculate the distance in feet
delay (10);
if (distance <= 15 && distance> = 2) {// if the distance is less than 15cm
analogWrite (They turn, 0); // Stop the engine by 1/4 second
analogWrite (LaIzAn, 0);
analogWrite (LaDeHo, 0);
analogWrite (Laizhou, 0);
delay (250);
analogWrite (LaDeHo, 0);
analogWrite (Laizhou, 0);
analogWrite (They turn, Mov); // Reverse for 1/2 second
analogWrite (LaIzAn, Mov);
delay (500);
analogWrite (They turn, 0); // Turn for 1 second
analogWrite (LaIzAn, 0);
analogWrite (LaDeHo, 0);
analogWrite (Laizhou, Mov);
delay (1000);
}
else {// If no obstacles moves forward
analogWrite (They turn, 0);
analogWrite (LaIzAn, 0);
analogWrite (LaDeHo, Mov);
analogWrite (Laizhou, Mov);
}
}
if (state == 'l') {// Button OFF, engine stops.
analogWrite (They turn, 0);
analogWrite (LaIzAn, 0);
analogWrite (LaDeHo, 0);
analogWrite (Laizhou, 0);
}
}
// END CODE
More Manuals http://manual.netandino.net