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: PrerequisitesFirst 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: Set up WiFi on your OdinubTo set WiFi just follow the link given here.And to turn on WiFi just execute following command.
ifup wlan0
Step 2: Download the packagesFor 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 pythonsudo apt-get install python-pip
Now let's download the packages by executing following commands.
sudo apt-get install requestssudo pip install python-firebase
Step 3: Set up GPIOIf 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: ScriptingNow 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.
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.
Comments
Please log in or sign up to comment.