Pls check this arduino code for earth quake detector

Discussion in 'The Projects Forum' started by rijoe.mathew, Feb 22, 2016.

  1. rijoe.mathew

    Thread Starter Member

    Sep 21, 2014
    42
    0
  2. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,810
    834
    I would have, had you attached the code. As it is, I can't read .rar files nor am I going to an unknown link.

    Attach the code and give us a detailed description of the error message.
     
  3. rijoe.mathew

    Thread Starter Member

    Sep 21, 2014
    42
    0
    This is the code:

    Code (C):
    1.  
    2. #include <EEPROM.h>
    3.  
    4. #include <EEPROM.h>
    5. #include "EEPROMAnything.h"
    6. #include <LiquidCrystal.h>
    7.  
    8.  
    9. const int alarmPin = 5;
    10. const int relayPin = 10;
    11. int Xacc, Yacc, Zacc, threshold = 0, thresholdSET = 25;
    12. long debouncing_time = 15; //Debouncing Time in Milliseconds
    13. volatile unsigned long last_micros;
    14. LiquidCrystal lcd(12, 11, 9, 8, 7, 6);
    15. struct sensorValue
    16. {
    17. int X;
    18. int Y;
    19. int Z;
    20. };
    21.  
    22. sensorValue acceleration;
    23.  
    24. void debounceInterrupt_Increment()
    25. {
    26. if ((long)(micros() - last_micros) >= debouncing_time * 1000) {
    27. IncrementThreshold();
    28. last_micros = micros();
    29. }
    30. }
    31.  
    32. void debounceInterrupt_Decrement()
    33. {
    34. if ((long)(micros() - last_micros) >= debouncing_time * 1000) {
    35. DecrementThreshold();
    36. last_micros = micros();
    37. }
    38. }
    39. void IncrementThreshold() {
    40. thresholdSET = EEPROM.read(500);
    41. thresholdSET++;
    42. EEPROM.write(500, thresholdSET);
    43. }
    44.  
    45. void DecrementThreshold() {
    46. thresholdSET = EEPROM.read(500);
    47. thresholdSET--;
    48. EEPROM.write(500, thresholdSET);
    49. }
    50.  
    51. void setup() {
    52. lcd.begin(16, 2);
    53. attachInterrupt(0, debounceInterrupt_Increment, RISING);
    54. attachInterrupt(1, debounceInterrupt_Decrement, RISING);
    55. pinMode(alarmPin, OUTPUT);
    56. pinMode(relayPin, OUTPUT);
    57. digitalWrite(relayPin, HIGH);
    58. EEPROM.write(500, thresholdSET);
    59. digitalWrite(alarmPin, LOW);
    60. lcd.setCursor(0, 0);
    61. lcd.print("Initializing....");
    62. delay(5000);
    63. sensorValue acceleration = { analogRead(A0) , analogRead(A1) , analogRead(A2) };
    64. EEPROM_writeAnything(0, acceleration);
    65. EEPROM_readAnything(0, acceleration);
    66. lcd.clear();
    67. }
    68.  
    69. void loop() {
    70. EEPROM_readAnything(0, acceleration);
    71. threshold = EEPROM.read(500);
    72. lcd.setCursor(0, 0);
    73. lcd.print("Monitoring Mode");
    74. lcd.setCursor(0,1);
    75. lcd.print("Threshold = ");
    76. lcd.print(threshold);
    77. Xacc = analogRead(A0);
    78. Yacc = analogRead(A1);
    79. Zacc = analogRead(A2);
    80.  
    81. 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))) {
    82. digitalWrite(relayPin, LOW);
    83. digitalWrite(alarmPin, HIGH);
    84. lcd.clear();
    85. lcd.setCursor(0, 0);
    86. lcd.print("ALARM !!!!!");
    87. lcd.setCursor(0,1);
    88. lcd.print("PLEASE EVACUATE");
    89. delay(5000);
    90. digitalWrite(relayPin, HIGH);
    91. digitalWrite(alarmPin, LOW);
    92. lcd.clear();
    93. }
    94.  
    95.  
    96. }
    97.  
    Moderators note: used code tags for C
     
    Last edited by a moderator: Feb 22, 2016
  4. rijoe.mathew

    Thread Starter Member

    Sep 21, 2014
    42
    0
    Im getting an EPROM error
     
  5. ebeowulf17

    Active Member

    Aug 12, 2014
    678
    79
    Are the include statements supposed to have some names in quotes and others in brackets? Looks weird to me, but I'm not sure either way. No time to look it up right now.
     
  6. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,810
    834
    Why are you including the EEPROM library twice? Cut one include out. Are you sure the EEPROMAnything library is compatible with EEPROM?

    Some names in quotes and some in brackets make sense. One is a local dir and the other is the public dir. I can't look up which one is what right now.
     
  7. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,810
    834
    Please include the error. My crystal ball is in the shop. Something with this much detail would be helpful:
    Code (Text):
    1. In file included from sketch_jul13b.cpp:2:
    2. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:2:46: error: Arduino.h: No such file or directory
    3. In file included from sketch_jul13b.cpp:2:
    4. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h: In function 'int EEPROM_writeAnything(int, const T&)':
    5. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:6: error: expected initializer before '*' token
    6. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:9: error: 'p' was not declared in this scope
    7. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h: In function 'int EEPROM_readAnything(int, T&)':
    8. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:15: error: 'byte' was not declared in this scope
    9. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:15: error: 'p' was not declared in this scope
    10. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:15: error: expected primary-expression before ')' token
    11. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:15: error: expected primary-expression before 'void'
     
  8. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,810
    834
    Please include the error. My crystal ball is in the shop. Something with this much detail would be helpful:
    Code (Text):
    1. In file included from sketch_jul13b.cpp:2:
    2. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:2:46: error: Arduino.h: No such file or directory
    3. In file included from sketch_jul13b.cpp:2:
    4. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h: In function 'int EEPROM_writeAnything(int, const T&)':
    5. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:6: error: expected initializer before '*' token
    6. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:9: error: 'p' was not declared in this scope
    7. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h: In function 'int EEPROM_readAnything(int, T&)':
    8. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:15: error: 'byte' was not declared in this scope
    9. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:15: error: 'p' was not declared in this scope
    10. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:15: error: expected primary-expression before ')' token
    11. C:\arduino-0023\libraries\EEPROM/EEPROMAnything.h:15: error: expected primary-expression before 'void'
     
  9. ebeowulf17

    Active Member

    Aug 12, 2014
    678
    79
    Thanks for the explanation. Knowing that's an option may help me later.
     
Loading...