Go Down

Topic: Fona 808 sms code (Read 1 time) previous topic - next topic


I am using Flora micro controller and Fona 808 GSM/GPS  module. I need to send a text message when push button is pressed. I tried altering the fona test coding in Adafruit fona library in Arduino IDE.

But in altered code the message is sent many times without the button being pressed. Please help me out with the problem, as I am new to coding.

Code: [Select]

#include "Adafruit_FONA.h"

#define FONA_RX 10
#define FONA_TX 9
#define FONA_RST 6

const int buttonPin = 12;
int buttonState = 0;

#include <SoftwareSerial.h>

SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

uint8_t type;

void setup() {
  while (!Serial);

  Serial.println(F("FONA basic test"));
  Serial.println(F("Initializing....(May take 3 seconds)"));

  if (! fona.begin(*fonaSerial)) {
    Serial.println(F("Couldn't find FONA"));
    while (1);
  pinMode(buttonPin, INPUT);
  // Print module IMEI number.
  char imei[15] = {0}; // MUST use a 16 character buffer for IMEI!
  uint8_t imeiLen = fona.getIMEI(imei);
  if (imeiLen > 0) {
    Serial.print("Module IMEI: ");

void loop() {
  Serial.print(F("FONA> "));
    char sendto[21]="70########", message[141]="Hiii";
        buttonState = digitalRead(buttonPin);
        if (buttonState == HIGH) {
        fona.sendSMS(sendto, message);
        else {
void flushSerial() {
  while (Serial.available())
}char readBlocking() {
  while (!Serial.available());
  return Serial.read();
uint16_t readnumber() {
  uint16_t x = 0;
  char c;
  while (! isdigit(c = readBlocking())) {
  x = c - '0';
  while (isdigit(c = readBlocking())) {
    x *= 10;
    x += c - '0';
  return x;

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout) {
  uint16_t buffidx = 0;
  boolean timeoutvalid = true;
  if (timeout == 0) timeoutvalid = false;

  while (true) {
    if (buffidx > maxbuff) {

    while (Serial.available()) {
      char c =  Serial.read();

      //Serial.print(c, HEX); Serial.print("#"); Serial.println(c);

      if (c == '\r') continue;
      if (c == 0xA) {
        if (buffidx == 0)   // the first 0x0A is ignored

        timeout = 0;         // the second 0x0A is the end of the line
        timeoutvalid = true;
      buff[buffidx] = c;

    if (timeoutvalid && timeout == 0) {
  buff[buffidx] = 0;  // null term
  return buffidx;


Hey Pushkala,

The first thing I'm seeing is the imei buffer is set to 15 instead of 16 (which is what it should be).

I also don understand why the message is set to 141, that's very high.

As I'm much more of a hardware guy I would recommend testing your circuit, some buttons have two ins and two outs, if you're using both of the ins or outs then you'll just get a constant signal to the arduino to send.


But in altered code the message is sent many times without the button being pressed
Maybe the input is floating.
You should really only send a message when the switch becomes pressed not while it is pressed.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up