Advertisement
dansguardian

Sensor TERREMOTO ARDUINO

Nov 5th, 2016
3,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
IO 2.41 KB | None | 0 0
  1. #include <EEPROM.h>
  2. #include "EEPROMAnything.h"
  3. #include <LiquidCrystal.h>
  4.  
  5.  
  6. const int alarmPin = 5;
  7. const int relayPin = 10;
  8. int Xacc, Yacc, Zacc, threshold = 0, thresholdSET = 25;
  9. long debouncing_time = 15; //tiempo de rebote en milisegundos
  10. volatile unsigned long last_micros;
  11. LiquidCrystal lcd(12, 11, 9, 8, 7, 6);
  12. struct sensorValue
  13. {
  14.   int X;
  15.   int Y;
  16.   int Z;
  17. };
  18.  
  19. sensorValue acceleration;
  20.  
  21. void debounceInterrupt_Increment()
  22. {
  23.   if ((long)(micros() - last_micros) >= debouncing_time * 1000) {
  24.     IncrementThreshold();
  25.     last_micros = micros();
  26.   }
  27. }
  28.  
  29. void debounceInterrupt_Decrement()
  30. {
  31.   if ((long)(micros() - last_micros) >= debouncing_time * 1000) {
  32.     DecrementThreshold();
  33.     last_micros = micros();
  34.   }
  35. }
  36. void IncrementThreshold() {
  37.   thresholdSET = EEPROM.read(500);
  38.   thresholdSET++;
  39.   EEPROM.write(500, thresholdSET);
  40. }
  41.  
  42. void DecrementThreshold() {
  43.   thresholdSET = EEPROM.read(500);
  44.   thresholdSET--;
  45.   EEPROM.write(500, thresholdSET);
  46. }
  47.  
  48. void setup() {
  49.   lcd.begin(16, 2);
  50.   attachInterrupt(0, debounceInterrupt_Increment, RISING);
  51.   attachInterrupt(1, debounceInterrupt_Decrement, RISING);
  52.   pinMode(alarmPin, OUTPUT);
  53.   pinMode(relayPin, OUTPUT);
  54.   digitalWrite(relayPin, HIGH);
  55.   EEPROM.write(500, thresholdSET);
  56.   digitalWrite(alarmPin, LOW);
  57.   lcd.setCursor(0, 0);
  58.   lcd.print("Inicializando....");
  59.   delay(5000);
  60.   sensorValue acceleration = { analogRead(A0) , analogRead(A1) , analogRead(A2) };
  61.   EEPROM_writeAnything(0, acceleration);
  62.   EEPROM_readAnything(0, acceleration);
  63.   lcd.clear();
  64. }
  65.  
  66. void loop() {
  67.   EEPROM_readAnything(0, acceleration);
  68.   threshold = EEPROM.read(500);
  69.   lcd.setCursor(0, 0);
  70.   lcd.print("Modo monitor");
  71.   lcd.setCursor(0,1);
  72.   lcd.print("lÍMITE = ");
  73.   lcd.print(threshold);
  74.   Xacc = analogRead(A0);
  75.   Yacc = analogRead(A1);
  76.   Zacc = analogRead(A2);
  77.  
  78.   if ((Xacc >= (acceleration.X + threshold)) || (Xacc <= (acceleration.X - threshold))||(Yacc >= (acceleration.Y + threshold)) || (Yacc <= (acceleration.Y - threshold))||(Zacc >= (acceleration.Z + threshold)) || (Zacc <= (acceleration.Z - threshold))) {
  79.     digitalWrite(relayPin, LOW);
  80.     digitalWrite(alarmPin, HIGH);
  81.     lcd.clear();
  82.     lcd.setCursor(0, 0);
  83.     lcd.print("PELIGRO !!!!!");
  84.     lcd.setCursor(0,1);
  85.     lcd.print("POR FAVOR EVACUAR");
  86.     delay(5000);
  87.     digitalWrite(relayPin, HIGH);
  88.     digitalWrite(alarmPin, LOW);
  89.     lcd.clear();
  90.   }
  91.  
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement