SunBlock
Intro
For one of our courses at school, every person needed to create a project. It had to do with all of our other subjects. I decided to make a smart sunprotection device. This device consists out of a Rapsberry Pi, standard blinds , a servo, a Light Dependent Resistor (LDR), a shift register and some resistors. This device will automatically open or close when the LDR gets a certain amount of light. This device could be handy to keep the house fresh, when it's hot. It's also connect to a database, which will safe all the values of the measuring devices. This database itself is connect to a website, where you can find some info about the project and also graphs of values.
Supplies/Materials/Tools
Requirements:
- MG995 (Servomotor)
- Raspberry Pi
- GL5528 (LDR)
- MCP3008 (shiftregister)
- Voltcraft 600W, 600mA, adaptable power supply
- 2x 2,2 kOhm resistors
- 1x 1 kOhm resistor
- 1x 10 kOhm resistor
- Gear set
- A few stretchers
- 4 plates of wood that are about 1 meter long and 20 cm wide
- 1 plate of wood that is 1 meter long and 40 cm
- Some vines
- Slats
-
Standard slats headpiece
Tools:
- Multimeter, to check all the components.
- Nail shooter
- Some screwdrivers: stars and flat
- Scissors
- Sawing machine
- Measuring rod
The price for all the requirements together is around 160 euros. When you buy these products always check if they good quality. In the attached excel file you can more info about where bought all these products.
Downloads
Circuit
In the attachments you can find the circuit in a image form, and also in fritzing form. In the fritzing scheme, you can find extra info like the values of the resistors, but also the specific names of the components.
Explanation of the circuit:
In this project I use a Raspberry pi 3, which i connect to the breadboard with the T-cobbler Plus. To connect my LDR to the Pi, I used a MCP 3008 (shift register) so i could convert the bits into a normal value. I connect the positive side of my servo to the 5 V power supply, the negative side to the ground of the external power supply, and the signal cable to GPIO pin 23, with a 1 kOhm resistor in between.
Depending on the servo motor, you can also use a external power supply. If you do this make sure that your power supplies are NOT connected, but also that the grounds ARE connected, so you get a common ground.
You can always check if the components are well connected with the multimeter.
Database
My project needed a database, so I could safe my values of the sensors, and use them later in my website. For this I used MySQL.
Installing MySQL is pretty, you can find more info about it at this link : https://dev.mysql.com/doc/mysql-getting-started/en...
On the picture you can see the structure I used for my database. It's a pretty easy structure because there aren't many things to safe in this project.
You can use the attached .mwb file to synchronize my database with your databases in MySQL.
Downloads
Database on Raspberry PI
To store the data on the Raspberry Pi, you need to install MySQL on your Pi. You can do this with these 2 commands:
- sudo apt-get install mysql-server
- sudo apt-get install mysql-client
-
sudo apt-get install python3-mysql.connector
Now that you installed MySQL, you can use it by using the following command: mysql -uroot -p and entering the password you set earlier in the installation.
Now, to create the database itself you need to the following steps:
- Create 2 users with the commands you can find in the first picture. If you want you can choose a different name and password.
- Create a database with this command: CREATE TABLE TableName;
- Create the tables with the queries you can find in picture 2,3 and 4.
Now the database on your Raspberry Pi is ready to store your values.
Coding
Now that the circuit and the database are ready, we can start with the coding of the project.
On this link, you can see all the codes i used for this project: https://github.com/wouteroosterlinck.
You will find the code for my circuit in the file called Project1_elektronicacode.py. The rest of the files are for my website and my database connection. Please note, if you chose another name, password or database name for your database, then you will need to adjust line 5-9 with your entered values in the file: DbClass.py.
All these codes are written in PyCharm.
Transfer Code to Raspberry Pi
To upload files to the Raspberry Pi from Python.
Steps
- First you need to start with downloading python on the Pi with the command: "sudo apt-get install python3"
- Go to Settings in PyCharm.
- Go to Deployment.
- Fill in the details of your Raspberry Pi, picture 1.
- Choose the mapping your going to use, picture 2.
If you did these steps you can start uploading all your files to the Raspberry Pi.
Building the Case
Each of these steps have an explaining picture. The pictures are in the order as the steps. Some of the pictures will be from the internet, because some of pictures got lost.
Step 1:
- Saw 2 planks that are 1 m long, and 20 cm wide.
- Saw 2 planks that are 85cm long, and 20 cm wide.
You can do this with a sawing machine, but also with a regular saw.
Note: make sure that the 2 planks are the same size, so that your frame won't be asymmetrical.
Step 2:
- Connect the 4 planks by shooting 2 nails in each corner of the frame.
Make sure that the corners of the planks are nicely aligned with each other. If you don't have a nail gun, you can also use a hammer, but this will pretty hard. For this part, I didn't get a clear picture, so I needed to use a picture from the internet.
Step 3:
- To enforce the frame, i also put 2 screws in every corner.
This will make sure that your frame is solid.
Step 4:
- Attach the 2 (or more) attach hooks for the headpiece to the top the frame.
You can do this with a screwing machine. For this step I also chose a picture from the internet because it's clearer.
Step 5:
- Saw a plank that is 1 m long, and 35 cm wide.
This plank will serve as a pedestal. You can use a machine saw, or a normal saw for this. Picture from the internet.
Step 6:
- Attach the pedestal to the bottom of the frame with some screws.
You can do this with a screwing machine. Picture from the internet.
Placing the Servomotor and the Slats Headpiece
Each of these steps has a photo that can help you to understand the steps. They are both in the same order.
Step 1:
- Remove the sidecap of the headpiece.
- Remove the cable that is normally used to turn the blinds.
Step 2:
- Replace the cable with a stretcher.
- Close the sidecap of the headpiece.
Step 3:
- Click the headpiece of the slats into the attach hooks.
Step 4:
- Attach the pulley (katrol) to the gear of the servo motor with 2 little screws.
- Put gear on the servo.
Step 5:
- Attach the servomotor on the left or right side of your frame, just make sure it's at the same side as the gear wheel of the slats.
Step 6:
- Attach the stretcher from the headpiece to the pulley that is attached to the gear of the servo.
Step 7 (optional):
The slats that I bought where to long for my case, so i needed to shorten them.
- Measure the length of the slats you need, with my frame it's around 85 cm.
- Use scissors to take off the part you don't need.
Step 8:
- Hang the slats on their holders.
Attach the Raspberry Pi to the Frame
Each of these steps has a photo that can help you to understand the steps. They are both in the same order.
Step 1:
- Place the breadboard on top of the frame
- Put 4 nails around the breadboard so it wont move easily.
Step 2:
- Put 2 nails next to each other with a distence of 3,5 cm between them. Note: Make sure that you put them at the wright distance of each other, and also make sure they aren't to high or to low.
Step 3:
- Put the case of the Pi on these 2 screws, it normally has 2 holes on the bottom of the case.
Step 4 (optional):
This is only for people who use an external power supply.
- Put a nail with a little hook over the power supply, so that it wont move easily.