The objective of the program is, when the sensor is triggered , feedback should be printed on the shell that an alarm is triggered,while an LED will also blink to show that an alarm is being triggered and at the same time wake the sim800l to send an SMS notification.
The problem we are experiencing is that, when the sensor is triggered, the SMS programmed part is not responding ,only the led blinks and feedback is received on the shell terminal, that an alarm is triggered. we are not sure if we have programmed correctly for the SMS to be sent or not, we are beginners in micropython but please assist further in that regard.
Code: Select all
from machine import UART, Pin
import uasyncio as asyncio
import time
import utime
uart = UART(0, 9600)
test_led = machine.Pin(8, machine.Pin.OUT)
sensor_dig2_pir5 = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_DOWN)
CR = chr(13)
CTRLZ = ('\x1A')
QUOTE = chr(34)
def SIM800(command):
AT_command = command + "\r\n"
print ("done")
ser.write(str(AT_command).encode('ascii'))
time.sleep(1)
print ("commands ready")
def pir_handler(pin):
if pin.value():
if pin is sensor_dig2_pir5:
print("Alarm!sensor triggered!")
test_led.value(1)
utime.sleep(0.2)
def send_message(message, reciepient):
uart.write('AT+CMGF=1\x1A')
uart.read()
print("sim ready")
uart.write('AT+CMGS="+27733166980"\x1AHello User\x1A')
uart.read()
print("sent")
test_led.value(0)
sensor_dig2_pir5.irq(trigger=machine.Pin.IRQ_RISING, handler=pir_handler)