Okay, here goes (I was just thinking if anyone had come across the same issue).
The thing is this: Using 1.8.5 with this code doesn't send the message. It does connect to the SIM card shield, and the SIM card finds the network, but this code works only if compiled in an early version of the IDE. Please ignore the comments in Finnish, or, learn Finnish with the code.
The piezo horn is used only to confirm the switch going down. This code does send the message.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
const int mySwitch = 6; // Muuttumaton muuttuja mySwitch on kytkennässä 6
int piezoPin = 7; // Muuttuja pilli on kytkennässä 7
// Määritellään muuttujan mySwitchDown arvoksi false
boolean mySwitchDown = 0;
boolean lastState = 0;
void setup()
{
//Sammutetaan ledi
digitalWrite(LED_BUILTIN, LOW);
// Pinni joka määritelty kytkimeksi on input pinni
pinMode(mySwitch, INPUT);
// Sisäinen ledi on yksi output pinni
pinMode(LED_BUILTIN, OUTPUT);
// määritellään mySwitch pinniin HIGH eli 5 volttia
digitalWrite(mySwitch, HIGH);
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
}
void loop()
{
mySwitchDown = digitalRead(mySwitch);
if (mySwitchDown != lastState) {
if (mySwitchDown==LOW) {
// Viive seuraavaan loopin alkuun
delay(100);
// Arduinon sisäinen led syttyy
digitalWrite(LED_BUILTIN, HIGH);
// Pilli, hertsit(äänenkorkeus), viive
tone(piezoPin, 1000, 500);
// Viive, johon lisätään pillille annettu viive
delay(1500);
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+358505018555\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
// Jos mySwitchDown ei toteudu
} else {
//Arduinon sisäinen ledi sammuu
digitalWrite(LED_BUILTIN, LOW);
}
} else {
delay(100);
}
lastState = mySwitchDown;
}
void RecieveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
}