FUSION AUTOMATE
Published © GPL3+

Send SMS using Raspberry Pi Pico W and A9G Board

How to Send SMS from A9G Board by Sending AT Commands from Raspberry Pi Pico W using MicroPython Programming

IntermediateProtip1 hour51
Send SMS using Raspberry Pi Pico W and A9G Board

Things used in this project

Hardware components

Raspberry Pi Pico W
Raspberry Pi Pico W
×1

Software apps and online services

MicroPython
MicroPython

Story

Read more

Schematics

connection diagram

Code

main.py

Python
# Import required libraries
import machine
import time

# Configure UART for communication with the A9G module
uart = machine.UART(0, baudrate=115200, tx=machine.Pin(0), rx=machine.Pin(1)) # UART0 on Pico

# Function to send AT commands and receive responses
def send_at_command(command):
    uart.write(command + '\r\n')       # Send the command
    time.sleep(3)                       # Wait for response
    response = uart.read()              # Read the response
    if response:
        print("Response:", response.strip())  # Print the response
        return response.strip()
    else:
        print("No response received.")  # Print if no response received
        return None

# Function to send an SMS
def send_sms(phone_number, message):
    # Set text mode
    response = send_at_command('AT+CMGF=1')
    if not response or b'OK' not in response:
        print("Failed to set text mode.")
        return

    # Set recipient number
    response = send_at_command('AT+CMGS="{}"'.format(phone_number))
    if not response or b'>' not in response:
        print("Failed to set recipient number.")
        return

    # Send message
    response = send_at_command(message)
    if not response:
        print("Failed to send message.")
        return

    # Send Ctrl+Z to end message
    uart.write(chr(26))
    time.sleep(1)

# Example usage
phone_number = '+91XXXXXXXXXX'  # Replace with recipient's phone number
message = 'Hello, this is a test message from Raspberry Pi Pico W with A9G board!'
send_sms(phone_number, message)

Credits

FUSION AUTOMATE

FUSION AUTOMATE

25 projects • 1 follower

Comments