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 :

  • Devices Tab
  • New Device at right top corner
  • New WebPage
    • name : controlWeb
    • deviceId: 10
    • template – leave default
    • more about adding WebPage here
  • At new created WebPage click index.html then Edit with wizard
    • Insert Component button
    • And fill adding window:

    • this new created button will change variable Relay_01
    • add second button with RELAY_02 as name and label relay2
    • close the window
    • click at index.html and click open in newTab
    • by clicking at relay 1 and relay 2 you can change button states, and If  you have opened android application relays states are changing each time buttons at webPage are clicked

 

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:

  • Led anode is connected to Pin 19
  • Led cathode is connected by resistor to GND
  • button one leg is connected to GND second to pin 26

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.

  • Expand Python script device
  • then click at python.py and Edit
  • paste code:
    Into window and click Save. After restart You will be able to control your led by webPage and arduino App 🙂

 

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.