24 - 09 - 2017

A bluetooth controled car

A bluetooth control of a toy car:


DemoDiagram: BlueToothCar.nsm

The red car project shows how to control a toy car with Numato bluethood device and Altona Lab SCADA software. The car is equiped with many sensors, so the user can see on computer's display the orientation of the car on the land and distance between a car and objects in front and behind. For all the orientation sensors is used a mobile phone with AltonaRemoteSensors android application, which sends the sensor's information per one sec via TCP/IP to host computer.

The SCADA diagram has two modes - manual and automatic. In manual mode, the user can control the car through keyboard in front, front-lef, front-right, back, back-left, back-right directions. In automatic mode, the car start to move in front direction, until the front object is fixed from the distance sensor. Then the car stops, the SCADA application remembers the current azimut angle of the car and the car starts back-left moving. The back-left moving continues until one of the both events appear - the difference between current and remembered azimuth angles of the car becomes 90 degrees or if this event not happend, then if the elapsed time in back-left moving is 10 seconds.


In automatic mode, the car starts to move in front direction until the front sensor senses the object. Then the car stops and a SCADA software remembers the current azimut angel. The car starts to move in back left direction until the difference betwen a new car's azimut angel and remembered last azimuth angle becomes 90 degrees. If this event never happend, the SCADA diagram will wait 6 seconds and will stops the back left moving. Then a car starts to move again in front direction.

For this project we need:
- an old radio controled car, we will use only it's DC motors;
- Numato L298 Motor driver to control the car's motors;
- Numato 8 channel Bluetooth GPIO Module to control the motor driver and to read with its analog inputs the values from distance sensors;
- two distance sensors with analog outputs, which work in range 10 to 80 cm;
- Battery and 5V Numato voltage regulator;
- Because the car is very fast, we have to reduce the speed of forward moving DC motor. For this purpose I use a pulse wide modulation with 555 integrated circuit. It is conected to Enable signal of the DC motor and I experimentaly set the needful filling factor of impulse.
- An old phone with android operation system with installed AltonaRemoteSensors application, which send the information from all phone's sensor to SCADA application using TCP/IP communication.
- to assemble the car I will use a hot silicon pistol;


The distance sensors are SHARP GP2Y0A21 10..80 sentimeters and are with analog outputs. The output voltage is approximated in SCADA diagram:


How everithing work. The motor driver controls the two DC motors for ahead and back direction and for left and right. When the Enable signal is in hight level, the hight level of I3 input means ahead direction, I4 means back. The same happend with DC motor for left/right direction. To control the both DC motors we use IO2 to IO5 outputs of bluethooth GPIO module which are connected to motor driver. With analog inputs IO0, IO1 we read the distance between object and car - in front and behind:

Additional if the user wants, he can add a Pulse Wide Modulator, to reduce the speed of the car. The output of PWM has to be connected to Enable input of Motor driver:


The Bluetooth diagram has a few areas:
The control area shows all the car's sensors - azimuth angle, Roll angle, Pitch angle, frond and back distance, Object in front and behind, there buttons for manual control the car and to Start/Stop the automatic mode:

The first green area represents the control of the car. The main block is a Numato Bluetooth block, its four digital inputs are connected to digital outputs of the bluetooth device and are responsable for forward, back, left and right direction of the car. The analog inputs of Numato device are converted to voltage with Expression block, then are filtered with AverageVal block. Then the signal is approximated because the relation between a voltage output of the sensor and the distance is not linear. This is the approximation table. So the outputs of this block are in centimeters. At Around blocks are set when the distance is under half meter, theirs digital output becomes to hight level. So as the result, the green area has a few inputs to control the car and two outputs which become to hight levels when there is an object under half meter in front or behind a car:

Additional logic on left side of the green area alows combinated commands to remote car to be send. for example: forward and left moving direction, forward and right, back left and back right. The group of buttons are connected with buttons from the interface. The Keyboard block alows a manual control using a keyboard pad.

The secondt green area is responsable for automatic mode. It has two inputs from buttons to start and stop the mode. When the Start button is pressed, the Triger for Automatic mode switchs On and this allows the Automatic module to be sensitive to signals from front and behind distance sensors. At the same moment the Forward moving triger switchs On too and the car goes in forward direction. The moving will continue until the object appears in front of the car's sensor. This will reset the Triger for forward moving and will start a TimeOut for 2 seconds and after this interval the triger for back lef moving will be switched On and the can will start back lef moving:

The back left moving is controled from the bottom green area with name: Orientation module. The module received an information for car's azimut angle from AndroidPhoneInfo block. The output of first expression block always has an angle 90 degress right by the current angle. So when the input Start back left moving become to hight level, the Memory block will remember the result of expresison block, this will be the expected rotation angle of the car. When the car starts back left moving, the difference between the current car's azimut angle and the remembered will start to decrease from 90 degree to zero. When the difference becomes around zero, the Orientation module will rise the hight level of its output and will stop the back left moving of Automatic mode module. When the back left moving starts, the TimeOut block starts to wait 6 seconds. If the back left moving never turn the car to 90 degrees, then the timeout will stop the back left moving: