RasbperryPi pins control over the internet

Assumptions

Check out the Video Tutorial for more details :-

 

A very simple tutorial that will show you how you can control Raspberry Pi over the internet.

Here I have attached a LED to Raspberry Pi. State of LED is controlled by website or by mobile application. I have also connected a push button to Raspberry Pi  which can also be used to control the LED.

 

Android application (it’s not mandatory to use the mobile app)

Install Arduino Remote LITE  And signup to your RemoteMe account. If  you don’t have account create one for free here

After Signup at variable list there are plenty new variables added automatically by application:

  1. variables tab
  2. Variables
  3. Its good to turn on persistent state – by clicking save icon

We can already change variable state by mobile app:

From Relay tab

After the changes at app, values are sent to RemoteMe.

Adding WebPage (It’s not mandatory you can use mobile app)

WebPages are freely stored at RemoteMe cloud and using them you can control your devices.

We will add one WebPage with two buttons. Buttons are going to change state of relay_01 and relay_02 variables.

Add new WebPage :

 

Raspberry Pi

Now we will connect our Raspberry Pi zero w and  when RELAY_01 variable is true we will turn on a LED  and when button at Raspberry Pi is clicked RELAY_02 will change state to opposite.

Install RemoteMe program at you Raspberry Pi instructions here 

Connecting LED ans button to your Raspberry Pi:

Be careful and double check the connections before you power the Pi.

When connections are made we can add the control script more details here

At Raspberry Pi choose burger menu and “Add external script with wizard”

At first step choose:

Second step device ID:5, name python.

At last step choose “create Device”. when Raspberry Pi program is  restarted you will see:

It means that at your Raspberry Pi device you have one script, and both RPi and python script are connected.

Ofcourse now LED and buttons will not work. so lets edit our python script.

 

How its working

When You open variables tab and expand Relay_01 and Relay_02 you will get:

It means all three devices are observing RELAY_01 and RELAY_02 variable, and if its changed  by one of the device, change is propagate to all other devices.
More about Variable, and devices section here , here and here

When the RELAYs variable is changed by the WebPage its propagated to android application and it redraws state of relay. When the change comes to python this functions is called:

and this function just changes output of the pin to turn on or off the LED

When change is received at Raspberry Pi or Relay2 it calls:

we just remember the state of this relay in global variable “relay2”

When the button on RPI is pressed we are calling this function:

this function change global variable rela2 into opposite and this state is sent to RemoteMe by calling function  setRELAY_02(relay2) and then RemoteMe propagate new state of variable to the android app and WebPage.

WebPages and android application automatically recognize this variable and change connected into this component.