Node.js is one of the best options for Real-Time Applications. I have previously worked on some real-time apps using Sockets, so with the same concept, I decided to make some IoT projects with Node.js server for self-learning.
This Rover of mine communicates with my Node.js server using Bluetooth and on the front-end, I send commands to the server using Sockets.
Project AimTo study and implement wireless communication between Node server and hardware (which is in this case our Rover), and to remotely control the Rover with a mobile web-page served by Node server using Sockets.
PrerequisiteYou need to have some basic knowledge of Node, socket programming, and L298 Motor Driver working.
Requirements- 1 Arduino Uno
- 1 L298 Motor Driver
- HC-05 Bluetooth Module
- Jumper Wires
- 2 Battery - 9 volts each
- 2 gear Motors (6-9 volts)
- 2 compatible wheels
- Chassis
- Computer with Node.js installed for our server.
Building the Rover is not that complicated, you can purchase a "2 wheel chassis kit" which is easily available online and comes with all assembling units.
Our Arduino Uno and L298 Motor Driver are embedded on top of our Rover, both of which are powered by two 9 volts battery separately.
Arduino Uno in turn will power the HC-05 Bluetooth module which will communicate with our server.
Circuit DiagramAs shown above the circuit diagram, the L298 motor driver is powered by a 9V Battery, the two motor control outputs are connected to Motor A and Motor B and as the motor has no polarity you can connect any terminal to it, but make sure that both motors rotate in the same direction. Do not remove the 5V regulator jumper.
Note: if you power L298 with more than 12 volts the onboard 5V voltage regulator will be damaged.
Arduino Uno is also powered by a 9V battery with its positive terminal connected to the Vin pin of Arduino and the negative terminal to the common ground. Arduino in-turn will power the Bluetooth module, so connect the Vcc pin of HC-05 to 5V of Arduino and GND to ground.
For serial communication between HC-05 and Arduino, connect the TXD pin of HC-05 to the RX pin of Arduino and RXD pin of HC-05 to the TX pin of Arduino.
Now to control the L298 module you can connect the EN1 and EN2 pin with any PWM pin of the Arduino. And then connect L298's Input pin -1, 2, 3, 4 with any digital pin of Arduino.
Data TransmissionAs shown above, is a diagram showing the transmission of signals.
1. The user will access the web-page served by the node server. The URL would be the IP address with port number used, for e.g- "192.XXX.XXX.129:8080".
2. When the user clicks a button on the web-page, it will trigger the server to perform the required function. This communication happens due to Sockets.
3. The Node server which is connected to the HC-05 module via Bluetooth, will send the required data to the HC-05 module.
4. The HC-05 will transmit data to Arduino UNO using serial communication.
5. The Arduino UNO in turn will control the L298 module.
Step 2- Setting up the serverFor our server, we need to install Node.js. Install any stable version of node, mine is 11.15 version. We need to install the following packages-
- node-gyp
- express
- node-bluetooth
- ejs
Note - Installation of "node-gyp" might be tricky as it does not support some latest version of Node, so better install version 11.15 of Node.
Now, we need to listen to events from a web page, as soon as an event is triggered while interacting with the web-page, the page will emit the required function which needs to be executed to our Node server. The server in turn will listen to that message and will execute the desired function (which is in our case, send data to Bluetooth).
So, create a server and web-page using packages like "express" and "EJS". Design the web-page with the controls you want and set up socket connections for it by creating a socket server, you can refer to this documentation.
For Bluetooth setup refer to this documentation. Whenever any control-button is clicked a message is sent to the HC-05 module.
Here is my simple web-page --
As Bluetooth will communicate with Arduino-Uno using Serial Communication we will send some "string" as a command and an additional letter which will tell us to terminate and capture the string.
For example-: for moving forward, Bluetooth will transmit "forwardT", and in the Arduino end as soon as we encounter the letter "T" we will know the serial communication is completed.
And with that incoming string command, we will configure the L298 driver to move forward, backward, left, right, alter the speed, etc.
Find the Arduino Code attached.
Step 4- Final ResultEnhancements and Future ScopeIn later stages, I am planning to control the rover using voice commands, and obstacle avoidance feature. I can also maintain a database where I will keep statistics records such as distance traveled, max speed, avg speed, etc. I will also add multiple sensors such as temperature, light, and humidity and will keep track of it at regular intervals which will get stored in our DB.
Next VersionCheck my next project "Voice Controlled Rover using Mobile"
Comments