Vous êtes sur la page 1sur 18

[21:44, 6/7/2017] +591 73003882: void setup() {

// motor 1

pinMode(7, OUTPUT);

pinMode(6, OUTPUT);

//motor 2

pinMode(5, OUTPUT);

pinMode(4, OUTPUT);

//sensor Izq

pinMode(2, INPUT);

//sensor derecho

pinMode(3, INPUT);

void loop() {

if (digitalRead(2) == HIGH && digitalRead(3) == HIGH)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (digitalRead(2) == LOW && digitalRead(3) == LOW)

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);
}

[21:45, 6/7/2017] +591 73003882: Del seguidor de lnea...

[21:45, 6/7/2017] +591 73003882:

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (digitalRead(2) == LOW && digitalRead(3)

== HIGH)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, HIGH);

if (digitalRead(2) == HIGH && digitalRead(3) == HIGH)

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);

[21:45, 6/7/2017] +591 73003882: void setup() {

// motor 1
pinMode(7, OUTPUT);

pinMode(6, OUTPUT); void setup() {

// motor 1

pinMode(7, OUTPUT);

pinMode(6, OUTPUT);

//motor 2

pinMode(5, OUTPUT);

pinMode(4, OUTPUT);

//sensor Izq

pinMode(2, INPUT);

//sensor derecho

pinMode(3, INPUT);

void loop() {

if (digitalRead(2) == LOW && digitalRead(3) == LOW)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (digitalRead(2) == HIGH && digitalRead(3) == LOW)

digitalWrite(7, LOW);

digitalWrite(6, HIGH);

//motor 2
pinMode(5, OUTPUT);

pinMode(4, OUTPUT);

//sensor Izq

pinMode(2, INPUT);

//sensor derecho

pinMode(3, INPUT);

void loop() {

if (digitalRead(2) == LOW && digitalRead(3) == LOW)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (digitalRead(2) == HIGH && digitalRead(3) == LOW)

digitalWrite(7, LOW);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (digitalRead(2) == LOW && digitalRead(3) == HIGH)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, LOW);
digitalWrite(4, HIGH);

if (digitalRead(2) == HIGH && digitalRead(3) == HIGH)

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);

[21:45, 6/7/2017] +591 73003882: #include <Servo.h>

Servo servo1;

long t;

long d;

long dder;

long dizq;

int estado;

int opcion = 0;

void setup() {

//SENSOR ultrasonido

pinMode(8, INPUT);

pinMode(9, OUTPUT);

servo1.attach(10);

//SENSOR IAQ

pinMode(2, INPUT);

//SENSOR DER
pinMode(3, INPUT);

//MOTOR IZQ

pinMode(7, OUTPUT);

pinMode(6, OUTPUT);

//MOTOR DER

pinMode(5, OUTPUT);

pinMode(4, OUTPUT);

Serial.begin(9600);//CONFIGURAMOS EL PUERTO SERIAL

void loop() {

if (Serial.available() > 0) { // lee el bluetooth y almacena en estado

estado = Serial.read();

Serial.println(estado);

delay(150);

if (estado == 79)

opcion = 0;

if (estado == 80)

opcion = 1;

if (estado == 81)

opcion = 2;
}

switch (opcion)

case 0:

if (digitalRead(2) == LOW && digitalRead(3) == LOW)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (digitalRead(2) == HIGH && digitalRead(3) == LOW)

digitalWrite(7, LOW);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (digitalRead(2) == LOW && digitalRead(3) == HIGH)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, HIGH);

if (digitalRead(2) == HIGH && digitalRead(3) == HIGH)

{
digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);

break;

case 1:

if (estado == 66)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (estado == 72)

digitalWrite(7, LOW);

digitalWrite(6, HIGH);

digitalWrite(5, LOW);

digitalWrite(4, HIGH);

if (estado == 68)

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);
}

if (estado == 70)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);

if (estado == 69)

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);

break;

case 2:

digitalWrite(9, LOW);

delayMicroseconds(5);

digitalWrite(9, HIGH);

delayMicroseconds(10);

t = pulseIn(8, HIGH);

d = (0.017 * t);

Serial.print("distancia frontal ");

Serial.println(d);

delay(500);

if (d <= 10)
{

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);

servo1.write(0);

delay(500);

digitalWrite(9, LOW);

delayMicroseconds(5);

digitalWrite(9, HIGH);

delayMicroseconds(10);

t = pulseIn(8, HIGH);

dder = (0.017 * t);

delay(500);

servo1.write(180);

delay(1000);

digitalWrite(9, LOW);

delayMicroseconds(5);

digitalWrite(9, HIGH);

delayMicroseconds(10);

t = pulseIn(8, HIGH);

dizq = (0.017 * t);


if (dizq > dder)

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

delay(500);

else

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);

delay(500);

servo1.write(90);

delay(500);

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

delay(50);

break;

}
Serial.print(dizq);

Serial.print(" ");

Serial.println(dder);

[21:45, 6/7/2017] +591 73003882: #include <Servo.h>

Servo servo1;

long t;

long d;

long dder;

long dizq;

int estado;

int opcion = 0;

void setup() {

//SENSOR ultrasonido

pinMode(8, INPUT);

pinMode(9, OUTPUT);

servo1.attach(10);

//SENSOR IAQ

pinMode(2, INPUT);

//SENSOR DER

pinMode(3, INPUT);

//MOTOR IZQ

pinMode(7, OUTPUT);

pinMode(6, OUTPUT);

//MOTOR DER

pinMode(5, OUTPUT);
pinMode(4, OUTPUT);

Serial.begin(9600);//CONFIGURAMOS EL PUERTO SERIAL

void loop() {

if (Serial.available() > 0) { // lee el bluetooth y almacena en estado

estado = Serial.read();

Serial.println(estado);

delay(150);

if (estado == 79)

opcion = 0;

if (estado == 80)

opcion = 1;

if (estado == 81)

opcion = 2;

switch (opcion)

case 0:

if (digitalRead(2) == LOW && digitalRead(3) == LOW)

{
digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (digitalRead(2) == HIGH && digitalRead(3) == LOW)

digitalWrite(7, LOW);

digitalWrite(6, HIGH);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (digitalRead(2) == LOW && digitalRead(3) == HIGH)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, HIGH);

if (digitalRead(2) == HIGH && digitalRead(3) == HIGH)

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);

break;
case 1:

if (estado == 66)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (estado == 72)

digitalWrite(7, LOW);

digitalWrite(6, HIGH);

digitalWrite(5, LOW);

digitalWrite(4, HIGH);

if (estado == 68)

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

if (estado == 70)

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, LOW);
digitalWrite(4, LOW);

if (estado == 69)

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);

break;

case 2:

digitalWrite(9, LOW);

delayMicroseconds(5);

digitalWrite(9, HIGH);

delayMicroseconds(10);

t = pulseIn(8, HIGH);

d = (0.017 * t);

Serial.print("distancia frontal ");

Serial.println(d);

delay(500);

if (d <= 10)

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);
servo1.write(0);

delay(500);

digitalWrite(9, LOW);

delayMicroseconds(5);

digitalWrite(9, HIGH);

delayMicroseconds(10);

t = pulseIn(8, HIGH);

dder = (0.017 * t);

delay(500);

servo1.write(180);

delay(1000);

digitalWrite(9, LOW);

delayMicroseconds(5);

digitalWrite(9, HIGH);

delayMicroseconds(10);

t = pulseIn(8, HIGH);

dizq = (0.017 * t);

if (dizq > dder)

digitalWrite(7, LOW);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);
delay(500);

else

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, LOW);

digitalWrite(4, LOW);

delay(500);

servo1.write(90);

delay(500);

digitalWrite(7, HIGH);

digitalWrite(6, LOW);

digitalWrite(5, HIGH);

digitalWrite(4, LOW);

delay(50);

break;

Serial.print(dizq);

Serial.print(" ");

Serial.println(dder);