Remote Controlled Car ******************* .. image:: Images/RemoteControlledCar.jpg :align: center Description ============ The remote controlled car is a small car that is is controlled from a phone’s web browser. It consists of an integrated circuit (IC) L293D connected to a pair of gear motor with wheel, the Rpi needs to be connected to the internet. The communication between the phone and the raspberry pi is done using Element n’s IoT engine Scriptr. Learning Objectives =================== The Mini Car is a machine that helps students learn and apply the following: - Coding, electronics, robotics sciences. - Internet of things using Scriptr. - Basic web development using html, javascript. Materials Needed ================ - Raspberry Pi with micro SD card and Raspbian - Wifi Dongle (if Rpi Version 2 and lower) - Two gear motor with wheel - IC, L293D - Jumper wires - External Power for motors - Power bank for raspberry pi - Breadboard - Glue gun and glue sticks - Cutter blades or scissors - Thin sturdy cardboard (poster or portfolio cardboard) - Plexiglass Setup and Functionality ======================= .. image:: Images/RemoteControlledCar_HTML.png :align: center *Figure 1: shows the layout of our html page.* This picture is the output the html page that the user can open from his phone browser. It consists of 5 different pictures that act as buttons. When one of these buttons are pressed - using javascript - a message will be sent to Scriptr. On Scriptr side, when a message is received, it will be broadcasted to all the subsrcibers on the channel. Our Raspberry Pi will subscribe to this channel and hence will receive the message. The Rpi will analyze this message and act accordingly. For exemple if the forward button is pressed our html page will send a message to scriptr saying ‘forward button is pressed’ - The format of this message is actually different, it is sent as a JSON message (but more on that later) -. Scriptr will then broadcast this message (or edit the message beforehand) through the channel. Our Raspberry Pi being a subscriber to this channel will receive this message and will turn on the motors in order to go forward. Introduction To Scriptr ======================== What is IoT ------------ In quick words, the Internet of Things is the a system in which everyday objects have network connectivity, allowing them to send and receive data. Scriptr is an engine developed by a Lebanese company, Element n that helps us connect devices through a certain channel How does Scriptr Work ---------------------- Simply put, Scriptr opens a channel and broadcast a message through this channel. In fact in scriptr we have two types of users: Either a user is connected/subscribed to the channel, he then receives all the messages sent to this channel and can in his turn send a message through this channel. Or a user is simply sending messages to this channel to which he’s not subscribed to. We call this way of communication PubSub. Circuitry and Electronics: ================================================= The diagram below shows the connections and the circuitry of all the components used in this project: .. image:: Circuits/RemoteControlledCar.png :align: center *Figure 2: shows the wiring and connections of all the components to the Raspberry Pi.* The function of the Integrated circuit L293D is to control the motors. These motors needs an external source of power, hence the batteries,in order to have an optimal performance. Due to the fact that on a long term, the IC and the motors require more current than what is provided by the Raspberry pi. Programming =========== HTML & Java Scriptr ------------------- .. literalinclude:: Code/RemoteControlledCar.html :Web socket Definition: Simply put, a web socket is equivalent to a telephone call between terminals - computers-. :Json: JSON (JavaScript Object Notation) is a lightweight data exchange format. It’s used due to its simplicity, In fact it s easy for humans to read and write, and easy for machine to parse and generate. Exemple : { "id": 1, "name": "A green door", "price": 12.50, } this is a JSON message, from this message we can understand that the name of the object is ‘ a green door’ and has an id = 1, its price is 12.50. Scriptr -------- Create a file in scriptr called : move and insert these lines of code in it. .. literalinclude:: Code/RemoteControlledCarScriptr.txt As we can see from the script, Scriptr does not broadcast the message as it is, we have the possibility to modify the message before broadcasting it. This function in Scriptr will be activated every time a user sends a message to this channel. Python ------- .. literalinclude:: Code/remote_controlled_car.py