You are on page 1of 4

# Import required libraries

from machine import Pin, ADC

import time

from math import floor

from random import randint

import urequests

# Set pin numbers

PIN_LM35 = ADC(0) # Analog input A0

BUZZ = Pin(7, Pin.OUT) # Digital output D7

YELLOW_LED = Pin(5, Pin.OUT) # Digital output D5

GREEN_LED = Pin(6, Pin.OUT) # Digital output D6

BUTTON_PIN = Pin(12, Pin.IN) # Digital input D12

# Set phone number to send SMS to

PHONE_NO = "7829010171"

# Set refresh and period values

alpha = 1

period = 50

# Initialize variables

old_value = 0

old_refresh = 0

rev = 0

rand_number = 0

temp = 0
# Function to send SMS

def send_sms(phone_no, bpm):

global rand_number

rand_number = randint(10000, 99999)

url = "https://api.thingspeak.com/apps/thinghttp/send_request?
api_key=QF7VR5BU3EWZ6TDL&field1=" + str(bpm)

urequests.get(url)

print("Women Safety\nBPM: " + str(bpm) + "\nALERT!!\nI Am In Danger Please HELP HELP!")

print("https://maps.google.com/maps?=loc:12.730810,77.706870")

print("randNumber: " + str(rand_number))

print("Sent\n")

print("Women Safety\nfalse Alert!!\n")

print("")

# Function to calculate temperature in Celsius

def get_temp_celsius():

adc_val = PIN_LM35.read()

millivolt = adc_val * (5000.0 / 1024.0)

temp_c = millivolt / 50

return temp_c

# Function to calculate heart rate (BPM)

def get_bpm():

global old_value, old_refresh

beat = ADC(0).read()

value = alpha * old_value + (0 - alpha) * beat

refresh = value - old_value


b = floor(beat / 6)

old_value = value

old_refresh = refresh

return b

# Set up interrupt for rev counter

def isr(pin):

global rev

rev += 1

# Initialize interrupt for rev counter

Pin(2, Pin.IN, Pin.PULL_UP).irq(trigger=Pin.IRQ_FALLING, handler=isr)

# Main loop

while True:

# Get current temperature in Celsius

temp_celsius = get_temp_celsius()

# Display temperature on LCD

print(str(temp_celsius) + " C Temp")

time.sleep(2)

# Get heart rate (BPM)

bpm = get_bpm()

# Display heart rate on LCD


print(" Women Safety ")

print("BPM: " + str(bpm))

print("")

# Set LED colors based on BPM

if bpm >= 100:

YELLOW_LED.value(0)

time.sleep(0.1)

GREEN_LED.value(1)

time.sleep(0.1)

else:

YELLOW_LED.value(1)

time.sleep(0.1)

GREEN_LED.value(0)

time.sleep(0.1)

# If heart rate is above threshold, send SMS

if bpm >= 100:

send_sms(PHONE_NO, bpm

You might also like