My Cart

How to Translate SMS Text Messages into Morse Code Using GSM/GPRS Mobile Kit

Difficulty Level: Intermediate -

Introduction

This tutorial allows the user to translate SMS text messages into morse code. When the module receives a SMS it will reproduce it in morse code through the buzzer.

Ingredients:

    - 1 x GSM/GPRS Mobile Kit:
    • 1x Platform
    • 1x GPRS/GSM QUADBAND MODULE (SIM900)
    • 1x GPRS antenna
    • 1x Buzzer
    • 1x 220Ω resistors
    • 1x Breadboard
    • 1x External power supply
    • 1x Programming cable
    • Jumper Wires

Preparation Time: 30 minutes

Buy now
NOTE: Depending on the platform chosen to develop the project, the ingredients and the schematics shown in this tutorial can vary.

This project can be developed with Arduino or Intel Galileo. It is also compatible with Raspberry Pi using the Raspberry Pi to Arduino shields connection bridge.

For further information about the GPRS/GSM QUADBAND MODULE (SIM900) Shield, consult the main tutorial.

Step 1: Connection

Connect the GPRS antenna to the shield and then, connect the shield to Arduino or to Raspberry Pi connection bridge. Connect the resistor and the buzzer in the breadboard as you can see in the next diagram.

Connect two wires, red and black, to the two long rows on the side of the breadboard to provide access to the VCC supply (5V in Arduino and 3.3V in Raspberry Pi) and ground. Then, connect digital pin 9 to one leg of the resistor. That other leg of the resistor is connected to the negative of the buzzer.Finally, connect positive terminal, marked with a "+", to VCC.

WARNING: In Raspberry Pi, GPIO voltage levels are 3.3 V and are not 5 V tolerant. There is no over-voltage protection on the board. Digital inputs use a 3V3 logic level and are not tolerant of 5V levels, such as you might find on a 5V powered Arduino. Extreme caution when working with GPIO, you may damage your Raspberry Pi, your equipment and potentially yourself and others. Doing so is at your own risk!

Step 2: The Code

Arduino:

Code:
/*  
 *  GPRS/GSM Quadband Module (SIM900)
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Luis Miguel MartĂ­
 */

 
#include <Morse.h>

Morse morse(9);

Morse morse(9);

int8_t answer;
int x;
int onModulePin = 2;
char SMS[200];
char character;

void setup() {

  pinMode(onModulePin, OUTPUT);
  Serial.begin(115200);

  Serial.println("Starting...");
  power_on();
  digitalWrite(9, HIGH);
  delay(3000);
  memset(SMS, 0, sizeof(SMS));

  Serial.println("Setting SMS mode...");
  sendATcommand("AT+CMGF=1", "OK", 1000);    // sets the SMS mode to text
  delay(500);
  sendATcommand("AT+CNMI=3,2,0,0", "OK", 1000); //configure new message reception
}

void loop() {

  if (Serial.read() == '+') {

    for (byte i = 0; i < 200; i++) {
      delay(1);
      SMS[i] = Serial.read();
    }
    byte z = 47;
    while (char(SMS[z]) != '\n') {
      Serial.print(SMS[z]);
      morseChar(SMS[z]);
      z++;
    }
  }

}

void morseChar(char character) {

  if (character >= 'a') character = character - 'a' + 'A';
  switch (character) {
    case 'A':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'B':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'C':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'D':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'E':
      morse.dot();
      break;
    case 'F':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'G':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'H':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'I':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'J':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'K':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'L':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'M':
      morse.dash();
      morse.elemPause();
      morse.dash();
      break;
      morse.space();
    case 'N':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'O':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'P':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'Q':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'R':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'S':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'T':
      morse.dash();
      break;
    case 'U':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'V':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'W':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'X':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'Y':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'Z':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case ' '://word pause
      morse.wordPause();
      break;
    case '0':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case '1':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case '2':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case '3':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case '4':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case '5':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case '6':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case '7':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case '8':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case '9':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;

  }
}

