Adafruit has an awesome tutorial on properly wiring and testing your Fona808; you can find it (here). If you want a description of the chip components and required accessories, you can find that (here). This tutorial is based on wiring to an arduino, so make sure you look at the correct tutorial (i.e., not the USB version).
THE CIRCUIT:
WHAT YOU NEED:
- ADAFRUIT FONA808
- Lithium Ion Polymer Battery-3.7V 1200mAh (required for FONA808 to work–no exceptions!)
- Passive GPS Antenna uFL 9mm x 9mm (highly recommended)
- Slim Sticker-type GSM/Cellular Quad-band Atenna (required for FONA808 to work–no exceptions!)
- 2G SIM CARD (required for FONA808 to work–no exceptions!)
- ARDUINO UNO R3
- BREADBOARD
- RGB LED
- SIMPLE PUSH BUTTON
- 330 OHM RESISTOR (3)
- 10 OHM RESISTOR (1)
- JUMPER WIRES (15)
- SOLDERING KIT
PART I | Getting Started
1.1 ASSEMBLY
A) Soldering: You must solder the FONA808 to the header strip or it will NOT produce stable electrical contact (and, therefore, will not work). If you’ve never done this before, check out Adafruit’s guide (here) and/or watch this video. I thought I could skip this step, but alas…
B) Wiring: (based on Arduino UNO)
- Vio connects to 5V
- GND connects to GND
- Key connects to GND (always on)
- RX connects to digital 2
- TX connects to digital 3
- RST connects to digital 4
- PUSH BUTTON connects to digital 8 (with 10 OHM RESISTOR)
- RGB LED connects to digital 9,10,11 (with 330 OHM RESISTORS)
(see image above)
1.2 TEST HARDWARE
C) DOWNLOAD FONA 808 LIBRARY (here) and perform a hardware test (here).
PART 2 | THE CODE
A) BEFORE RUNNING THE CODE
- UPDATE the phone number that you want the text sent to (I’ve removed mine). There are two locations where you will have to make this change. (see image above)
- Upload the code (below) to your arduino uno.
- Open the serial monitor.
B) RUN THE CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
/* * Panic Button! * A way to silently alert authorities or someone who can help with your GPS location. Created 20-11-2017 By Deon P. The tutorial can be found at: http://www.sensingthecity.com */ #include "Adafruit_FONA.h" #include <SoftwareSerial.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; // Use this for FONA 800 and 808s Adafruit_FONA fona = Adafruit_FONA(FONA_RST); //for replies later char replybuffer[255]; uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); uint8_t type; const int buttonPin = 8; // pushbutton pin //RGB pins const int RED_PIN = 9; const int GREEN_PIN = 10; const int BLUE_PIN = 11; void setup() { while (! Serial); Serial.begin(115200); Serial.println(F("Initializing FONA... (May take a few seconds)")); fonaSerial->begin(4800); if (! fona.begin(*fonaSerial)) { Serial.println(F("Couldn't find FONA")); while(1); } Serial.println(F("FONA is OK")); // Try to enable GPRS Serial.println(F("Enabling GPS...")); fona.enableGPS(true); delay(4000); pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); pinMode(BLUE_PIN, OUTPUT); } void loop() { //BLINK RED LED TO SIGNIFY PRE-SMS-SEND (NORMAL) STATUS digitalWrite(RED_PIN, HIGH); delay(1000); digitalWrite(RED_PIN, LOW); delay(1000); int buttonState; buttonState = digitalRead(buttonPin); //if holding down button (i.e. panic) if (buttonState == LOW) { //get gps location float latitude, longitude;//variables to hold initial GPS readings boolean gps_success = fona.getGPS(&latitude, &longitude); if (gps_success) { Serial.print("GPS lat:"); Serial.println(latitude, 6); Serial.print("GPS long:"); Serial.println(longitude, 6); //send sms char message[141]; char LAT1[10];//string of lat and long unparsed & overflowing bound char LAT[10]; char LONG[10]; dtostrf(latitude, 10, 7, LAT1); //gathering GPS data in a format that can be sent dtostrf(longitude, 10, 7, LONG); //initialize desired array from unparsed array for(int i = 0; i < 9; i++) { LAT[i] = LAT1[i]; } LAT[9] = '\0';//truncate array at last desired value sprintf(message, "I JUST PUSHED MY PANIC BUTTON! I NEED HELP NOW! https://www.google.com/maps?q=%s,%s", LAT, LONG); Serial.println(LAT);Serial.println(LAT1);Serial.println(LONG); Serial.println(message) ; //prints the message in the serial monitor before sending char sendto[13] = "+19999999999"; //put the desired destination phone number for sms here fona.sendSMS(sendto, message) ; //sends the message via SMS} //BLINK BLUE LED FOR 30 SECONDS TO NOTIFY THAT TEXT SENT for (int i = 0; i < 30; i++){ digitalWrite(BLUE_PIN, HIGH);//keep blinking light red delay(1000); digitalWrite(BLUE_PIN, LOW);//keep blinking light red delay(1000); } } else { Serial.println("Waiting for FONA GPS 3D fix..."); } // Check for network, then GPRS Serial.println(F("Checking for Cell network...")); if (fona.getNetworkStatus() == 1) { // network & GPRS? Great! Print out the GSM location to compare float latitude, longitude; boolean gsmloc_success = fona.getGSMLoc(&latitude, &longitude); if (gsmloc_success) { Serial.print("GSMLoc lat:"); Serial.println(latitude, 6); Serial.print("GSMLoc long:"); Serial.println(longitude, 6); //send sms char message[141]; char LAT1[10];//string of lat and long unparsed & overflowing bound char LAT[10]; char LONG[10]; dtostrf(latitude, 10, 7, LAT1); //gathering GPS data in a format that can be sent dtostrf(longitude, 10, 7, LONG); //initialize desired array from unparsed array for(int i = 0; i < 9; i++) { LAT[i] = LAT1[i]; } LAT[9] = '\0';//truncate array at last desired value sprintf(message, "I JUST PUSHED MY PANIC BUTTON! I NEED HELP NOW! https://www.google.com/maps?q=%s,%s", LAT, LONG); Serial.println(LAT);Serial.println(LAT1);Serial.println(LONG); Serial.println(message) ; //prints the message in the serial monitor before sending char sendto[13] = "+19999999999"; //put the desired destination phone number for sms here fona.sendSMS(sendto, message) ; //sends the message via SMS} //BLINK BLUE LED FOR 30 SECONDS TO NOTIFY THAT TEXT SENT for (int i = 0; i < 30; i++){ digitalWrite(BLUE_PIN, HIGH);//keep blinking light BLUE delay(1000); digitalWrite(BLUE_PIN, LOW);//keep blinking light BLUE delay(1000); } } else { Serial.println("GSM location failed..."); Serial.println(F("Disabling GPRS")); fona.enableGPRS(false); Serial.println(F("Enabling GPRS")); if (!fona.enableGPRS(true)) { Serial.println(F("Failed to turn GPRS on")); } } } } } |
PART 2 | DEMO
A) Once the RGB LED is blinking red, we’re ready to test. HOLD Down the Button (for about 2-3 seconds) then release it.
B) First, look at the serial monitor. Were you able to get a GPS fix? Hint: If you can see GPS coordinates, then you did!
If not, repeat step 1. (You may need to test near a window or in a place with great cellular reception, since the SMS will not send without getting a GPS fix).
C) IN THE SERIAL MONITOR, after you get a fix, you’ll see the number and message you designated in the code (not +11111111111 as you see in the image below). You’ll also notice that the RGB LED now blinks BLUE (for about 30 seconds).
D) THE SMS (you’ll get the message you created at whatever phone number you designated in the code).
E) THE LINK (it works!)
YOU’RE DONE!
Comments are welcome! Congrats, and thanks for panicking!
2 replies on “Push Button to Send SMS with GPS Location [i.e., Panic Button]”
Hello, I am a High School student that is working on a project involving the use of GPS locations and automatic texting services, but we have no use for the push button in your code. Is there a way to get rid of these push button commands, also what are the numbers next to latitude and longitude referring to because we have looked through the code and have no idea what they are referring to.
hello Iam Final year ECE student. why can’t i send bulk of SMS and repetion of SMS to those persons