Now that the sensing circuits been built, there needs to be a way of receiving the results. That's where the GSM module comes in. We're going to use it to send the results over the cellular network in an SMS, once a day.

The GSM module communicates with the Raspberry Pi via serial using UART. Here's some great info on serial communication with the Raspberry Pi. In order to take control of the Pi's serial port we need to do some configuration first.

Boot up your Raspberry Pi with a a standard Raspbian Image. Now change the file "/boot/cmdline.txt" from:

"dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait"

to:

"dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait"

by removing the underlined section of text.

Secondly, you need to edit the file "/etc/inittab", by commenting out the second line in the following section:

#Spawn a getty on Raspberry Pi serial line

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100"

So that it reads:

"#Spawn a getty on Raspberry Pi serial line

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100"

and reboot the Pi. Now the serial port should be free to communicate with as you wish. It's time to wire up the GSM module. Take a look at the circuit diagram in the previous step and the pictures above to see how this is done. Basically, TX is connected to RX and RX is connected to TX. On the Raspberry Pi TX and RX are GPIO 14 and 15 respectively.

Now, you probably want to check that module is working, so lets try to send a text! For this you need to download Minicom. It's a program that allows you to write to the serial port. Use:

"sudo apt-get install minicom"

Once it's been installed minicom can be opened with the following command:

"minicom -b 9600 -o -D /dev/ttyAMA0"

9600 is the baud-rate and /dev/ttyAMA0 is the name of the Pi's serial port. This will open a terminal emulator in which whatever you write will appear on the serial port, i.e. be sent to the GSM module.

Insert your topped up sim card into the GSM module and press the power button. After which a blue led should come on. The GSM module uses the AT command set, here's the documentation if you're really interested. Now we check that Raspberry Pi has detected the module with the following command:

"AT"

the module should then respond with:

"OK"

Great! Then we need to configure the module to send an SMS as text rather than binary:

"AT+CMGF = 1"

again the response should be "OK". Now we write the command to send an SMS:

"AT+CMGS= "44************* "", replace the stars with your number.

The modem with respond with ">" after which you can write you message. To send the message press <CTRL-Z> . That's it, and with any luck you've just received a text straight from the your Raspberry Pi.

Well now that we know the GSM module is working you can close minicom; we wont need it for the rest of the project.