void power_on() {

  uint8_t answer = 0;

  // checks if the module is started
  answer = sendATcommand("AT", "OK", 2000);
  if (answer == 0)
  {
    // power on pulse
    digitalWrite(onModulePin, HIGH);
    delay(3000);
    digitalWrite(onModulePin, LOW);

    // waits for an answer from the module
    while (answer == 0) {   // Send AT every two seconds and wait for the answer
      answer = sendATcommand("AT", "OK", 2000);
    }
  }

}

int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout) {

  uint8_t x = 0,  answer = 0;
  char response[100];
  unsigned long previous;

  memset(response, '\0', 100);    // Initialice the string

  delay(100);

  while ( Serial.available() > 0) Serial.read();   // Clean the input buffer

  Serial.println(ATcommand);    // Send the AT command


  x = 0;
  previous = millis();

  // this loop waits for the answer
  do {
    // if there are data in the UART input buffer, reads it and checks for the asnwer
    if (Serial.available() != 0) {
      response[x] = Serial.read();
      x++;
      // check if the desired answer is in the response of the module
      if (strstr(response, expected_answer) != NULL)
      {
        answer = 1;
      }
    }
    // Waits for the asnwer with time out
  } while ((answer == 0) && ((millis() - previous) < timeout));

  return answer;
}
        

Raspberry Pi:

Code:
/*  
 *  GPRS/GSM Quadband Module (SIM900)
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Marcos Martinez
 */
 
#include "arduPi.h"


#define BUZZER 9

int8_t answer;
int x;
int onModulePin = 2;
char SMS[200];
char character;

void morseChar(char character);
void power_on();
int8_t sendATcommand(const char* ATcommand, const char* expected_answer, unsigned int timeout);

void dot();
void dash();
void elemPause();
void space();
void wordPause();

void setup() {
  pinMode(BUZZER, OUTPUT);
  pinMode(onModulePin, OUTPUT);
  Serial.begin(115200);

  printf("Starting...\n");
  power_on();
  digitalWrite(9, HIGH);
  delay(3000);
  memset(SMS, 0, sizeof(SMS));

  printf("Setting SMS mode...\n");
  sendATcommand("AT+CMGF=1", "OK", 1000);    // sets the SMS mode to text
  delay(500);
  sendATcommand("AT+CNMI=3,2,0,0", "OK", 1000); //configure new message reception
  printf("Waiting for a SMS...\n");
}

void loop() {

  if (Serial.read() == '+') {
	byte i=0;
    while(Serial.available()>0) {
      delay(1);
      SMS[i] = Serial.read();
      i++;
    }
    byte z = 47;
    while (char(SMS[z]) != '\n') {
      morseChar(SMS[z]);
      z++;
    }
    printf("SMS received: %s\n", SMS);
  }

}

