Rodd shan
Published

Smart Morning Alarm

This is an IoT project which is an alarm system which you cannot snooze or turn off. It senses that if you are present on the bed, it beeps.

IntermediateFull instructions provided1 hour5,569
Smart Morning Alarm

Things used in this project

Story

Read more

Schematics

Hardware Connections

Connections

Code

Arduino Code

Arduino
#include <Ultrasonic.h>

/*
 * Ultrasonic Simple
 * Prints the distance read by an ultrasonic sensor in
 * centimeters. They are supported to four pins ultrasound
 * sensors (liek HC-SC04) and three pins (like PING)))
 * and Seeed Studio sesores).
 *
 * The circuit:
 * * Module HR-SC04 (four pins) or PING))) (and other with
 *   three pins), attached to digital pins as follows:
 * ---------------------    ---------------------
 * | HC-SC04 | Arduino |    | 3 pins  | Arduino |
 * ---------------------    ---------------------
 * |   Vcc   |   5V    |    |   Vcc   |   5V    |
 * |   Trig  |   12    | OR |   SIG   |   13    |
 * |   Echo  |   13    |    |   Gnd   |   GND   |
 * |   Gnd   |   GND   |    ---------------------
 * ---------------------
 * Note: You need not obligatorily use the pins defined above
 * 
 * By default, the distance returned by the distanceRead()
 * method is in centimeters, to get the distance in inches,
 * pass INC as a parameter.
 * Example: ultrasonic.distanceRead(INC)
 *
 * created 3 Apr 2014
 * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
 * modified 23 Jan 2017
 * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
 * modified 03 Mar 2017
 * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes)
 *
 * This example code is released into the MIT License.
 */



/*
 * Pass as a parameter the trigger and echo pin, respectively,
 * or only the signal pin (for sensors 3 pins), like:
 * Ultrasonic ultrasonic(13);
 */
Ultrasonic ultrasonic(12, 13);

void setup() {
  Serial.begin(9600);
  
  }

Ultrasonic Python Code

Python
import conf, json, time
from boltiot import Bolt

limit=105     #This is distance b/w sensor and wall
max_time=20   
min_time=18

mybolt=Bolt(conf.bolt_api_key, conf.device_id)
response=mybolt.serialRead('10')
print(response)

def buzzer_action(pin, value):
  response=mybolt.digitalWrite(pin, value)
  
ticks=time.time() #gets the current time
ltime=time.localtime(ticks) #gets the local time
current_hour=ltime.tm_hour  #gets the current hour

while True:
  response=mybolt.serialRead('10')
  data=json.loads(response)
  distance= data['value'].rstrip()
  print("Distance:", distance)  #distance recieved from Arduino
  
  if(current_hour<max_time and current_hour>=min_time):
    print("Current Hour:", current_hour)
    if int(distance) < limit:   #If the person is sleeping then the distance will decrease
      print("Limit Exceeded || Buzzer Action")
      buzzer_action(1, "HIGH")    #buzzer beeps
      time.sleep(5)
      buzzer_action(1, "LOW")     #buzzer stops
      continue
    else:
      time.sleep(10)      #waits for 10 seconds
      continue
  time.sleep(10)    #waits for 10 second and again repeats all steps

Credits

Rodd shan
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.