Sleep Easy

848

9

2

Introduction: Sleep Easy

About: My Name is Jakob Soens and I am currently a student MCT at Howest (Kortrijk Belgium)

Hi, my name is Jakob. I'm allergic to house dust mite and I have asthma. This is the inspiration for this project.
For my first year of MCT we got an assignment to make a project from scratch using all the knowledge we gained this year.

I chose to make something that could benefit me and people like me who have trouble with allergies. Generally I don't have a lot of trouble during the day. The real problem is when I'm sleeping and can't control the environment around me. During the night heat can rise, humidity can fall and air quality can worsen. All these things can affect the way you sleep.

I bought an air purifier a while back and immediately noticed that there was less dust in the air and therefore I could sleep better. I didn't have a stuffy nose when I woke up and I felt well rested, but it wasn't perfect. I still had to turn the air purifier on and off every time and didn't really know when it was necessary.

This is where this project came to mind. I decided to start measuring different values, mainly: dust, air quality, temperature and humidity. With those values I could turn on my air purifier automatically and I would have a better view of what could be causing my bad sleep.

This is my first project and I called it Sleep Easy.

Supplies

I decided to add an air humidifier to my project because of the importance of humidity on a good sleep and all around health. I also had some trouble hacking my air purifier so for now I just use a small fan as an example.

To recreate this project this is what you are going to need.
Main:

  • 1 x Raspberry Pi and adapter
  • 1 x Arduino and USB cable
  • 1 x SD card minimum 8gb

Actuators:

  • 1 x Air purifier (small 12v fan)
  • 1 x Air Humidifier (Medisana UHW)

Sensors:

  • 1 x DHT22
  • 1 x Grove - Air Quality Sensor v1.3
  • 1 x Grove - Dust sensor

Components:

  • 1 x 5V relay module
  • 1 x LCD Display 16x02
  • 1 x Button
  • 1 x Breadboard power supply and adapter
  • 1 x 12v adapter
  • 4 power socket strip

Small components:

  • 1 x 10kOhm potentiometer/trimmer
  • 1 x transistor bc337
  • 1 x resistor 470-220Ohm
  • 1 x Diode
  • About 10 jumper wires m/m
  • About 15 jumper wires f/f
  • About 10 jumper wires m/f

Case:

I used some wood I had lying around but you could use anything to make a small box.

Tools:

  • Ethernet Cable
  • Hammer
  • Soldering Iron
  • Wood glue
  • Small nails
  • Drill
  • Wood file
  • Saw
  • Paint (a colour you prefer)

You can find the Bill of Materials down below.

Step 1: Assembling the Circuit & Raspberry Pi

Attached you can find the breadboard and electronic schematics.

The main components of this circuit are the sensors: DHT22(Temperature and Humidity), Air Quality and Dust Sensor and the actuators: fan and air humidifier.

The fan is controlled by using a bc337 transistor. If you're using an actual air purifier it will probably be with a relay like the air humidifier.

Since there are a lot of free GPIO pins I connected the LCD directly to the Raspberry Pi for clear and fast communication.

Side Note:
I used an Arduino to read in the sensors for the main reason that the dust sensor needs some time to calculate the amount of dust in the air and the Arduino is better suited for these kind of basic repetitive tasks.

At first I connected the Arduino and Raspberry Pi with a logic converter, but I realised that I could save an adapter and some cables by connecting the Arduino with the usb cable directly to the Raspberry Pi.

Setting up the Raspberry Pi

My colleague student Killian Okladnicoff has made a wonderful guide on how to set up a Raspberry Pi for project such as this one. Check out step 2 of his project for the guide and check out his project as well!

Step 2: Creating the Case

In this step you can improvise a lot on how you want to build a case. I chose a simple box shape with sliding panels so I can access the inside easily. For materials I mainly used scrap wood.

In the pictures you can find the first sketches with all the measurements. It's quite a simple design that anyone with little skills can make.

Step 3: Setting Up the Website and Database

After setting up the Raspberry Pi you can use Visual Studio Code with the remote ssh extensions to connect to your Pi. Attached there is a pdf that explains how to get the files in the right place in a very easy and convenient way using Github. You can find my Github repositoryhere.

Database:

From the repository, download the Database folder to your computer. You will need to create a database structure on your Pi to save all the data. For this follow the instructions in the pdf. You will need to download Mysql Workbench

Testing:

If you followed the pdf everything should be working. If you're connected with an Ethernet cable you can surf to 169.254.10.1 and you will see the home page of the website. However the back end is not running yet so you won't see any new data on the website.

If you open the file app.py in Visual Studio Code and run it by clicking the green triangle in the right corner. The back end will start sending data to the database. If you refresh the website in a few minutes you should be seeing the current temperature, humidity, air quality and dust amount.

Website:

On the first page you can see the current data.

If you go to the 'Toestel' page you can turn the fan/air humidifier on and off manually.

On the 'Historiek' page you can see a graph showing data from different dates.


Step 4: Automation

To make your Pi start the back end automatically every start up you need to setup a few commands.

Open you Pi again in Visual Studio Code and open the terminal in the bottom.

Enter the first command:

  • Sudo nano /etc/systemd/system/Sleepeasy.service

Save with Ctrl + O and exit with Ctrl + X

You can change the name at the end to whatever you want.

Copy the text from the txt file below into the terminal.

Then enter the following commands:

  • Sudo systemctl daemon-reload
  • Sudo systemctl enable Sleepeasy.service
  • Sudo systemctl start Sleepeasy.service
  • Sudo systemctl status Sleepeasy.service

With the last command you should see that the service is up and running.
Now you can try a restart with sudo reboot.

After a few minutes the service will start and you will see the ip address displayed on the LCD.

Side note:

The service might start slowly. To fix this you need to remove "ip=169.254.10.1" from the boot/cmdline.txt file.

Use this command to edit.

  • sudo nano /boot/cmdline.txt

Save with Ctrl + O and exit with Ctrl + X

Step 5: Finally

Thank you for reading my Instructables. I hope you enjoyed it and were able to recreate this project without a lot of problems.

If you have any questions or suggestions please feel free to comment below. I will try to respond to questions asap.

Best regards,

Jakob Soens

First Time Author Contest

Participated in the
First Time Author Contest

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Maps Challenge

      Maps Challenge
    • Metal Contest

      Metal Contest

    2 Comments

    0
    NirL
    NirL

    1 year ago

    So many MCT students from Howest lately:)
    Good job on the project!