void morseChar(char character) {
  if (character >= 'a') character = character - 'a' + 'A';
  switch (character) {
    case 'A':
      dot();
      elemPause();
      dash();
      space();
      break;
    case 'B':
      dash();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      space();
      break;
    case 'C':
      dash();
      elemPause();
      dot();
      elemPause();
      dash();
      elemPause();
      dot();
      space();
      break;
    case 'D':
      dash();
      elemPause();
      dash();
      elemPause();
      dot();
      space();
      break;
    case 'E':
      dot();
      break;
    case 'F':
      dot();
      elemPause();
      dot();
      elemPause();
      dash();
      elemPause();
      dot();
      space();
      break;
    case 'G':
      dash();
      elemPause();
      dash();
      elemPause();
      dot();
      space();
      break;
    case 'H':
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      space();
      break;
    case 'I':
      dot();
      elemPause();
      dot();
      space();
      break;
    case 'J':
      dot();
      elemPause();
      dash();
      elemPause();
      dash();
      elemPause();
      dash();
      space();
      break;
    case 'K':
      dash();
      elemPause();
      dot();
      elemPause();
      dash();
      space();
      break;
    case 'L':
      dot();
      elemPause();
      dash();
      elemPause();
      dot();
      elemPause();
      dot();
      space();
      break;
    case 'M':
      dash();
      elemPause();
      dash();
      break;
      space();
    case 'N':
      dash();
      elemPause();
      dot();
      space();
      break;
    case 'O':
      dash();
      elemPause();
      dash();
      elemPause();
      dash();
      space();
      break;
    case 'P':
      dot();
      elemPause();
      dash();
      elemPause();
      dash();
      elemPause();
      dot();
      space();
      break;
    case 'Q':
      dash();
      elemPause();
      dash();
      elemPause();
      dot();
      elemPause();
      dash();
      space();
      break;
    case 'R':
      dot();
      elemPause();
      dash();
      elemPause();
      dot();
      space();
      break;
    case 'S':
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      space();
      break;
    case 'T':
      dash();
      break;
    case 'U':
      dot();
      elemPause();
      dot();
      elemPause();
      dash();
      space();
      break;
    case 'V':
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dash();
      space();
      break;
    case 'W':
      dot();
      elemPause();
      dash();
      elemPause();
      dash();
      space();
      break;
    case 'X':
      dash();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dash();
      space();
      break;
    case 'Y':
      dash();
      elemPause();
      dot();
      elemPause();
      dash();
      elemPause();
      dash();
      space();
      break;
    case 'Z':
      dash();
      elemPause();
      dash();
      elemPause();
      dot();
      elemPause();
      dot();
      space();
      break;
    case ' '://word pause
      wordPause();
      break;
    case '0':
      dash();
      elemPause();
      dash();
      elemPause();
      dash();
      elemPause();
      dash();
      elemPause();
      dash();
      space();
      break;
    case '1':
      dot();
      elemPause();
      dash();
      elemPause();
      dash();
      elemPause();
      dash();
      elemPause();
      dash();
      space();
      break;
    case '2':
      dot();
      elemPause();
      dot();
      elemPause();
      dash();
      elemPause();
      dash();
      elemPause();
      dash();
      space();
      break;
    case '3':
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dash();
      elemPause();
      dash();
      space();
      break;
    case '4':
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dash();
      space();
      break;
    case '5':
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      space();
      break;
    case '6':
      dash();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      space();
      break;
    case '7':
      dash();
      elemPause();
      dash();
      elemPause();
      dot();
      elemPause();
      dot();
      elemPause();
      dot();
      space();
      break;
    case '8':
      dash();
      elemPause();
      dash();
      elemPause();
      dash();
      elemPause();
      dot();
      elemPause();
      dot();
      space();
      break;
    case '9':
      dash();
      elemPause();
      dash();
      elemPause();
      dash();
      elemPause();
      dash();
      elemPause();
      dot();
      space();
      break;

  }
}

void power_on() {

  uint8_t answer = 0;

  // checks if the module is started
  answer = sendATcommand("AT", "OK", 2000);
  if (answer == 0)
  {
    // power on pulse
    digitalWrite(onModulePin, HIGH);
    delay(3000);
    digitalWrite(onModulePin, LOW);

    // waits for an answer from the module
    while (answer == 0) {   // Send AT every two seconds and wait for the answer
      answer = sendATcommand("AT", "OK", 2000);
    }
  }

}

int8_t sendATcommand(const char* ATcommand, const char* expected_answer, unsigned int timeout) {

  uint8_t x = 0,  answer = 0;
  char response[100];
  unsigned long previous;

  memset(response, '\0', 100);    // Initialice the string

  delay(100);

  //while ( Serial.available() > 0) Serial.read();   // Clean the input buffer

  Serial.println(ATcommand);    // Send the AT command


  x = 0;
  previous = millis();

  // this loop waits for the answer
  do {
    // if there are data in the UART input buffer, reads it and checks for the asnwer
    if (Serial.available() != 0) {
      response[x] = Serial.read();
      printf("%c", response[x]);
      x++;
      // check if the desired answer is in the response of the module
      if (strstr(response, expected_answer) != NULL)
      {
		printf("\n");
        answer = 1;
      }
    }
    // Waits for the asnwer with time out
  } while ((answer == 0) && ((millis() - previous) < timeout));

  return answer;
}


void dot()
{
  digitalWrite(BUZZER, LOW);
  delay(150);
  digitalWrite(BUZZER, HIGH);
}
void dash()
{
  digitalWrite(BUZZER, LOW);
  delay(450);
  digitalWrite(BUZZER, HIGH);
}
void elemPause()
{
  delay(150);  
}
void space()
{
  delay(450);  
}
void wordPause()
{
  delay(750);  
}


