Skip navigation

Arduino

8 Posts authored by: markvenn
markvenn

SMS to light an LED!

Posted by markvenn Apr 7, 2015

Hi

I have been playing with my Uno and GSM shield to try to see if I can get the real world to react to a good old fashioned SMS text. In these days of 3G and 4G data rates, I wanted to show that we don't have to have the latest toys to interact with the real world.

So, to start I am using a common cathode RGB LED with a first gen Uno with an R3 GSM shield wired up as below.

sms_rgb_bb.jpg

(Please imagine an Uno underneath this shield :-))

So, the idea is to react to the contents of an incoming text message and light the LED with the colour that is sent to the Arduino. (A this point the choice is red, green or blue).

 

At the moment I am working on IF statements to check the contents of the message as it arrives but I am probably going to change this to either a case statement or with the message passed as a parameter into a new function. Anyway, the code as it stands at the moment:

 

/*

This sketch, for the Arduino GSM shield, waits for a SMS message
and displays it through the Serial port. Then returns message to sender
letting them know it has been received on Arduino.
dependent on the message certain colours will be displayed by led

Circuit:
* GSM shield attached to and Arduino
* SIM card that can receive SMS messages
* common cathode rgb led

created 7 Apr 2015
based on code by Javier Zorzano / TD & Tom Igoe

*/

// include the GSM library
#include <GSM.h>

// PIN Number for the SIM (set if sim pin code protected)
#define PINNUMBER ""

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char senderNumber[20];
char outGoing[16];

// variables to define pins to be set for each colour
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
// define String variable to hold incoming message
String message;

