Вы находитесь на странице: 1из 4

#include <Ultrasonic.

h>

Ultrasonic ultrasonic1(50,2); // (Trig PIN,Echo PIN)


Ultrasonic ultrasonic2(48,3);
Ultrasonic ultrasonic3(46,4);
Ultrasonic ultrasonic4(44,5);
Ultrasonic ultrasonic5(42,6);

const int zumbador = 8; // Zumbador conectado al pin 6


const int led1 = 10; // LED conectado al pin 6
const int led2 = 11;
const int led3 = 12;

void setup() {
Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.

pinMode(zumbador, OUTPUT);

pinMode(led3, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}

void uno() {
int pausa1,distance1 ;
Serial.print(ultrasonic1.Ranging(CM));
delay(100);// CM or INC
Serial.println(" cm1" );
distance1= ultrasonic1.Ranging(CM);

if(distance1 >= 546 || distance1 <= 1){


Serial.println("fuera de rango");
distance1=1000;
}
else {
Serial.print(distance1);
Serial.println("cm");
}
if(distance1 < 50){
pausa1 = distance1 * 10;
digitalWrite(zumbador, HIGH);
digitalWrite(led1, HIGH);
delay(pausa1);
}

digitalWrite(zumbador, LOW);
digitalWrite(led1, LOW);
delay(pausa1);
}
void dos() {
int pausa2,distance2 ;
Serial.print(ultrasonic2.Ranging(CM)); // CM or INC
Serial.println(" cm1" );
distance2= ultrasonic2.Ranging(CM);

if(distance2 >= 546 || distance2 <= 1){


Serial.println("fuera de rango1");
distance2=1000;
}
else {
Serial.print(distance2);
Serial.println("cm1");
}
if(distance2 < 50){
pausa2 = distance2 * 10;
digitalWrite(zumbador, HIGH);
digitalWrite(led2, HIGH);
delay(pausa2);
}

digitalWrite(zumbador, LOW);
digitalWrite(led2, LOW);
delay(pausa2);
}

void tres() {
int pausa3,distance3 ;
Serial.print(ultrasonic3.Ranging(CM)); // CM or INC
Serial.println(" cm1" );
distance3 =ultrasonic3.Ranging(CM);
if(distance3 >= 546 || distance3 <= 1){
Serial.println("fuera de rango2");
distance3=1000;
}
else {
Serial.print(distance3);
Serial.println("cm2");
}
if(distance3 < 50){
pausa3 = distance3 * 10;
digitalWrite(zumbador, HIGH);
digitalWrite(led3, HIGH);
delay(pausa3);
}

digitalWrite(zumbador, LOW);
digitalWrite(led3, LOW);
delay(pausa3);
}

void cuatro() {
int pausa4,distance4 ;
Serial.print(ultrasonic4.Ranging(CM)); // CM or INC
Serial.println(" cm1" );
distance4 =ultrasonic4.Ranging(CM);

if(distance4 >= 546 || distance4 <= 1){


Serial.println("fuera de rango3");
distance4=1000;
}
else {
Serial.print(distance4);
Serial.println("cm3");
}
if(distance4 < 50){
pausa4 = distance4 * 10;
digitalWrite(zumbador, HIGH);
digitalWrite(led1, HIGH);
delay(pausa4);
}

digitalWrite(zumbador, LOW);
digitalWrite(led1, LOW);
delay(pausa4);
}

void cinco() {
int pausa5,distance5 ;
Serial.print(ultrasonic5.Ranging(CM)); // CM or INC
Serial.println(" cm1" );
distance5 =ultrasonic5.Ranging(CM);

if(distance5 >= 546 || distance5 <= 1){


Serial.println("fuera de rango4");
distance5=1000;
}
else {
Serial.print(distance5);
Serial.println("cm3");
}
if(distance5 < 50){
pausa5 = distance5 * 10;
digitalWrite(zumbador, HIGH);
digitalWrite(led1, HIGH);
delay(pausa5);
}

digitalWrite(zumbador, LOW);
digitalWrite(led1, LOW);
delay(pausa5);
}

void loop() {
Serial.println ("\ n");
uno();
dos();
tres();
cuatro();
cinco();
delay(500);
}