SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <EEPROM.h>
  2.  
  3.    
  4. byte echoPin = 10;
  5. byte ledpin = 12;
  6. byte buzzer = 11;
  7. byte trigPin = 9;    
  8. byte temp = 25;
  9. byte result;
  10. long duration, distance;
  11.  
  12.  
  13. void setup(){
  14.  
  15.   pinMode(trigPin, OUTPUT);
  16.   pinMode(echoPin, INPUT);
  17.   pinMode(buzzer, OUTPUT);
  18.   pinMode(ledpin, OUTPUT);
  19.   Serial.begin(9600);
  20.  
  21.   for(int i = 0; i<10; i++)
  22.   {
  23.  
  24.   digitalWrite(trigPin, LOW);
  25.   delayMicroseconds(1);
  26.   digitalWrite(trigPin, HIGH);
  27.   delayMicroseconds(5);
  28.   digitalWrite(trigPin, LOW);
  29.   duration = pulseIn(echoPin, HIGH);
  30.   distance = ((331.5 + 0.6 * temp) / 10000.0) * (duration / 2.0);
  31.   EEPROM.write(i,distance);
  32.  
  33.  
  34.        if(distance<=5)
  35.         {
  36.  
  37.         digitalWrite(buzzer,HIGH);
  38.     digitalWrite(ledpin,HIGH);
  39.  
  40.     }
  41.  
  42.     else
  43.  
  44.     {
  45.  
  46.     digitalWrite(buzzer,LOW);
  47.     digitalWrite(ledpin,LOW);
  48.  
  49.     }
  50.  
  51.           delay(1500);
  52.         }
  53. }
  54.  
  55. void loop(){
  56.  
  57.     for(int i = 0; i < 10; i++)
  58.  
  59.     {
  60.        result = EEPROM.read(i);
  61.        Serial.println(result);
  62.    
  63.     if( result<=5){
  64.    
  65.     digitalWrite(buzzer,HIGH);
  66.     digitalWrite(ledpin,HIGH);
  67.  
  68.     }
  69.  
  70.     else
  71.     {
  72.  
  73.     digitalWrite(buzzer,LOW);
  74.     digitalWrite(ledpin,LOW);
  75.    
  76.     }
  77.  
  78.   delay(1500);
  79. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top