Together with my colleagues, we have been introduced to this wonderful corner of the hardware world by our teacher at a subject called "Microprocessors Systems" where we discussed and took the first contact with a variety of development boards, including the Raspberry Pi series.
Based on that, we had a little test based on activating LEDs with our Raspberry Pi systems. Which gave us a more intriguing view regard the logic of the technology, even if it was a simple task.
Based on these, we have been tasked to create a project, using our knowledge to give life to a "hackster style" type of working device.
So, together with my colleague, after long discussions, we create the design and logic for a timer (clock) which registry the periods of activity and inactivity of a PIR sensor, powered up by a Raspberry Pi 4 and creating patterns of LEDs control to further test the logic behind the PIR's detection traits.
For today, we shall share and teach the reader of this project how to feel the first experience of using a PIR sensor and advanced logic of working with Python (MicroPython in this case), to give a chance to feel the first drops of how to be a player in this amazing creative world of the Internet of Things and Web of Things.
Stage 1: Installing Raspbian on your Raspberry Pi and connecting to it.To begin with, we will make sure that after we purchased all the ingredients, to prepare the SD card to be installed with a special OS for our Raspberry: NOOBS or Raspbian. For this project, we follow the to install Raspbian, which is easy.
By following the instructions from the software's main page and installing Raspberry Pi Imager on our units, we insert the SD card via USB adaptor or adaptive card, we follow the instructions, we make sure we choose "full installation" and using CTRL+ SHIFT+X, we access the configuration page of the Imager.
On this page, you can optionally select the "overscan" suggestion, but everything else we select to be installed and configured according to our resources.
If you did correctly, when you will insert the SD card back into the RPi card support, once we power it, it should automatically connect to your WIFI, to have a desktop GUI and suggested applications and should be good to go.
TIP: To find your RPi's IP in your network, we can install the application "Fing" on our mobile devices (since your phone is connected to your router via WiFi) and this will help us display all the IP's we have in our network, including your RPi if it's plugged in.
Once we got our RPi's IP, we can use 2 applications to connect to it:
-PuTTY if we want only terminal connection style;
-VNC Viewer for a full desktop experience(recommended);
If you followed these instructions and documented how to do them, you have a successfully installed Raspberry Pi OS and you can connect to it to experience its full desktop capacities.
Stage 2: Administrating Apache and PHP on your RPiFor the full installation of Apache and PHP (version 7 used in this project), I will provide pages and details on how to install them perfectly. If there would be more problems appearing, you can consider searching further or use something else on the server-side.
To install Apache you can follow this link and to overcome the possible upcoming error regard establishing the domain, follow this link.
To install PHP 7 you can follow the first link from the Apache installation from above. And you will also need this link because a normal PHP installation will provide only a few of the dependencies you need, which may lead to your PHP code being ignored. This way you will be assured that your PHP will run perfectly.
If you followed the links from above, you should now have both Apache and PHP running perfectly on your RPi.
Stage 3: Creating the programs and explaining the logic of the projectThis project is provided with the py and PHP files you need to use to test if you correctly assembled all the components. You are free here to use any text editor and python based applications, luckily these are provided by your Raspberry Pi already if your installation was correct.
Use sudo python
and sudo python3
to test the Python files while with any browser (Chromium is your RPi's native browser) you will check the PHP file. The codes are provided with enough explications to understand how to work and execute them, so we will explain a bit the logic of the project.
This project represents a little closer understanding view of the concept based on detection, time registry, and possibilities to answer to a certain period of time with a personal method of activating a task.
As a project, we use detection to activate LEDs at calculated periods of time. As a concept, this combination helps us control or trigger events as soon as our sensors detect activity and even when they are inactive. Working exactly like a guard monitoring infinitely and knows exactly what protocol to apply or what to do in case something is picked up on the cameras.
This concept would be applied in future possible projects to further prove the infinite usage it holds.
If the files executed correctly and the idea behind the project been a bit understood, you are closer to see your project working from the terminal only.
Stage 4: A bit of Linux administrationFollowing the previous 3 stages, we should now have our project as hardware prepared, the necessary dependencies installed and the programs prepared and able to be executed from the terminal. At this stage, with a bit of Linux, we should be able to execute the entire project from its web page.
These details may be explained above at Stage 2, but these will be explained again to make sure we link everything.
The root folder for this program will be /var/www/html
as we saw from PHP and Apache from above.
Now we will give permissions to our files where the owner will be the one able to write, while everyone else, group, the owner will read it and execute it. And we will make sure our py files are executable as well. We will use the following commands:
sudo chmod -R 755 directory
- to give permission to the entire html folder;
sudo chmod 755 /path/to/file
- to give permission to a file if we don't want to use the first command;
sudo chmod +x /path/to/file-
to make sure our files are executable;
sudo chmod 777 /path/to/file-
to give full permission to everyone (this is in case your program yet doesn't work, but this to be used as a final option only!)
After, we make sure that our owner, which as default will be pi, and www-data as the group, would be those which own priorities to our folder html. For that we will use the next command:
sudo chown -R pi:www-data directory
- this will make pi and the group www-data owners of a folder;
If everything was executed correctly and double-checked, now we will be able to fully use the program and admire the power of Raspberry Pi 4 and PIR Sensor combined.
The final resultFor following all the stages and the ingredients of this recipe, our result should be like in the video provided below.
NOTE: One thing at this project is that it can't execute both the main file and the stop file on the same page, so I highly recommend duplicate the web page, in one you will execute the main program, and in the second one, at need, you will activate the stop protocol. This way also benefits because we can see both files working, even if it's not in the same tab of your browser.
Comments