Yún – SMS alarm

luca 07/03/2015 0

This tutorial will explain a way to communicate between the sketch running on the ATMega and the Linino (Linux) OS running on the Yun’s SoC: the ability to execute Linux processes from a sketch.

I’m going to build a simple SMS alarm:

  • A microswitch is connected to the Arduino
  • when the microswitch is pressed, an SMS is sent using Skebby gateway

Linino side

A PHP script will send the message interacting with the Skebby SMS gateway.

To be able to run PHP scripts you have first to install some modules, with the command:

opkg install php5 php5-cli php5-mod-curl

The sendSMSAlert.php script, developed starting from some of the available examples, is available on my GitHub’s repository and must be saved in the /root folder (home directory for the root user).

You have to change some parameters in the sendSMS method: insert your Skebby account, the recipient and sender numbers and the text to be sent:

echo sendSMS("skebby_user", "skebby_password", 
 "391234567890", "391234567890", "Warning: door opened!", "0cent") . "\n";
All the phone numbers must start with the international prefix (for Italy, 39) and without + or 00 characters

Skebby offers different SMS types: the last parameter specifies which SMS have to be used. The available SMS types are listed at the top of the script:

define ("SMS_TYPE_0CENT", "0cent");
define ("SMS_TYPE_CLASSIC", "classic");
define ("SMS_TYPE_CLASSIC_PLUS", "classic_plus");
define ("SMS_TYPE_BASIC", "basic");

In the video I used the 0cent type, which is free but requires the Skebby app installed on the recipient’s phone (and the phone must be connected to the Internet too).

Arduino side

The Arduino sketch is too available on my repository.

I connected the microswitch this way:

  • the common PIN to Arduino’s PIN 2
  • the normally closed PIN to ground
  • the normally opened PIN to 5V

This means that when the microswitch is open, PIN 2 of Arduino is connected to the ground (LOW state), but when the microswitch is pressed, that PIN is connected to 5V (HIGH state). I also used PIN 13 (connected on a LED on the board) to display the status of the microswitch).

yun-alarm1 yun-alarm2

Both the two PINs can be changed using the constants at the beginning of the sketch:

#define SWITCH_PIN 2
#define LED_PIN 13

In the main loop() the sketch continuously checks the microswitch status: if it’s pressed, the sendAlert() method is invoked. I also store the previous status of the microswitch to be sure to send an SMS only when it changes from free to pressed.

The sendAlert() method uses a functionality of the Bridge library: the ability to run a command/script on the Linino side:

void sendAlert() {
  Process p;            

It calls the PHP interpreter (php-cli) to run the sendSMSAlert.php script that was previously saved in the root’s home directory.


In this tutorial I showed you a first example of how to interact between a sketch and Linino… in the next ones I’m going to show you how to do the opposite (Linino -> sketch) and how to pass values between them,

Leave A Response »

This website uses cookies to ensure you get the best experience on our website maggiori informazioni

Questo sito utilizza i cookie per fonire la migliore esperienza di navigazione possibile. Continuando a utilizzare questo sito senza modificare le impostazioni dei cookie o clicchi su "Accetta" permetti al loro utilizzo.