Arduino car,

In this tutorial  will show you how to build a simple Wemos nodeMCU, or other ESP -based car,system. In the course I will use the term arduino for this device.

Before starting the course, I suggest to read the articles “quick start” for both the website and arduino.

Parts,

  • batteries – I’ve used AA accumulators in the amount of 10 – in my case, the battery voltage is 1.2V which gives a max ~ 6.5v so it is the maximum for motors, if you want to use ordinary batteries then hook up the bridge VM input through voltage converters set to 6v
  • two battery sockets, 5 pcs each
  • TB6612FNG H-bridge for steering motors from wheels
  • voltage converter link set to 5V
  • robot platform link 
  • Wemos D1 mini Pro 

 

Optionally – if we want our robot to have light effects:

Connections

Chassis

We start with assembling the robot chassis. Engines on the right and left side are connected to each other and we supply the power cable to both at once. It is important that after powering up the engines spin in the same direction, the wheels on the right side always spin in the same direction, the same on the left side of the car.

The whole looks like this:

When the left side of the robot is spinning at a different speed than the right one then the robot turns. When the right side is spinning at the same speed but in the opposite direction as the right one, then the robot spins around its own axis

Electronics

 

At the beginning do not hook the converter, bridge and wemos. Only after setting the inverter, check that the voltage is exactly 5v on the board.

Instead of looking at the connection diagram of the bridge, it is better to check with the list:

  • Arduino D7 – AIN1 bridge
  • Arduino D6 – AIN2 bridge
  • Arduino D5 – PWMA bridge
  • Arduino D3 – BIN1 bridge
  • Arduino D2 – BIN2 bridge
  • Arduino D1 – PWMB bridge
  • Arduino 5V connected to the bus with 5V voltage from the converter
  • Arduino 3.3V connected to the bus with 3.3V voltage (the arduino stabilizer provides us with voltage on this bus)
  • StandBy bridge – 3.3V bus
  • VCC bridge – 3.3V bus
  • VM bridge – directly to the battery – this is the voltage transmitted to the motors
  • All wemos masses, bridge, grounding converter
  • inverter input – battery plus to plus minus to minus;)
  • output transducer – 5V bus

light effects:

  • connect two stripes together to get one long
  • GND LED strip – ground
  • LED strip power supply 5V
  • HV1 converter output – signal input for the LED strip
  • LV1 – Arduino D8 input
  • resistor 6.8k ground – LED strip signal input

How will it work

The H-bridge controls the motors for inputs (AIN1, AIN2) depending on the state determines the direction of the engine’s spinning, and PWM signal is sent to the PWMA input, the higher the signal fill, the faster the engine will run

Above setting of outputs. and frequency setting analogWriteFreq (1000); (as 100 will be the engines will “jump”).

And the function for motor control is given as an argument from -1023 to 1023 and the function will control the motor accordingly

The same function is for the second engine.

For lighting, we will use the Adafruit_NeoPixel library – it should be added to Arduino:

and the SingleRing object – which displays the corresponding effects more about the class here

Arduino program

 

we download the entire directory from here to our computer to the arduino directory. Then we complete the constants:

More about fixes and how to supplement them here. Of course, before uploading and completing the token, you must have an account at remoteme.org. After uploading, our arduino will appear on our device manager.

I have described the fragment of the arduino code regarding the remoteme.org system in the quick start

 

Car testing

Before testing, put the car in such a way that it is stable and none of the wheels touches the ground!

When the message arrives, it is directed to this function where:

  • If the first byte is 1 = motor control mode
    • the next two bytes are the speed of the left motor (-1023 – 1023) – represented as a two-byte int
    • the next two bytes are the speed of the right motor (-1023 – 1023) – represented as a two-byte int
  • If the first byte is 2 = light effect
    • the next two bytes are the effect to display

to test engine operation, send a message to the car. Click “” At the device and we get a window to send messages, fill in as on the screen

the most important are bytes to send “1 0 0 0 0” means to set the speed of the car to zero (enter these values in the field “Hex” if you enter in the Text field will be sent messages that adruino will not be able to decode)

if we enter in Hex: “1 4 FF 1 AA”

it will mean:

  • 1 – control the motors
  • 4 0 = 256 * 3 + FF = 256 * 3 + 15 * 16 + 15 = 1023 – engine speed one (max)
  • 1 AA = 256 * 1 + 10 * 16 + 10 = 426 – the speed of the second engine

PAfter sending one of the engines will be spinning at the maximum speed and the other will be more than half the slower. Of course, to stop the engines we send 1 0 0 0 0;

Play with the control of lights on your own.

Of course, we will not control the car in this way. we will make a website that will send similar messages.

Website

how to create a website here. We create a blank page:

 

and then drag one file after another from here

on the field “Drop new files here”, after this operation all files will be on us in the cloud:

Opening the page on the mobile phone: Click on index.html then Get anymous link (more in the quick web page)

We have 3 options: rewrite this long URL to a mobile phone, 2 copy and send to a mobile phone, 3 or generate a QR code and scan the phone.

Of course, we can also open the link in the browser (chrome) and after switching to the developer tool (F12) and go into the mobile phone mode Ctrl + Shift + M. And test it

Control: putting a finger on the screen the wheel changes positions, from this moment the swing is measured from the place where the finger is placed, moving the finger on the screen we control the car. And the red stripes on the sides show the speed of the left and right engines:

 

About the connection buttons (those green at the top) more in the quick start

To change the light effect, select the effect from the drop-down menu at the bottom left.

When the car is driving differently than we expect –  we change the engine connection to the H-bridge. Or modify the script.js code:

by changing the position lines L1 and L2 – and in places X and / or Y add minus.

It is also a function that sends data to the car – identically as we sent using the remota.org GUI

  • carController.getLeftSideSpeed () – returns the number s of the range [-1 1]
  • fasterStart – makes the small deflection a little bigger, so that the car can move faster
  • ret.putInt8 (1); – the first byte of the message informs arduino that we want to control the engine
  • ret.putInt16 – write the motor speed as a two-byte integer to the message
  • remoteme.sendUserMessageByFasterChannel (arduinoDeviceId, ret); – we send a message to arduino.

arduinoDeviceId is taken from index.html

#### arduinoDeviceId # – is replaced by remoteme while serving to the browser into device id the first arduino – and that we have only one will be our arduino steering the car. When we have more arduino we give here the deviceId of arduino to which we want to send the message

there may also be one fragment in script.js that is not clear

and ot object initialization

it means that the sendMotor function will not be called more often than 100ms – protection against the clogging of our arduino if we would move the finger long and fast, more in the documentation

 

That’s it, I was not describing the code line by line thinking that for someone with basic knowledge about javascript and programming arduino it will be clear.

As always, I recommend fanpage on FB https://www.facebook.com/remoteMe.org/ where I throw information about the project, future courses.

Regards,

Maciek