Modification of an old thread concerning the creation of an ARDUINO vehicle by DIY enthusiasts

Marc DANIEL

Well-Known Member
Licensed User
This is an edit to an old thread

Build your own arduino car

For DIY enthusiasts, it is possible to build an Arduino car using more or less the same principles as before, without needing the pre-made chassis presented in China.

3b-Montage.jpg


wheelbase: 5.32 inches - Maximum support width: 5.51 inches - Support length: 9 inches

8b-VueGénérale.jpg


Additional material, modules and components used for building the car:

Arduino_Uno.jpg
MotorShieldL298.jpg


We will be using an Arduino Uno board, onto which we will attach an L298P motor shield with a built-in buzzer. This shield will have the necessary connections for the servo motor (steering) and the two motors.

1774786566054.png
1774786598046.png
1774786618296.png


1774786646209.png
1774786672013.png
1774786686467.png


Rear-mounted motors with mounting brackets and wheels included

2b-Roues.jpg

We modify the front wheels by using 2 small ball bearings per wheel to fix them to the steering bar.
1774786904596.png
1774786927385.png
1774786949662.png



1774786971132.png
1774786995132.png
1774787019006.png


- An Arduino UNO R3 or similar board

- An L298P motor shield with integrated buzzer and dedicated connections for the servo and the two motors

- A quarter-inch breadboard for the HC-05 Bluetooth module and the small test button

- An HC-05 Bluetooth module

- An MG 996R servo with cables and accessories (arms and screws) to control the front steering (We attach it under the board used as a base in front of the steering bar)

- Two motors to power the rear wheels

- Four wheels

The two front wheels will be reversed, drilled, and modified with two mini-bearings that will fit onto the steering bar axles.

Suitable nuts and washers will be needed

The rear wheels are attached with hexagonal brass brackets supplied with the motors and an external screw.

- 4 mini ball bearings 0,196 x 0,43 x 0,157 inches (2 per front wheel)

- Complete pre-assembled steering rod (5,51 inches wheel spacing)

- One steering linkage

- One holder for 3 18650 Li-ion lithium batteries

- Three 3.7-volt 18650 Li-ion rechargeable batteries

- One main switch

- Three 1KΩ resistors, one 220Ω resistor, one blue LED, white LEDs for the front, red LEDs for the rear

- Colored wires, jumpers for the various connections between all these components

- The bracket will be cut from a 1 cm thick sheet of plywood


Barre.jpg


Allow a spacing of 5,51 inches (14 cm) between the front wheels and therefore the rear wheels to cut your support board accordingly

1774787369833.png

Servomoteur.jpg


A link will be fixed between the servomotor and the steering bar

The Arduino B4R program will be slightly modified since we are now managing two rear motors instead of one, but the scenario remains the same, and therefore the B4A smartphone application remains exactly the same as before with the car and chassis. The test button will produce exactly the same results:



- The front wheels will turn right then left before aligning in a straight line.



- The vehicle will move forward for 3 seconds and then backward for 3 seconds.



- The installed lights and the integrated buzzer will turn on and off several times.



MiniFritzing.jpg




General diagram of the connections between the various components of the Arduino car

 
Last edited:

Marc DANIEL

Well-Known Member
Licensed User
ArduinoVehicle.B4R:
' ArduinoVehicle.B4R - Véhicule ARDUINO - ARDUINO Vehicle
' Arduino UNO Board & L298P Motor Driver Shield

#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region


Sub Process_Globals
    Public Serial1 As Serial
    Private SoftwareSerial1 As SoftwareSerial
    Private astream As AsyncStreams
    Private BtnTest, ENA, ENB,  PWMA, PWMB, Lights, RedLights, Buzzer As Pin
    Private Speed As UInt
    Private FEUX As Boolean
    Public MonServo As Servo
    Private SON As Boolean
    Public Angle, L, X=0  As UInt
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("Start")
    ENA.Initialize(12, ENA.MODE_OUTPUT)  ' Forward or Reverse
    ENB.Initialize(13,ENB.MODE_OUTPUT)
    PWMA.Initialize(10, PWMA.MODE_OUTPUT)
    PWMB.Initialize(11, PWMB.MODE_OUTPUT)
    MonServo.Attach2(9,30,130)              ' Servomotor-driven steering rod
    Lights.Initialize(7, Lights.MODE_OUTPUT)
    RedLights.Initialize(8, RedLights.MODE_OUTPUT)
    Buzzer.Initialize(4, Buzzer.MODE_OUTPUT)
    BtnTest.Initialize(BtnTest.A0,BtnTest.MODE_INPUT_PULLUP)
    BtnTest.AddListener("BtnTEST_StateChanged")
    SoftwareSerial1.Initialize(9600,0,1)
    ' TXD pin of the HC-05 Bluetooth module connected to the RX pin (D0) of the Arduino UNO board (blue wire in our diagram) - direct connection
    ' RXD pin of the HC-05 Bluetooth module connected to the TX pin (D1) of the Arduino UNO board (green wire in our diagram) - resistor protection - receives external data
    ' It is recommended to temporarily disconnect these wires during the compilation phases of the Arduino B4R program and reconnect them afterward
    astream.Initialize(SoftwareSerial1.Stream, "astream_NewData", Null)
    straight_Ahead
