Are you interested in using the Arduino to control a wheeled robot? I'm sure that at some point, you wanted to control your own robot. However, there is always a big problem: I don't have a robot with wheels. How do I test my programming control logic?

I, too, always asked myself this question, when I didn't own my own robot. It was for this reason that I built the Printed Circuit Board Robot Car with the JLCPCB Company.

Figure 1 - JLCPCB Robot Car Printed Circuit Board.

Figure 1 - JLCPCB Robot Car Printed Circuit Board.

Next, we will present the complete structure to build the Arduino-controlled PCB Robot Car project.

Developing the JLCPCB Robot Car with Arduino

The JLCPCB Robot Car was developed with 8 LED's and an ultrasonic sensor to detect obstacles. As you can see, the 2 blue LEDs are used to represent the robot's wheels.

In addition, we have 2 red LEDs in each rear view mirror and 4 lighting LEDs on the front of the car.

With these 8 LEDs, we can do several types of simulations. Through them, you can, for example, signal the movement forward, backward, left, and right.

In addition, activate some LEDs when the object is very close to the car.

Did you like the possibilities of things that are possible to do with the JLCPCB Robot Car? If you liked it, let's understand how to build our own JLCPCB Robot Car with Arduino.

Figure 2 - Electronic Schematic of the Project.

Figure 2 - Electronic Schematic of the Project.

The schematic above shows the connection structure of the circuit elements of the electronic board.

From this electronic scheme, the electronic board was developed. The electronic structure of the board is shown below.

Figure 3 - Printed Circuit Board without electronic components.

Figure 3 - Printed Circuit Board without electronic components.

The structure of the board is quite simple and allows it to be connected to a protoboard.

In addition, there are holes that allow the attachment of the ultrasonic sensor to the rear of the JLCPCB Robot Car.

From there, you will learn how to create logic and use your JLCPCB Robot Car with Arduino.

For this, we will solve the following problem:

Draw up a project to deflect the JLCPCB Robot Car with Arduino when it detects an obstacle. The robot must turn to the right, activate the rearview LED and continue after it is out of the obstacle.

Now, let's get our hands dirty and develop this project.

Development of the JLCPCB Robot Car with Arduino

First, we must build the circuit in the figure below. This circuit is formed by the sensor and the LEDs of the car with wheel and headlight.

Figure 4 - Electronic Circuit in TinkerCAD Software.

Figure 4 - Electronic Circuit in TinkerCAD Software.

From this circuit, the programming logic below was created. This logic is intended to simulate the diversion of the car from any obstacle. If the car is less than 30 cm from the obstacle, the car must turn on the LEDs and start the engines, so that it can change direction.

The LED's will turn off when the vehicle moves away from the object, that is, when the distance is greater than 30 cm.

#define echoPin 9 #define trigPin 8

long time = 0;
int measure = 0;

void setup()
{
  pinMode(2, OUTPUT);  pinMode(3, OUTPUT);  pinMode(4, OUTPUT);  pinMode(5, OUTPUT);    pinMode(trigPin, OUTPUT);  pinMode(echoPin, INPUT);

}

void loop() {
  digitalWrite(trigPin, LOW);  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);  delayMicroseconds(10);  digitalWrite(trigPin, LOW);
  time = pulseIn(echoPin, HIGH);
  measure = time * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
	  if(measure <= 30)  {    digitalWrite(4, HIGH);    digitalWrite(5, HIGH);    digitalWrite(2, HIGH);    digitalWrite(3, LOW);  }    if(measure > 30)  {    digitalWrite(2, HIGH);    digitalWrite(3, HIGH);        digitalWrite(4, LOW);    digitalWrite(5, LOW);    digitalWrite(3, LOW);    digitalWrite(2, LOW);  }

}

The operation of the program is quite simple.

Initially, names for the ultrasonic sensor connection pins were declared and, also, the program variables were declared. The code portion is shown below.

#define echoPin 9 #define trigPin 8

long time = 0;
int measure = 0;

Next, we declare the void setup function. This function is used to configure the pins as inputs and outputs for the LEDs and pins of the ultrasonic sensor. The code portion is shown below.

void setup()
{
  pinMode(2, OUTPUT);  pinMode(3, OUTPUT);  pinMode(4, OUTPUT);  pinMode(5, OUTPUT);    pinMode(trigPin, OUTPUT);  pinMode(echoPin, INPUT);

}

After that, we enter the loop function. First, we trigger the sensor's trig and store the time the signal went and returned in the time variable. The code portion is shown below.

  digitalWrite(trigPin, LOW);  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);  delayMicroseconds(10);  digitalWrite(trigPin, LOW);
  time = pulseIn(echoPin, HIGH);

After calculating the time, we must calculate the distance. The distance is calculated using the equation below.

  measure = time * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)

We calculate the distance from the average speed of sound propagation through the air, which is 340 m/s.

We divide it by 2, because we only need the distance to or from the wave since the calculated time is equivalent to the time to go and return the sound through the air.

Finally, we will check the distance range the robot is at any obstacle. If the distance is less than or equal to 30, drive one of the wheels and turn on the two LEDs, to indicate that it is making the turning movement.

The figure below presents the LEDs.

Figure 5 - Electronic circuit when car is detecting obstacle.

Figure 5 - Electronic circuit when car is detecting obstacle.

After that, we have the second condition. The second condition checks whether the distance value is greater than 30. If this is true, the two motors (blue LEDs) are turned on and the headlight LEDs are turned off.

This can be seen in the figure below.

Figure 6 - Electronic circuit when car is not detecting obstacle.

Figure 6 - Electronic circuit when car is not detecting obstacle.

Finally, after the last check, the code flow goes back to the beginning and everything starts running again.

This project was developed with JLCPCB and you can download this file in the topic below.

Files for download of the project

All files are in attachment section below.

Acknowledgments

We appreciate the support and partnership of JLCPCB to produce the project with low cost and accessibility.

Access this link, download the files and access your project at JLCPCB.