Arduino

How to connect Javasctript and Arduino

Here's how you can make a project using arduino and javascript

The objective of the project is to switch a LED on when an image is detected by a Neural Network

Here's a list of the software needed for this roject

You need to follow these steps;

  1. Connect a LED in pin 13 of an Arduino
  2. Install Arduino software in pendrive
  3. Install driver for Arduino recognition found in folders drivers
  4. Check the port number in Arduino menu, e.g COM3 and click on it to be sure of port recognition
  5. Under examples of Arduino software,uploaf Arduino Standar-Firmata
  6. Install node.js 8.9.4 LTS version. It is a Javascript server listening to http://localhost:8080 or http://127.0.0.1:8080
  7. Open the Unix terminal and execute node hello.js to check servers is working
  8. Write in terminal "npm install johnny-five" this is a node package manager(NPM) found at npmjs.org
  9. Alternative to NPM is Bower because is another powerfull package manager.To use bower you need to install git from github.com and write in the terminal "npm install -g bower"
  10. npm install express
  11. npm install socket.io --save
  12. npm install arduino-firmata

What is Firmata? It is a standard protocol to communicate with microcontrollers (LEDs or buttons) from any software or any connected computer, the goal is to avoid having to program in different programming languages

The intention is to install the firmware protocol inside our arduino board, to be able to control it remotely. First of all you have to install the johni five firmware but first you have to have the node.js, socket.io and express.js installed on your computer. Once installed node.js, For the rest of the tools we will use a file called manifest where we will indicate the dependencies of our application. We create our folder where we are going to mount the application and at the root of this we put the file package.json, in this file we are telling you to install us express, socket.io and johnny-five, it is saved in the root folder of our project .After we execute the cmd, in this we write the command "npm install" and all the dependencies will be installed. Now, the firmata protocol would be installed and the arduino would be ready for our project. Then we must create webSocket, that is, the web page from where we will control the arduino, this allows us socket.io that allows us a communication between the browser and the server (node.js). For the interface of the page you can use bootstrap and html5, this would be an attempt of javascript code to turn it off and on from the created web:

Javascript code (the web to interact with arduino)

Html code(the interface of the web)

Example of an Interface of the web

How to use the lenguage of Arduino

First we have to understand the different functions to apply the Arduino, one basically is play with a Led.Now we can interact with the led throug de pin mode with two forms, Digitalwrite or analoghwrite