End Sub

Private Sub BtnTEST_StateChanged(State As Boolean)
        If State = False Then 'Test Button=0
        Log("Test Button: ", State)
        DeviceTesting
    Else                      'Test Button=1
        Log("Test Button: ", State)
    End If
End Sub

Sub DeviceTesting 'Functionality tests of the equipment after pressing the small yellow test button
    'tests de fonctionnement des équipements après appui sur le petit bouton jaune de test
   
    For x = 1 To 2
        RedLights.DigitalWrite(True) 'Test the lights if installed - Test des feux si installés
        Lights.DigitalWrite(True)
        Log("lighting the lights") 'Allumage des feux
        FEUX = True 'lights on by default
        Delay(1000)
       
        Buzzer.DigitalWrite(True) 'Buzzer test if installed - Test du Buzzer si installé
        SON = True
        Log("Buzzer activation")
        Delay(1000)
       
        RedLights.DigitalWrite(False)
        Lights.DigitalWrite(False)
        FEUX = False 'lights off by default
        Log("Lights out") 'Extinction des feux
        Delay(1000)
       
        Buzzer.DigitalWrite(False)
        SON = False
        Log("Buzzer off") 'Arrêt du buzzer
        Delay(1000)
    Next
   
    'Tests on the steering controlled by the servomotor
    'Tests sur la direction commandée par le Servomoteur
   
    straight_Ahead
    Left_Turn
    Delay(2000)
    Right_Turn
    Delay(2000)
    straight_Ahead

    'Engine tests - Forward - Reverse
    'Test sur les moteurs - Marche avant - Marche arrière
   
    FastForward
    Delay(5000)
   
    Engines_Stop_Down
    Delay(2000)
   
    FastReverse
    Delay(5000)
   
    Engines_Stop_Down

End Sub 'End of equipment functional testing - Fin des tests de fonctionnement des équipements


Sub AStream_NewData (Buffer() As Byte)
    'The data transmitted from your Android smartphone via the B4A app using the Bluetooth connection
    'will be analyzed and converted into commands by the ARDUINO board and the B4R app.
    'Thus, the values of X are controlled from your smartphone.
    L= Buffer.Length
    If L = 1 Then X = Buffer(0)
    If L = 2 Then X = Buffer(0)
    If L = 5 Then X = Buffer(4)
    Log("Buffer: ", L ," bytes")
    Log("Value of X: ",X)
   
    Select X
       
        Case 0 'Stopping the car - Arrêt de la voiture
            Speed=0
            Envoi
           
        Case 2 'Front wheels aligned in a straight line
            ''Alignement des roues avant en ligne droite
       
            straight_Ahead
           
        Case 3 'Buzzer control if connected to pin 4
            'GESTION du Buzzer si connecté à la broche 4
            'If you are using the L298P Motor Driver Shield on your Arduino UNO board, the buzzer is built into pin D4.
            If SON = False Then
                Buzzer.DigitalWrite(True)
                SON = True
                Log("Déclenchement du Buzzer") 'Buzzer activation
            Else
                Buzzer.DigitalWrite(False)
                SON = False
                Log("Arrêt du Buzzer") ' Buzzer Off
            End If
           
        Case 4
            'Slight right turn - Rotation légère à droite
            Slight_Right_Turn
           
        Case 5
            'sharp rightward rotation - Rotation nette à droite
            Right_Turn
           
        Case 6
            'Slight left rotation - Rotation légère à gauche
            Slight_Left_Turn
                           
        Case 7
            'sharp leftward rotation - Rotation nette à gauche
            Left_Turn
           
               
        Case 8
            GrandHuit
           
        Case 9     ' GESTION des FEUX, LEDS, DIODES et lumières diverses si connectés
            'MANAGEMENT of LIGHTS, LEDs, DIODES and various other lights if connected
            If FEUX=False Then
                RedLights.DigitalWrite(True)
                Lights.DigitalWrite(True)
                FEUX = True
                   
            Else
                RedLights.DigitalWrite(False)
                Lights.DigitalWrite(False)
                FEUX = False
                Log("Extinction des LEDs") 'LEDs turned off
                'Extinction des LEDS si elles existent et ont été connectées
                'Turn off the LEDs if they exist and have been connected.
            End If
           
        Case 10
            Forward
            ' Forward - Marche avant
           
           
        Case 11
            FastForward
            ' fast forward movement of the car - MARCHE AVANT rapide de la voiture
           
        Case 12
            Reverse
            ' Reverse - Marche arrière
                   
        Case 13
            FastReverse
            'fast reverse - Marche arrière rapide
    End Select
End Sub

