This is a Python scipt that controls an AC/DC relay attached to a Raspberry Pi with a space heater plugged in. There is an adafruit GSM Board that receives text messages using a Ting SIM card connected to the Raspberry Pi. When the Pi receives a text messgae it will turn the AC/DC relay on or off accordingly, thus powering the heater on or off. The following are a list of commands that can be sent to the Pi that will control the heater.
In addition to the original heater control that this code performed, it has been extended and modified in a number of ways.
- Allow extensibility to add more features.
- Gas sensor is now sent through an analog converter so the exact gas level can be known.
- The gas sensor has a trigger level, and a lower "all clear" level so the alert will keep firing until the issue is addressed, but not spam your phone.
- The gas sensor will alert you to gas anytime it is detected, not just when the heater is being operated.
- A light sensor has been added so you can tell if you left the lights on.
- A temperature sensor has been added so you know if you need to turn on the heater.
- A LCD was added so you can position the unit and know what the signal quality is.
- Enhanced the "STATUS" command to give you a full rundown of all the sensor data.
This version was based on the piWarmer by Maria DeGrazia. https://github.com/mdegrazia/piWarmer
I want to extend my many thanks to Maria for starting such an amazing project!
The light sensor code is from "arenadorn" and tsl2591
The temperature, and gas sensor code is heavily based on the SunFounder sample code.
HangarBuddy is to be used at your own risk This version of the code has been modified to increase the reliability and safety of the device, but it is an experimental device.
The commands are not case sensitive.
SMS Message | Action |
---|---|
ON | Turn the Relay/Heater on |
OFF | Turn the Relay/Heater off |
STATUS | Return status of the Relay/Heater (on or off) |
HELP | Return the list of commands. |
SHUTDOWN | Shutdown the Pi |
You will need to modify the HangarBuddy.config file to match your installation. This file includes a list of phone numbers that are authorized to issue commands. The file also includes a phone number that any alerts will be sent to.
For a complete set of installation instructions, visit https://github.com/mdegrazia/piWarmer/wiki.
Note: GPIO25 is physical pin 22
- Red wire from GPIO25 to Relay "+"
- Black wire from Relay "-" to GPIO GND
- TTL Black to Fona "GND"
- TTL White to Fona "TX"
- TTL Green to Fona "RX"
- TTL Red to Fona "Vio"
- USB to Pi USB
- ORANGE Fona PS to GPIO23
- YELLOW Fona Key to GPIO GND
- GREEN Fona RI to GPIO24
- USB power into the Fona mini-USB port
Note:GPIO23 is physical pin 16 Note:GPIO24 is physical pin 18
- Red F/M: VCC to GPIO 3V3
- Black ADC GND to GPIO GND
- White ADC SDA to GPIO SDAI
- Gray ADC SCL to GPIO SCLI
- White F/F ADC AIN0 to MQ2 White
- Pigtail Connector into reciever
- Red to GPIO 3V3
- Black to GPIO GND
- Brown NOT USED
- White plug into Temp Sensor
- Yellow to GPIO04
- Red to +5VO
- Black to GPIO GND
NOTE: If you have the IO hat installed on the Pi, then you can use the duplicate SDA/SLC connectors on the set screw side AND the connector pin side.
- VCC (Red) to GPIO 3.3V
- GND (Black) to GPIO Ground
- SDA (White) to GPIO SDA
- SLC (Gray) to GPIO SLC
You may need to make to "Y" pig tails to support the additional i2c device.
While the Raspberry Pi can support a number of i2c devices, and all of the devices used are at different offsets, even with the IO hat, there are only connectors for two devices.
If you intend on using ALL THREE i2c devices (Gas Sensor, Light Sensor, and LCD) then a splitter for the SDAI and SCLI lines will need to be made.
If you intend to use two or fewer, then no work needs to be done, and any free SDA/SCL pins may be used.
- Red wire from LCD VCC to GPIO 5V
- Black wire from LCD GND to GPIO GND
- White wire from LCD SDA to GPIO SDA
- Gray wire from LCD SCL to GPIO SCL
To do this, you need to enable I2C and 1-Wire using raspi-config
sudo raspi-config
- Select Option 5
Interfacing Options
- Select Option
P5 I2C
and enable - Select Option
P7 1-Wire
and enable - Save changes, exit
raspi-config
and reboot your Raspberry Pi
Modprobe two modules for the temperature sensor:
sudo modprobe w1-gpio
sudo modprobe w1-therm
All the parts listed are from Amazon
This assumes you are building "from scratch" and need to buy a Raspberry Pi and associate parts. I have picked a version of the Pi Zero that has Wireless, which is good if you want to pull the code down directly onto the Pi
Any version of the Raspberry Pi should work for this project as long as it has GPIO pins, and an I2C bus.
The LiPo battery is absolutely required and used directly by the GSM board.
A MicroUSB to USB adapter is required for the modem to connect into the Pi Zero's only USB port.
- Raspberry Pi W, case, and IO pins
- Adafruit GSM board, SMA edition
- Adafruit 1S Lipo W/ JST connector
- MicroUSB to USB adapter
- USB to TTL/Serial adapter
- Ting GSM Sim Card
- Iot Power Relay
- Experimentation board with wires
You will need an antenna, and two options have been tried. One is a small antenna that will work if the device is near a window or your hangar has good reception. The 7dbi (high gain) antenna option should be used if reception is an issue
The Raspberry Pi zero uses a mini HDMI port for display. If you do not have an adapter, you will need one. This is not required in the installation once the device is "deployed". The USB hub makes coding and debugging on the PI possible as it allows a keyboard, mouse, and the Fona modem to be connected simultanously. When the HangarBuddy is "deployed" only the Fona will be plugged into the USB port.
https://tutorials-raspberrypi.com/configure-and-read-out-the-raspberry-pi-gas-sensor-mq-x/ http://www.learningaboutelectronics.com/Articles/MQ-2-smoke-sensor-circuit-with-raspberry-pi.php
https://learn.adafruit.com/adafruit-fona-808-cellular-plus-gps-breakout?view=all https://learn.adafruit.com/adafruit-fona-mini-gsm-gprs-cellular-phone-module?view=all https://learn.adafruit.com/adafruit-fona-mini-gsm-gprs-cellular-phone-module/handy-commands https://cdn-learn.adafruit.com/downloads/pdf/adafruit-fona-mini-gsm-gprs-cellular-phone-module.pdf
- Log in to your rasperry pi as the
pi
user. mkdir src
cd src
git clone https://github.com/JohnMarzulli/piWarmer/
cd piWarmer
sudo cp piWarmer.logrotate.conf /etc/logrotate.d/
sudo chown root root /etc/logrotate.d/piWarmer.logrotate.conf
sudo cp piWarmer.service /etc/systemd/system/
sudo chown root root /etc/systemd/system/piWarmer.service
sudo systemctl enable piWarmer.service
sudo reboot
Once you reboot, the piWarmer service should be started automatically. You can view any startup errors for the service in /var/log/syslog
.