spurred on by the completion of my two previous projects, the Compact Camera and Portable Games Console, I wanted to find a new challenge. The natural progression was an outdoor remote systemā¦
I wanted to build a Raspberry Pi weather station that was able to sustain itself off grid and send me the results through a wireless connection, from anywhere! This project really has had its challenges, but luckily powering the Raspberry Pi is one of the main challenges that has been made easy by using the PiJuice as a power supply with itās added solar support.
My Initial thought was to use the fantastic AirPi module to take readings. This however, had two main drawbacks; it requires a direct internet connection to upload the results and it needs to be connected directly to the GPIO on the Pi which means it canāt be exposed to the air without also exposing the Raspberry Pi (not ideal if we want this weather station to last any length of time).
The solutionā¦ build my own sensing module! Using much of the AirPi for inspiration I was able to put together a very simple prototype using a few sensor I already had; temperature, humidity, light levels and general gases. And the great thing about this is that itās really easy to add more sensors at anytime.
I decided to use a Raspberry Pi a+ mainly due to its low power consumption. To send me the results I used the EFCom Pro GPRS/GSM module, which can send a text straight to my mobile phone with the results! Pretty neat right?
Iām glad to here of any ideas you have for other great solar or portable projects. Let me know in the comments and Iāll do my best to create a tutoria
Step 1: Parts
1 x Raspberry Pi a+
1 x Sim Card
1 x Bread Board
1 x MCP3008 ADC
1 x LDR
1 x LM35 (Temperature Sensor)
1 x DHT22 (Humidity Sensor)
1 x TGS2600 General Air Quality sensor
1 x 2.2 KĪ© Resistor
1 x 22 KĪ© Resistor
1 x 10 KĪ© Resistor
10 x Female ā Female Jumper wires
Assortment of single gauge wire
1 x Single Outdoor Junction Box
1 x Double Outdoor Junction Box
1 x Waterproof Cable Connector
2 x 20mm Semi Blind Cable Grommets
Step 2: Sensing circuit
Thereās quite a few different elements to this project, so itās best to do everything in steps. First off Iām going to go through how to put together the sensing circuit.
Itās a good idea to build this on a bread board first, just in case you make any mistakes, I have included a circuit diagram and step by step pictures, to be referred to.
- The first component to get wired up is this MCP3008 analogue to digital converter. This can take up to 8 analogue inputs and communicates with the Raspberry Pi via SPI. With the chip facing up, and the semi-circle cut away on the end furthest from you, the pins on the right all connect to the Raspberry Pi. Connect them up as shown. If youād like to learn a little more about how the chip works hereās a great guide to the MCP3008 and the SPI protocol.
- The pins on the left are the 8 Analogue inputs, numbered 0-7 from top down. We will only use the first 3 (CH0,CH1,CH2), for the LDR, the general gas sensor (TGS2600) and the temperature sensor (LM35). First connect the the LDR as shown in the diagram. One side to ground and the other to 3.3V via a 2.2KĪ© resistor and CH0.
- Next, connect the āgeneral gas sensorā. This gas sensor is used for detection of air contaminants such as hydrogen and carbon monoxide. I havenāt yet worked out how to get specific concentrations, so for now the result from this sensor is a basic percentage level, where 100% is fully saturated. With the sensor facing up (pins on the underside), the pin directly to the right of the small outcrop is pin 1 and then the numbers increase clockwise around the pin. So pins 1 and 2 connect to 5V, pin 3 connects to CH1 and ground via a 22KĪ© resistor and pin4 connects straight to ground.
- The final analogue sensor to connect is the LM35 temperature sensor. This has 3 pins. Take the sensor so the flat side is closest to you, the left most pin connects straight to 5V (not marked on diagram, my bad!), the centre pin connects to CH2 and the right most pin connects straight to ground. Easy!
- The last component to connect is DHT22 humidity sensor. This is a digital sensor so can be connected straight to the Raspberry Pi. Take the sensor with the grid facing you and the four pins on the underside. Pins are ordered from 1 on the left. Connect 1 to 3.3V. Pin 2 goes to GPIO4 and 3.3V via a 10KĪ© resistor. Leave pin 3 disconnected and pin 4 goes straight to ground.
Thatās it! The test circuitās been built. Iām hoping to add more components when I have the time. Iād really like to add a pressure sensor, a wind speed sensor and Iād like to get more intelligent data on gas concentrations.
Step 3: GSM module
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.
For More Detail : Raspberry Pi Solar Weather Station