SHARE
TWEET

Untitled

a guest Mar 24th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Medidor de nivel via Arduino
  2. //Feito pro Fabio H. Araujo
  3. //araujofabio@airmail.cc
  4.  
  5. #define trig 11 //trigger
  6. #define echo 12 //receiver
  7. #define BB1 7 //botao
  8.  
  9. //config do US
  10. void trigPuls ();
  11. float pulse;
  12. float dist_cm;
  13.  
  14. int distmax; //variavel da distancia maxima
  15. int VV1; //porcentagem
  16. int EB1 = 0; //variavel do botao  
  17.  
  18. void setup () {
  19.   pinMode(trig, OUTPUT);
  20.   pinMode(echo, INPUT);
  21.   pinMode(BB1, INPUT);
  22.  
  23.   digitalWrite(trig, LOW);
  24.  
  25.   Serial.begin(9600);
  26. }
  27.  
  28. void loop() {
  29.  
  30.   trigPuls();
  31.   pulse = pulseIn(echo, HIGH);
  32.   dist_cm = pulse/58.82;
  33.  
  34.   delay(500);
  35.  
  36.   EB1 = digitalRead(BB1);
  37.   if(EB1 == HIGH) {
  38.     VV1 = (pulse / 255.0) * 100;
  39.     long distmax = VV1;
  40.     Serial.print("Distancia maxima calculada (em porcentagem):");
  41.     Serial.println(VV1);
  42.     delay(1000);
  43.   }
  44.  
  45.   if(distmax >= 80) {
  46.     //acionar buzzer
  47.     delay(1000);
  48.   }
  49. }
  50.  
  51. void trigPuls()
  52. {
  53.   digitalWrite(trig, HIGH);
  54.   delayMicroseconds(10);
  55.   digitalWrite(trig, LOW);
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top