Arduino Uno - Led On-Off Via Internet

In our previous post, we discussed about how to on-off led with a simple program. In this article, we will learn about how to do it using Internet. We will see how to use Arduino Uno with Firebase.


cheezycode-arduino-firebase


We will use our system to provide Internet to our Arduino Kit as we are not using Arduino Internet Module. We did the initial setup in our first article of Arduino Uno. For this program to run - we need to Install Firebase. Just run the command npm install firebase. Firebase Real Time database will act as a middle layer between user input and board.

Flow of data


cheezycode-firbase-flow

Program (main.js)


var five = require(“johnny-five”);
var Firebase = require("firebase");
var board = new five.Board();
var firebaseRef = new Firebase("https://arduinotutorial.firebaseIO.com");
board.on("ready", function () 
{
  var led = new five.Led(13);
  firebaseRef.on("value", function (snapshot) 
  {
    var buttonValue = snapshot.val();
    if (buttonValue === “on”) 
    {
      led.on();
    }
    else
    {
      led.off();
    }
  });
});



For board configuration led should be in pin 13. Plugin your board and execute the above program. Mac user in terminal and window user in command prompt using command node main.js (make sure you are in the same directory in which your program is).

Now open URL - https://arduinotutorial.firebaseapp.com/ you will see ON and OFF button now press ON button, led in the board will light up and if you press OFF button it will switch off. So with few lines of code, you can see the magic of lighting up the led via Internet.

If you like the article - please share and follow us on Facebook. Happy Reading


Comments

Popular posts from this blog

Create Android Apps - Getting Started

Polymorphism in Kotlin With Example