int main (){
	setup();
	while(1){
		loop();
	}
	return (0);
}

        

Intel Galileo:

Code:
/*  
 *  GPRS/GSM Quadband Module (SIM900)
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Jorge Casanova, Luis Martin
 */
 
#include <Morse.h>

Morse morse(9);

int8_t answer;
int x;
int onModulePin = 2;
char SMS[200];
char character;

void setup() {

  pinMode(9, OUTPUT);
  pinMode(onModulePin, OUTPUT);
  Serial.begin(115200);
  Serial1.begin(115200);

  Serial.println("Starting...");
  power_on();
  digitalWrite(9, HIGH);
  delay(3000);
  memset(SMS, 0, sizeof(SMS));

  Serial.println("Setting SMS mode...");
  sendATcommand("AT+CMGF=1", "OK", 1000);    // sets the SMS mode to text
  delay(500);
  sendATcommand("AT+CNMI=3,2,0,0", "OK", 1000); //configure new message reception
}

void loop() {

  if (Serial1.read() == '+') {

    for (byte i = 0; i < 200; i++) {
      delay(1);
      SMS[i] = Serial1.read();
    }
    byte z = 47;
    while (char(SMS[z]) != '\n') {
      Serial.print(SMS[z]);
      morseChar(SMS[z]);
      z++;
    }
  }

}

void morseChar(char character) {

  if (character >= 'a') character = character - 'a' + 'A';
  switch (character) {
    case 'A':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'B':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'C':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'D':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'E':
      morse.dot();
      break;
    case 'F':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'G':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'H':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'I':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'J':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'K':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'L':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'M':
      morse.dash();
      morse.elemPause();
      morse.dash();
      break;
      morse.space();
    case 'N':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'O':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'P':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'Q':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'R':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'S':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case 'T':
      morse.dash();
      break;
    case 'U':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'V':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'W':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'X':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'Y':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case 'Z':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case ' '://word pause
      morse.wordPause();
      break;
    case '0':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case '1':
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case '2':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case '3':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case '4':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dash();
      morse.space();
      break;
    case '5':
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case '6':
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case '7':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case '8':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;
    case '9':
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dash();
      morse.elemPause();
      morse.dot();
      morse.space();
      break;

  }
}

void power_on() {

  uint8_t answer = 0;

  // checks if the module is started
  answer = sendATcommand("AT", "OK", 2000);
  if (answer == 0)
  {
    // power on pulse
    digitalWrite(onModulePin, HIGH);
    delay(3000);
    digitalWrite(onModulePin, LOW);

    // waits for an answer from the module
    while (answer == 0) {   // Send AT every two seconds and wait for the answer
      answer = sendATcommand("AT", "OK", 2000);
    }
  }

}

int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout) {

  uint8_t x = 0,  answer = 0;
  char response[100];
  unsigned long previous;

  memset(response, '\0', 100);    // Initialice the string

  delay(100);

  while ( Serial1.available() > 0) Serial1.read();   // Clean the input buffer

  Serial1.println(ATcommand);    // Send the AT command


  x = 0;
  previous = millis();

  // this loop waits for the answer
  do {
    // if there are data in the UART input buffer, reads it and checks for the asnwer
    if (Serial1.available() != 0) {
      response[x] = Serial1.read();
      x++;
      // check if the desired answer is in the response of the module
      if (strstr(response, expected_answer) != NULL)
      {
        answer = 1;
      }
    }
    // Waits for the asnwer with time out
  } while ((answer == 0) && ((millis() - previous) < timeout));

  return answer;
}
        

Links and Documentation

Related Tutorials

Datasheets and Manuals



If you are interested in Internet of Things (IoT) or M2M projects check our open source sensor platform Waspmote which counts with more than 100 sensors available to use 'off the shelf', a complete API with hundreds of ready to use codes and a low consumption mode of just 0.7µA to ensure years of battery life.

Know more at:

Get the Starter Kits at: