Hello World for IoT : LED Blinking

In this project we will Blink the LED with the help of IoT. blinking LED is the Hello World for electronics. We often use LED just to start with any programing Hadware.

I did my first firebase project by making a simple python script on Odinub. Odinub is very cool device wich comes with pre-loaded linux so it's very easy to startup.

Here I have connected my odinub with my laptop using PuTTY. You can also check out my guide for using Odinub headless.

 Now let's start with Blinking for that just follow given the steps to make your simple but intresting IoT project.

How to Blink LED with Firebase:

Step 0: Prerequisites

First we have to make an account on firebase. Firease is free realtime database and we will use firebase to fetch the value of LED(on/off).

I made my account using this guide. It is super easy to create account in firebase.

Step 1: Setup WiFi on your Odinub

To set WiFi just follow the link given here.
And to turn on WiFi just execute following command. 

ifup wlan0

Step 2: download the packages

For this project we need to install Python and Firebase.
So, let first download the packages of python by executing following commands.

sudo apt-get install python

sudo apt-get install python-pip

Now let's download the packages by executing following commands.

sudo apt-get install requests

sudo pip install python-firebase

Step 3: Setup GPIO

If we want to turn on led first we have to setup GPIO pin with “OUTPUT” direction for that just execute the following commands.

cd /sys/class/gpio

echo 116 > export

cd gpio116

echo out > direction

By execute above command pin 23 will set with “OUTPUT” mode. There are many mathods to use GPIOs here I have used GPIOs by file System. Another is by using libary. I will make library in future for Odinub GPIO.

This is one method by executing commands other mehod is y using GPIO library.

Step 4: Scripting 

Now we have to make a shell script to set the value of LED.
Let’s first write the shell script to turn the LED ON by execute following command.

nano on.sh

Now you will get a new screen in that write following line.

cd /sys/class/gpio/gpio116

echo 1 > value

After write above lines press Ctrl+X and then Y to save the file.
Now we have to do the same to turn the LED OFF by execute following command.

nano off.sh

Now you will get a new screen in that write following line.

cd /sys/class/gpio/gpio116

echo 0 > value

After write above lines press Ctrl+X and then press Y to save the file.

Now we have to link the firebase with Odinub so we have to write a python script which will link firebase and also it will toggle the LED as per input from firebase.
So, execute following command.

nano blink.py

Now you will get new window in that just write code which is given below.

After that just press Ctrl+X and then press Y to save the code.

Step 5: Execution

Now just run the code by execute following command.

python blink.py

You can see the current status of LED on your screen and when you change the value on your firebase you will get. LED is  just an example now we can use any thing insted of LED and make more complex projects using Odinub. Also you can Interface Relay and do some cool home automation stuff. Even using Firebase you can build you Android or iOS app and tinker with the steup. In future I would love to share more projects on this.

I have also shared the Video of my Project do check out.

Code :
Code Title :
Code Language :
python
2 Commenting Overall Comment
Vatsal Maniar
Commented on :

Hi Palak, I was also getting this error. You have to change the rules of read and write. Go to your Database>Real-time database>rules "rules": { ".read": true, ".write": true } I hope this will solve this error.

palak mehta
Commented on :

Hi Bhavik, I am having this error while trying to connect firebse with my Odinub result=firebase.get("/usr",None) File "/usr/local/lib/python2.7/dist-packages/firebase/decorators.py", line 19, in wrapped return f(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/firebase/firebase.py", line 274, in get return make_get_request(endpoint, params, headers, connection=connection) File "/usr/local/lib/python2.7/dist-packages/firebase/decorators.py", line 19, in wrapped return f(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/firebase/firebase.py", line 42, in make_get_request response.raise_for_status() File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://odinub-firebase.firebaseio.com/usr/.json Looking for the solution.Thanks in advance.