void setup()
{
  // configure pins to connect to led
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  setColour(0, 0, 0); // initialise led to off

  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  // configure and initialise GSM connection
  Serial.println("SMS Messages Receiver");

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while (notConnected)
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop()
{
  char c;

  // If there are any SMSs available()
  if (sms.available())
  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // Read message bytes and print them
    while (c = sms.read())
      message += c; // build the message from the sms.read() function

    //Serial.print(c);
    Serial.println(message); // display message on serial for testing
    message.toLowerCase(); // convert to lower case to make sure the comparision works later

    Serial.println("\nEND OF MESSAGE");

    /* read the contents of message variable. see if it is blue, green or red
     light appropriate colour on LED and send message back to let sender know
     that the message has been received.
     */
    if (message == "blue")
    {
      Serial.println("received message to set BLUE");
      Serial.println("\nSENDING REPLY");
      sms.beginSMS(senderNumber);
      sms.print("SET LED TO BLUE. (Message was blue");
      sms.endSMS();
      Serial.println("\nCOMPLETE");
      setColour(0, 0, 255);
      message = "";
    }

    if (message == "green")
    {
      Serial.println("received message to set GREEN");
      Serial.println("\nSENDING REPLY");
      sms.beginSMS(senderNumber);
      sms.print("SET LED TO GREEN.");
      sms.endSMS();
      Serial.println("\nCOMPLETE");
      setColour(0, 255, 0);
      message = "";
    }

    if (message == "red")
    {
      Serial.println("received message to set RED");
      Serial.println("\nSENDING REPLY");
      sms.beginSMS(senderNumber);
      sms.print("SET LED TO RED.");
      sms.endSMS();
      Serial.println("\nCOMPLETE");
      setColour(255, 0, 0);
      message = "";
    }



    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  delay(1000);

}
/* function that sets colour
takes three values to set the levels of each colour. Can be set as hex values by
prefixing with 0x. For example 0x03 = decimal 3, 0x0d = decimal 13
*/
void setColour(int red, int green, int blue)
{

  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}

 

So, there you go, a good old fashioned text message that says red, (or ReD due to the toLowerCase() function), will light the led a nice red colour. I will make some changes to the code, it comes in at 17,056 bytes of program storage space with 1,196 bytes of global variables so I thank that I want to tweak it a bit to see how efficient I can make it.

 

Shopping list

=========

 

Arduino GSM ShieldArduino GSM Shield

RGB LED (such as Kingbright L154A4SURKQBDZGWRGB LED (such as Kingbright L154A4SURKQBDZGW

Arduino UnoArduino Uno

And the winner was...

20150328_161248.jpg

Craig Terris. Here is is receiving his Arduino starter kit from Zac Colley, very kindly supplied by Element14! We drew the name from a hat, an actual hat; a room full of computer nerds and we fell back on good old tradition! Thanks odion

 

We had a brilliant day; we had a mum and her son who had the Ardunio for Christmas and had not got much further than blink, he had a go at a few of the projects in the starter kit book and had a good time. One of the strangest projects was "Party Face"; no pics unfortunately. This was an Uno with ethernet shield, (for the SD card capability), hooked up to a speaker and mounted in a cardboard mask. The guys worked extremely hard in getting the Uno to play a wav file stored on the sd card. The point? Well, as we all know, students like to party; when the partying gets too much, pop on the mask and have a sleep. The Uno then plays the messages stored on the SD card. We heard a lot of crackling to start then suddenly "Thanks for coming!" could be heard clearly. If there was more time I think the idea was to use ultra sonic detector to tell when someone approaches and the message plays to say, well whatever is programmed.

 

Roll over Apple, we have the coolest smart watch prototype here, Arduino style.

 

20150328_160754.jpg

As you can see, work in progress although we have working bluetooth connection and working displays. I am all for keeping it this size and having it strapped to the users forearm rather than making it smaller and watch-like but I am not sure how this will go. There is talk of making a custom PCB next although discussions were made about a 3d printed wrist mount.

 

We have python on Linux talking to and receiving from the serial output of the Mega, SMS powered RGB led with incoming messages changing the colour of the output and then sending back a text letting the sender know it had worked. But mostly people played and had fun; this was the whole point of the day. We will be setting up something else, hopefully on a regular basis, looking at names at the moment, Pompey Proto People seems likely!

 

So, that was it.

markvenn

Portsmouth Arduino Day

Posted by markvenn Mar 28, 2015

It's a great success so far with plenty of people turning up and with a nice mix of knowledge. We have some interesting projects on the go, will write these up soon.

here's some pictures!

20150328_140553.jpg

 

20150328_140559.jpg

 

20150328_140605.jpg

markvenn

Arduino Day 2015 - Portsmouth

Posted by markvenn Mar 28, 2015

Well, we are all set, waiting for the first people to arrive!

20150328_094415[2].jpg

markvenn

Arduino GSM Shield

Posted by markvenn Mar 27, 2015

I've been playing with the GSM shield and the sms functions. As some of you may remember a while ago I was having problems with my mega and the shield. paulellison helped me out considerably with identifying problems with the mega and the shield using different pins and also we found the power drain could be quite high during some functions. Anyway, I have been playing with some ideas, using incoming sms messages to trigger events and so far I have got the Uno I am using to receive a test and, depending on the first character of the text it will reply to the sender with an appropriate text message and, if the message starts with a '#' it will discard the text and let the sender know that this is what has happened.

 

This is going to be the starting code for something I am going to try to work on during our Arduino Day so I give you the basic code now and will let you see how it works tomorrow!

 

/*
 SMS receiver

 This sketch, for the Arduino GSM shield, waits for a SMS message
 and displays it through the Serial port. Then returns message to sender
 letting them know it has been received on Arduino

 Circuit:
 * GSM shield attached to and Arduino
 * SIM card that can receive SMS messages

 created 27 Mar 2015 by Mark Venn
 based on code by Javier Zorzano / TD & Tom Igoe


*/

// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER ""

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char senderNumber[20];


void setup()
{
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("SMS Messages Receiver / Responder");

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while (notConnected)
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop()
{
  char c;

  // If there are any SMSs available()
  if (sms.available())
  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal
    // Any messages starting with # should be discarded
    if (sms.peek() == '#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
      Serial.println("\nSENDING REPLY");
      sms.beginSMS(senderNumber);
      sms.print("Message discarded. (Began with #");
      sms.endSMS();
      Serial.println("\nCOMPLETE");
    }
    else if (sms.peek() == '@')
    {
      Serial.println("\nSENDING REPLY");
      sms.beginSMS(senderNumber);
      sms.print("Message began @");
      sms.endSMS();
      Serial.println("\nCOMPLETE");
    }
    else if (sms.peek() == ';')
    {
      Serial.println("\nSENDING REPLY");
      sms.beginSMS(senderNumber);
      sms.print("Message began ;");
      sms.endSMS();
      Serial.println("\nCOMPLETE");
    }
    else if (sms.peek() == '!')
    {
      Serial.println("\nSENDING REPLY");
      sms.beginSMS(senderNumber);
      sms.print("Message began !");
      sms.endSMS();
      Serial.println("\nCOMPLETE");
    }
    else


    // Read message bytes and print them
    while (c = sms.read())
      Serial.print(c);

    Serial.println("\nEND OF MESSAGE");

    // return message to sms sender
    
    sms.beginSMS(senderNumber);
    sms.print("Message Received!");
    sms.endSMS();
    Serial.println("\nCOMPLETE!\n");



    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  delay(1000);

}

 

I am thinking of trying case statements instead of the dreaded if else if else mess, this was just to try to get something working ready for tomorrow! We shall see how it goes! Going to have a good day I think, odion is going over with me, he is really getting in to Arduino and using python to do clever stuff depending on what is spat out of the serial port. Will get him to write something up sometime.

markvenn

Arduino Day 2015 - UK

Posted by markvenn Mar 17, 2015

Hi All

As you all know it is International Arduino Day on the 28th of March, only 11 days away. I expect some of you are attending or running events. A few of us, including pizak , who are working on various levels or education are running an event at the University of Portsmouth, Hampshire on the south coast of the UK, (not the one in the US, New Hampshire I think. I don't know, people leave England and then use the same names for so many places.... )

Anyway, I asked element14 if they were able to help us out with some gear for those people who want to come along and try out our beloved Arduino and they have been extremely helpful. We have 3 Arduino Starter Kits on the way!!! Arduino Starter Kit - Premier Farnell So, anyone who lives locally and wants to come along please look at our Eventbrite page and book your tickets! Arduino Day 2015: Portsmouth- Eventbrite

 

We are hoping to turn this into a regular event, although we are not sure of the name of the group that we are going to start to run these events. We want to be able to have people along who not only use Arduino but we will be opening up to all single board computers. I know that there are many people who, like me, use various Arduino boards, Beaglebone and RaspPi to do their work and I think we want to bring them in too, at a later date so they can help spread the word about how much fun can be had with a tiny computer, a few LEDs, a handful of wires, a motor and a bunch of friends!

 

We are going to be blogging throughout the day with info on the sort of things people are coming up with so look for updates!

markvenn

New Arduino Toys

Posted by markvenn Jan 21, 2015

I have some new toys to add to my arsenal of kit! Along with a Pi camera I received two nice little additions to my box of bits. I now have a Ethernet shield and a Yun. Not sure how to pronounce Yun; should it be similar to gun? Or maybe similar to spoon. Perhaps someone can enlighten me?

 

Anyway, here are my new babies!

Arduinos.jpg

I was surprised to find the comment that the ethernet shield is no longer manufactured on the packing list. Grab them while you can guys! The ethernet shield has storage capability with the micro sd slot which can be used to serve files on the network that your mega or uno is connecting to. The Yun also has a micro sd slot that performs the same function but It has wifi capability too. In fact, when you turn it on, the instructions say to connect via wireless to the new network that is now being broadcast. Sweet!

yun rear.jpg

This is the rear of the Yun, the sd slot is on the left; I am soooooo looking forward to using this baby, I have so many ideas for something that bridges Linux and Arduino.

ethernet rear.jpg

 

The Yun is a neat bit of kit, matching Arduino magic with a linux operating system, albeit a tiny system, OpenWRT

 

On the Arduino site there is an excellent page with some info on, have a look at Arduino - ArduinoYun I reckon that once you read this you will realise you need one! Yun on element14 can be found here: Yun

 

 

On a side note, I am looking forward to the Tre being widely available. How can anything with a background that  "is partially the result of a close collaboration between Arduino and the BeagleBoard.org foundation." (Arduino - ArduinoBoardTre) not be a lovely bit of kit?

I have been working with my Arduino Mega ADK and a nice little TO92 temp sensor, the TSIC 301. (Datasheet here) I have been playing with a very basic sketch, all it is doing at the moment is looping around "read value and display on serial"

const int IN_PIN = 0; // analogue input pin
const int DELAY = 1000; // a constant value for the delay.
int value = 0; // declare and initialise the variable for the value

void setup()
{
  Serial.begin(9600); // setup serial connection
}

void loop()
{
  value = analogRead(IN_PIN); // read the value of the sensor
  Serial.println(value); // display it in the serial monitor
  delay(DELAY); // wait 1 second then start the loop again although this can be altered easily
}

I am using this as the basis for a couple of ideas, one is to indicate high and low temperatures via LED display, maybe a "traffic light" systems that has different LEDs lit at certain temps or maybe a RGB LED would be best?(Suggestions please) Another idea is to tie this up with a stepper motor and use this sort of sketch to open and close a window in a greenhouse or similar.(All these ideas are being used as "proofs of concept" or should that be "proofs of concepts"?

I have been able to see the output value change from 78 in a normal run to 60 with an air duster blowing on it to 85 with a good  old fashioned "huff".I do not have a thermometer here to test the values, I will see if I can get hold of one to check.Apparently this can measure from -50C to +150C, (-58 to 302 to you Fahrenheit lovers :-) )

 

TO92 TSIC301 Temp Sensor_bb.png

The sensor in this Fritzing image is the correct form, TO-92, with the correct polarity with 1 being gnd, 3 being 3.0V to 5.5V and 2 being the actual sensor output.I am going to be using this sketch as the basis for a function, it is nice and small and won't take up a lot of memory.(4134 bytes)

Filter Blog

By date: By tag: