From school I got the assignment to make a project. I chose for a Smart alarm because I always sleep through my alarm and miss school then. You can only kill your alarm if there is light, sound and movement so you can't fall back in sleep or snooze it without opening your eyes. There is also a website where you can view your sleep pattern, set alarms and make new alarms.
To build the project there are some materials needed. you can find a list below. you can also find everything back in the bill of materials including the price.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Hardware
Before I started building everything i made 2 schemes (1 electrical and 1 on the breadboard) on fritzing and got them controlled to be sure there were no faults in it. Once i was sure everything was okay, I started with the project. First of all I began with the buzzer and the button because this were the easiest components. After that i connected my display to the raspberry pi. At the end then i connected my sensors. the light sensor and the motion sensor are easy because you don't need anything else but the PIR sensor needs something extra. To ensure that the PIR wouldn't make a short circuit you need to use a voltage bridge. It means that you need to use an additional resistor of 1k ohm and 2k ohm to be sure everything goes well. The exact use of the pins and how to connect everything to the pi can you find in the schemes.
Step 2: Database
To store al the data i needed a database.
My database exists of 6 tables.
there are 2 parts in the database. 1 for the sensors and 1 for the person and all his stats.
The sensor table contains an ID and a name. This table is connected to the History_sensors wich has an ID, value, Sensor_id and a name. the sensor_id is needed to know wich sensor has got a value and the date is needed to know when the sensor measured it.
The table person contains an ID, a name and a password. The password and the name are needed to log in so no one else can put an alarm for you. This table is connected to the sleep_pattern table and the Alarm_person table. The Sleep_patern table contains an ID, Hours_sleep, Date, Person_id, Bedtime and Wake_up_time. So here is the data stored to make a graphic about your sleep patern.
The table Alarm_person contains a Person_id, Alarm_id and the time. This table is needed because different people can use an alarm at the same time and 1 person can use multiple alarms. The last table is the alarm table. This one contains an ID and a description.
Step 3: Back-end
In the back-end i had to write different functions.
- ask for the table sensors
- ask for the table history_sensors
- ask for the sleep pattern
- put a new alarm
- ask for the table alarm
- register user
- put the values of the sensors in the table history_sensors
I used pycharm and wrote the code in python.
for all the functions i use the @app.route and then the address. every time you need to use a different address because otherwise it won't work. After this i write an if function with the method as value so when this is true he executes the code. in the if value there is a try catch and a sql statement to get the data or put the data away.
For the functions with the sensors it is different. Here i didn't use the @app.route but just made a function for the sensor. here you declare your pins and make a callback function. in This way everytime the sensor detects something the function is executed. In the callback function i used an if that works when the sensor detects something. In the if stands the code for putting the data into the table with an sql statement. There is also al sleep in it because otherwise it would put way too much values in the table for only 1 detection.
In my github you can find the full code for the project.
Step 4: Website
For my website I worked with html and css my website contains 11 html pages.
There are so much pages because everything works by the website. you can set an alarm, add an alarm and delete one. In the settings page you can change your password and email. You have a page for your sleep pattern. You can also add the moment when you went to sleep and when you wake up. The positive thing is every page has the same look and uses mostly the same things so the css is often the same in every page.
Step 5: Front-end
Step 6: Case
For my case i choosed to use wood. It is not that hard to cut it looks nice. My case is 26cm on 14 cm with a height of 7,5 cm. It is this big because everything needed to fit in. I made holes for the sensors, button and the lcd so the time is visible and the sensors can detect movement or light. To make these i used a lasercutter. Inside the case sits my breadboard and raspberry pi.