Sub GrandHuit
    'The car will perform the maneuvers on its own on a circuit several meters long,
    ' preferably outdoors
    ' La voiture va effectuer seule les manoeuvres sur un circuit de plusieurs mètres
    ' de préférence à l'extérieur
    straight_Ahead
    FastForward
    Delay(4000)
    For j=1 To 5
        Delay(4000)
        Right_Turn
        Delay(3000)
        straight_Ahead
        Delay(4000)
    Next
    For x=1 To 3 '3 headlight flashes + 3 buzzer sounds
        RedLights.DigitalWrite(True)
        Lights.DigitalWrite(True)
        Log("Allumage des feux") 'Lighting the lights
        FEUX = True
        Buzzer.DigitalWrite(True)
        SON = True
        Log("Déclenchement du Buzzer") 'Buzzer activation
        Delay(1000)
        RedLights.DigitalWrite(False)
        Lights.DigitalWrite(True)
        FEUX = False
        Log("Extinction des feux") 'Lights out
        Buzzer.DigitalWrite(False)
        SON = False
        Log("Arrêt du Buzzer") 'Buzzer off
        Delay(1000)
    Next
    Speed = 0
    Envoi
    'End of the circuit
End Sub
   
Sub straight_Ahead 'Front wheel alignment
    Log("The front wheels are aligned in a straight line")
    'Les roues avant sont alignées en ligne droite
    Angle = MonServo.Read
    If Angle < 90 Then
        For i = Angle To 90
            MonServo.Write(i)
            Delay(10)
        Next
    End If
    If Angle > 90 Then
        For i = Angle To 90 Step -1
            MonServo.Write(i)
            Delay(10)
        Next
    End If
End Sub

Sub Slight_Right_Turn
    'Slight right turn - Rotation légère à droite
    Log("Slight right turn")
    Angle = MonServo.Read
    If Angle < 110 Then
        For i = Angle To 110
            MonServo.Write(i)
            Delay(10)
        Next
    End If
    If Angle > 110 Then
        For i = Angle To 110 Step -1
            MonServo.Write(i)
            Delay(10)
        Next
    End If          
End Sub



Sub Right_Turn
    Log("sharp rightward rotation") 'Rotation nette à droite
    Angle = MonServo.Read
    If Angle < 125 Then
        For i = Angle To 125
            MonServo.Write(i)
            Delay(10)
        Next
    End If
    If Angle > 125 Then
        For i = Angle To 125 Step -1
            MonServo.Write(i)
            Delay(10)
        Next
    End If
End Sub

Sub Left_Turn
    Log("sharp leftward rotatione") ' Rotation nette à gauche
    Angle = MonServo.Read
    If Angle < 35 Then
        For i = Angle To 35
            MonServo.Write(i)
            Delay(10)
        Next
    End If
    If Angle > 35 Then
        For i  = Angle To 35 Step -1
            MonServo.Write(i)
            Delay(10)
        Next
    End If
End Sub

Sub Slight_Left_Turn
    Log("Slight left rotation") 'Rotation légère à gauche
    Angle = MonServo.Read
    If Angle < 70 Then
        For i = Angle To 70
            MonServo.Write(i)
            Delay(10)
        Next
    End If
    If Angle > 70 Then
        For i = Angle To 70 Step -1
            MonServo.Write(i)
            Delay(10)
        Next
    End If
End Sub

Sub Forward
    ENA.DigitalWrite(False)
    ENB.DigitalWrite(False)
    Speed = 100
    Envoi
    Log("Forward") ' Marche avant
End Sub

Sub FastForward
    ENA.DigitalWrite(False)
    ENB.DigitalWrite(False)
    Speed = 180
    Envoi
    Log("Fast Forward") ' Marche avant rapide
End Sub

Sub Engines_Stop_Down
    ENA.DigitalWrite(True)
    ENB.DigitalWrite(True)
    If FEUX = True Then
        RedLights.DigitalWrite(False)
        FEUX = False
    End If
    Speed = 0
    Envoi
    Log("Speed reset to zero")
    'Vitesse ramenée à 0
End Sub

Sub Reverse
    ENA.DigitalWrite(True)
    ENB.DigitalWrite(True)
    If FEUX = False Then
    RedLights.DigitalWrite(True)
    FEUX = True
    End If
    Speed = 90
    Envoi
    Log("Reverse") ' Marche arrière
End Sub

Sub FastReverse
    ENA.DigitalWrite(True)
    ENB.DigitalWrite(True)
    If FEUX = False Then
    RedLights.DigitalWrite(True)
    FEUX = True
    End If
    Speed = 110
    Envoi
    Log("Fast Reverse") ' Marche arrière rapide
End Sub




Private Sub Envoi 'Gestion vitesse de la voiture - Car speed management
    PWMA.analogWrite(Speed) ' Vitesse du moteur A - Motor A speed
    PWMB.analogWrite(Speed) ' Vitesse du moteur B - Motor B speed
    Log("Vitesse des moteurs: ",Speed)
End Sub
 

Attachments

  • ArduinoVehicle.zip
    3.5 KB · Views: 24
Last edited:

Marc DANIEL

Well-Known Member
Licensed User
The B4A app, which allows you to control this vehicle via the HC-05 Bluetooth module, remains unchanged; you can find it here >>> B4A app
 
Top