This project is all about controlling devices remotely via web or mobile app where Raspberry Pi 3 communicates with Arduino over Bluetooth. The reason behind my inspiration for making this project is the fact that one day I forgot to switch off my motor at my home and the motor got totally burned off.
Basically, this project can be divided into three sections. Let's get started.1. Arduino
Arduino handles the request send via raspberry pi through bluetooth (HC-05 bluetooth module). And accordingly it activates the 8 channel relay to switch devices ON and OFF displaying real time information in LCD. For instance, I have only used 3 out of 8 Relays.
Raspberry Pi is responsible to listen client's request though web or mobile app. A python based server runs which listens client's request and forwards the request to arduino though bluetooth. Please, don't get confused with the Robotic Head in this project. Inside that robotic head, there is still raspberry pi 3. For this project, You just need a Raspberry pi 3 loaded with latest raspian OS.
Please follow these steps to achieve configuration on Raspberry Pi side:
Step 1: Get Raspberry Pi up and running
Please follow this link to get Raspberry Pi loaded with Raspian OS: https://thepi.io/how-to-install-noobs-on-the-raspberry-pi/
Step 2: Configure Raspberry Pi's built-in Bluetooth
Make sure you have enabled Serial Port and Serial Console. Go to Main Menu --> Preferences -> Raspberry Pi Configuration. Click tab interfaces. Now enable Serial Port and Serial Console.
For installing and configuring Bluetooth, please follow my another link:
Step 3: Installing Python flask and necessary dependencies
Open terminal and enter:
sudo apt-get install python3-flask
Once you are done with Python flask installation and Bluetooth configuration, clone the repo provided below. Go inside /python_code folder and now start Python script here.
sudo python main.py
If everything goes well, you should be able to see server running on port 0.0.0.0:80
Now, check your local IP. Open terminal -> ifconfig. Copy that IP address and paste on browser for eg: 192.168.0.104. We should be able to see web page up and running.
Let's understand what port forwarding is and why we need it? Port forwarding is a technique that enables you to access your local host or local server from outside computer, any where from the world. For instance, your local IP address is 192.168.0.104. This is local private network address. The address that is assigned to your Raspberry Pi by your router. You will only be able to connect to this network when you are connected with that router.
So, this is the reason, why we need port forwarding.
Different routers may have different user interface for configuring port forwarding. but the main logic remains same. I have a tplink router. You can follow this link to port forward.
After successful configuration, go to your router default page then check it's WAN IP address. For example, in my case, I have: 100.66.208.221.
So, now if you browse 100.66.208.221:8080, it should automatically forward your request to your local IP address like 192.168.0.1:80 where you should be able to see your webpage up and running.
If you have any queries or any difficulties, please feel free to ask in comment below. Thanks.