Hi all,
I am doing a project which involves a cellular chip with GPS. I have it set that when a pair of wires disconnect from one another, it is supposed to start a timer. When that timer surpasses 30 seconds, then I want it to call and text. But while it is counting, I still need it to detect a cancel button to cancel all operations and return back to its resting state.
With that said, I have no idea how to continue from here, or even know if the stuff I have already is correct or not. Can someone help me in figuring this out?
My email is shenangostem@gmail.com if you want to contact me.
I look forward to hearing from you! Here is my code:
#include "Adafruit_FONA.h"
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST); //define fona
// constants
const int buttonPin = 5 ; // button for auto emergency distress
const int cancelPin = 6;
const int ledPin = 13; // LED for distress will be called
const int recordPin = 11;
// variables
int buttonState = 0; //start with harness connected
int cancelState = 0;
unsigned long startMillis; //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 1000; //the value is a number of milliseconds
//strings
char gps_string[ 140 ]; //define the GPS information as a string
void setup() {
Serial.begin(4800); //start serial monitor at 4800 baud
Serial.println("Beginning Setup");
fonaSerial->begin(4800); //begin software serial at 4800 baud
fona.begin(*fonaSerial); //fona begins to utilize software serial
fona.enableGPS(true); //enable GPS function
fona.getGPS( 0, gps_string, 140 ); //get the GPS location as a reference
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
pinMode(cancelPin, INPUT);
pinMode(recordPin, OUTPUT); //set the digital record pin as an output
}
void loop() {
currentMillis = millis();
buttonState = digitalRead(buttonPin); //read for button push every loop
cancelState = digitalRead(cancelPin);
fona.getGPS( 0, gps_string, 140 ); //update GPS info every loop
Serial.println("Pin State:" + buttonState); //
if (buttonState = 0) {
startMillis = millis();
}
if (startMillis < 30 && cancelState = 1) { //if pin is high (harness still connected) keep everything off
digitalWrite(ledPin, LOW);
digitalWrite(recordPin, LOW);
fona.hangUp();}
else { //if pin is low (harness tripped) turn everything on
digitalWrite(ledPin, 1);
fona.sendSMS("555-555-5555", "help...i've fallen and I can't get up!");
Serial.println("Text Message Sent");
delay(2500);
fona.sendSMS("555-555-5555", gps_string );
Serial.println("GPS Coordinates Sent");
delay(5000);
fona.callPhone("555-555-5555");
Serial.println("Calling");
delay(7500);
digitalWrite(recordPin, HIGH);
delay(500);
digitalWrite(recordPin, LOW);
Serial.println("Recording Started");
}
}