Introduction
In this project, we are going to build a Raspberry Pi Pico Home Automation System Using GSM SIM800 We will be able to control our home appliances using SMS.
The system allows users to control various devices in their homes using a mobile phone. The text provides instructions on how to set up the system and how to use it.
Required Material
What is Raspberry Pi Pico?
Raspberry Pi Pico is a low-cost, high-performance microcontroller board with a Cortex M0+ chip & flexible digital interface. It was launched in January 2021. The Pico has a USB 2.0 port and can be programmed in C/C++, MicroPython language. it is designed for use in a wide range of applications, including sensor interfacing, and interactive control. Getting Started Raspberry Pi Pico – Pinout, Specs – Beginner Guide
The GSM SIM800L Module
The GSM SIM800L Module is an affordable and powerful GSM model. It supports the GSM/GPRS 900/1800MHz frequency and this module can be used in a wide variety of applications including cellular data communication and SMS. I suggest you read Interface SIM800L with Arduino Tutorial – How It Works, Codes
This module is small and easy to use, and it provides your project with the ability to connect to a cellular network. The SIM800L module supports both voice and data, and it can be used with a variety of different GSM networks.
When you power up this module with a power supply of 3.8v–4.2v Volts the LED present on the board will start blinking. If the blinking is really fast that means SIM is not registered to a network. If there is steady/slow blinking, it means SIM has successfully logged in to a network.
Note- Make sure your power supply is at least 2A because this module consumes lots of energy.
The Home Automation System
A home automation system is a control system for a home, generally applying electrical and electronic devices, that enable a homeowner to remotely control and automate tasks in the home. the home automation system is a fantastic way to make your home more comfortable, safe and energy efficient. It can also help you save money on your utility bills.
Circuit diagram – Raspberry Pi Pico Home Automation with GSM 800
S.N. | Raspberry Pi Pico | SIM800L |
1. | 3.3V from Battery. | VCC |
2. | GND | GND |
3. | GP5 | TXD |
4. | GP6 | RXD |
Project PCB Gerber File & PCB Ordering Online
If you can not manually connect the wires, then here is a printed circuit board (PCB Board) for you. I used EasyEDA to design the PCB. The PCB Board for Robotic Car looks something like below.
The Gerber File for the PCB is provided below. You can just download the Gerber File and order the PCB from https://www.nextpcb.com/
Download Gerber File:Â Raspberry Pi Pico W Home Automation
Please visit their website and get exciting discounts and coupons, and more.
- Only 0$ for 5-10pcs PCB Prototypes:Nextpcb.com/pcbprototype
- Register and get $100 from NextPCB:Â Nextpcb.com/coupon
Why NextPCB
- Most Efficient, Economic, Inventive PCB Solutions
- Higher Quality
- Lower Price
- Faster Delivery
Micropython Code – Raspberry Pi Pico Home Automation System Using GSM SIM800
This Micropython code is used to control the Raspberry Pi Pico home automation system using the GSM SIM800 module. This system lets you control your home from anywhere in the world using your mobile phone or tablet.  Getting Started With Raspberry Pi Pico With Thonny IDE
Main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
from machine import UART, Pin gsm_module = UART(1, baudrate=9600, tx=Pin(5), rx=Pin(4), timeout=2000) gsm_buffer = '' destination_phone = '+916209403151' relay1 = Pin(19, Pin.OUT) relay2 = Pin(20, Pin.OUT) def convert_to_string(buf): tt = buf.decode('utf-8').strip() return tt def do_action(msg): msg = msg.lower() if(msg.strip() == 'light off'): relay1(0) send_sms('light is OFF') elif(msg.strip() == "light on"): relay1(1) send_sms('light is ON') elif(msg.strip() == 'fan off'): relay2(0) send_sms('fan is OFF') elif(msg.strip() == 'fan on'): print('do_action1: '+msg) relay2(1) send_sms('fan is ON') def send_command(cmdstr, lines=1, msgtext=None): global gsm_buffer print(cmdstr) cmdstr = cmdstr+'\r\n' while gsm_module.any(): gsm_module.read() gsm_module.write(cmdstr) if msgtext: print(msgtext) gsm_module.write(msgtext) buf=gsm_module.readline() buf=gsm_module.readline() if not buf: return None result = convert_to_string(buf) if lines>1: gsm_buffer = '' for i in range(lines-1): buf=gsm_module.readline() if not buf: return result buf = convert_to_string(buf) if not buf == '' and not buf == 'OK': gsm_buffer += buf+'\n' return result def read_sms(sms_id): result = send_command('AT+CMGR={}\n'.format(sms_id),99) print(result) if result: params=result.split(',') if params[0] == '': return None params2 = params[0].split(':') if not params2[0]=='+CMGR': return None number = params[1].replace('"',' ').strip() date = params[3].replace('"',' ').strip() time = params[4].replace('"',' ').strip() #print('gsm_buffer:'+gsm_buffer) return [number,date,time,gsm_buffer] def send_sms(msgtext): global gsm_buffer result = send_command('AT+CMGS="{}"\n'.format(destination_phone),99,msgtext+'\x1A') if result and result=='>' and gsm_buffer: params = gsm_buffer.split(':') if params[0]=='+CUSD' or params[0] == '+CMGS': print('OK') return 'OK' print('ERROR') return 'ERROR' print(send_command('AT')) print(send_command('AT+CMGF=1')) print(send_command('AT+CNMI=1')) while True: if gsm_module.any(): buf=gsm_module.readline() buf = convert_to_string(buf) print(buf) params=buf.split(',') if params[0][0:5] == "+CMTI": msgid = int(params[1]) msg_data = read_sms(msgid) if not msg_data: print("No sms data found.") break print(msg_data[3]) if not msg_data[0] == destination_phone: print("Destination phone pumber not matching") break do_action(msg_data[3]) |
Conclusion
In ending, the Raspberry Pi Pico home automation system is an excellent way to automate your house. It is easy to set up and use and is very affordable. The GSM SIM800L is a great addition to the method and allows you to control your system remotely.