Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://labdegaragem.com/forum/topics/duvidas-altera-o-de-frequencia-no-buzzer-sensor-ultrassonico
- #define trigPin 13 // Pino de disparo do US
- #define echoPin 12 // Pino de leitura do US
- #define led 11 // Pino Led indicativo 1
- #define led2 10 // Pino Led indicativo2
- #define led3 5 // Pino Led indicativo 3
- #define pinBuzzer 7 // Pino saída buzzer
- void setup() {
- Serial.begin (9600);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- pinMode(led, OUTPUT);
- pinMode(led2, OUTPUT);
- pinMode(led3,OUTPUT);
- pinMode(pinBuzzer,OUTPUT);
- }
- void loop() {
- long duration, distance;
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = (duration/2) / 29.1;
- map(distance, 0, 400,200,10);
- tone(pinBuzzer,(10,262,distance));
- if (distance >= 400 || distance <= 0){
- Serial.println("Out of range");
- }
- else {
- Serial.print(distance);
- Serial.println(" cm");
- }
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement