This project is sponsored by JLCPCB - Printed Circuit Board Factory.
Introduction
Every person who decides to enter the world of robotics with Arduino has great challenges.
One of these challenges is to start with some simple application and something that you can see working in practice during the learning classes.
That way, it is possible to learn in a practical way and absorb knowledge much faster.
It was for this reason that we decided to develop the ArduinoRobot Ludos.
Next, we will present the Arduino Robot Ludos and the details of its structure.
What is Arduino Ludos Robot?
It was created for the purpose of allowing you, who is a beginner or teacher, and doesn’t have an easily accessible robot, can use a simple robotic kit, with varied features and that helps you make your class more didactic and practical.
In addition, he proposes to:
- facilitate the first contacts with the robot assembly;
- allow it to be a simple and creative application.
All of this will facilitate the assembly of your first robot and allow you and your student to use its various resources with the Arduino.
As you can see in Figure 2, the Robot Ludos has the shape of a cube. It allows you to use an Arduino or other control, boards to create your project.
In addition, it has the following components in its structure:
- 01 x Button;
- 01 x 16x2 LCD screen;
- 02 x Red LEDs;
- 01 x Ultrasonic Sensor.
In addition to these components, you can take advantage of the internal space and make use of several other modules and sensors to develop other projects.
Our goal is to allow you to build different types of projects and experiences with this kit. It has few parts, easy to assemble, and several features in a single robot.
The following is a complete view of the Ludos Robot in different views.
Now, we will develop a project with Robot Ludos. We will develop an ultrasonic ruler with the Robot Ludos. If you want to access the complete Arduino Robot Ludos documentation and download yours, visit this Arduino Robot Ludos documentation.
Developing the Ultrasonic Ruler with Robot Ludos
For this project, we will use 3 resources of the Robot Ludos: the button, the ultrasonic sensor, and the 16x2 LCD display.
Following we'll present the project that will be developed.
Develop an ultrasonic ruler with the Arduino Robot Ludos. Every time the button is pressed, the robot must calculate the distance with the ultrasonic sensor and present its value on the 16x2 LCD display.
For this project, we'll use the JLCPCB Arduino Compatible printed circuit board presented below.
You can obtain the Arduino JLCPCB compatible PCB for your projects for $2 in your first order with the link: Earn my PCBs Arduino Compatible.
Below, we present the full electronic schematic of the project.
Now, we'll show the full code of this project.
#include <LiquidCrystal_I2C.h> //Biblioteca I2C do LCD 16x2 #include <Wire.h> //Biblioteca de Comunicacao I2C LiquidCrystal_I2C lcd(0x27,16,2); // Configurando o endereco do LCD 16x2 para 0x27 #define botao 3 #define echoPin 9 #define trigPin 8 long tempo = 0; int distancia = 0; bool BotaoCabeca = 0, estado = 0; void setup() { pinMode(botao, INPUT); pinMode(echoPin, INPUT); pinMode(trigPin, OUTPUT); Wire.begin(); //Inicializacao da Comunicacao I2C lcd.init(); //Inicializacao do LCD lcd.backlight(); lcd.setCursor(2,0); lcd.print("Oi, eu sou o"); lcd.setCursor(3,1); lcd.print("Robo Ludos!"); delay(2000); } void loop() { BotaoCabeca = digitalRead(botao); if(BotaoCabeca == 1 && estado == 0) { lcd.clear(); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); tempo = pulseIn(echoPin, HIGH); distancia = tempo * (0.034/2); if(distancia <= 65) { digitalWrite(4, LOW); digitalWrite(5, LOW); } if(distancia > 65) { digitalWrite(4, HIGH); digitalWrite(5, HIGH); lcd.print(""); } lcd.setCursor(0,0); lcd.print("Distancia:"); lcd.setCursor(0,1); lcd.print(distancia); lcd.setCursor(3,1); lcd.print("cm"); estado = 1; } if(BotaoCabeca == 0 && estado == 1) { estado = 0; } }
In the first part of the Arduino robot code, we do the declaration of libraries, name definitions, and declaration of variables.
#include <LiquidCrystal_I2C.h> //Biblioteca I2C do LCD 16x2 #include <Wire.h> //Biblioteca de Comunicacao I2C LiquidCrystal_I2C lcd(0x27,16,2); // Configurando o endereco do LCD 16x2 para 0x27 #define botao 3 #define echoPin 9 #define trigPin 8 long tempo = 0; int distancia = 0; bool BotaoCabeca = 0, estado = 0;
After this, we'll enter the void setup function.
void setup() { pinMode(botao, INPUT); pinMode(echoPin, INPUT); pinMode(trigPin, OUTPUT); Wire.begin(); //Inicializacao da Comunicacao I2C lcd.init(); //Inicializacao do LCD lcd.backlight(); lcd.setCursor(2,0); lcd.print("Oi, eu sou o"); lcd.setCursor(3,1); lcd.print("Robo Ludos!"); delay(2000); }
Firstly, the button pin and sensor pin are configured like digital input and output. After, we have the Wire and LCD initialization, and the message printed in LCD of the Arduino Robot Ludos: "Hello, I'm Ludos Robot" in Portuguese for 2 seconds.
After that, it will enter the void loop function and wait for the moment when the user presses the button in the Arduino robot Ludos.
void loop() { BotaoCabeca = digitalRead(botao); if(BotaoCabeca == 1 && estado == 0) { lcd.clear(); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); tempo = pulseIn(echoPin, HIGH); distancia = tempo * (0.034/2); if(distancia <= 65) { digitalWrite(4, LOW); digitalWrite(5, LOW); } if(distancia > 65) { digitalWrite(4, HIGH); digitalWrite(5, HIGH); lcd.print(""); } lcd.setCursor(0,0); lcd.print("Distancia:"); lcd.setCursor(0,1); lcd.print(distancia); lcd.setCursor(3,1); lcd.print("cm"); estado = 1; } if(BotaoCabeca == 0 && estado == 1) { estado = 0; } }
Initially, we read the button on the Arduino robot Ludos.
BotaoCabeca = digitalRead(botao);
In the condition below, the condition checks whether the button is pressed and was previously deactivated.
if(BotaoCabeca == 1 && estado == 0)
If this is true the system will trigger the ultrasonic sensor and measure the distance between the Arduino robot ludos and some object that is in front of you.
lcd.clear(); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); tempo = pulseIn(echoPin, HIGH);
After the trip, the system will store the time that the echo pin passed at a high logic level in the tempo variable.
tempo = pulseIn(echoPin, HIGH);
With the calculated time and the speed of sound propagation through the air, which is 340 m/s, we can calculate the distance using the average speed formula.
distancia = tempo * (0.034/2);
From the above equation, we have the calculated distance between the Arduino robot Ludos and the object.
Then the system checks whether the distance is greater than or less than 65. If the value is greater, the LEDs will be on. Otherwise, the LEDs will be turned off.
In the following figure, we present the Arduino Robot Ludos showing the distance value of 59 cm and with the LEDs off.
Did you see how interesting it is to develop projects with Arduino Robot Ludos?
As already mentioned, you can create other projects and ideas from the assembly structure of Arduino Robot Ludos.
Conclusions & Acknowledgments
We appreciate the support and partnership of the company JLCPCB for providing us with printed circuit boards to develop the Arduino Robot Ludos project.