Parts for creating a robot using Arduino. Four-legged robot based on Arduino

Subscribe
Join the “koon.ru” community!
In contact with:

In today's article I will tell you how to make a robot that avoids obstacles based on an Arduino microcontroller with your own hands.



To make a robot at home, you will need the microcontroller board itself and an ultrasonic sensor. If the sensor detects an obstacle, the servo will allow it to go around the obstacle. By scanning the space to the right and left, the robot will choose the most preferable path to avoid the obstacle.

Codebender is a browser-based IDE, the easiest way to program your robot from the browser. You need to click on the “Run on Arduino” button and that’s it, it couldn’t be simpler.

Insert the battery into the compartment and press the function button once and the robot will start moving forward. To stop the movement, press the button again.

/* Arduino Obstacle Avoiding Robot with a servo motor and an ultrasonic sensor HC-SR04 LED and buzzer */ //Libraries #include #include "Ultrasonic.h" //Constants const int button = 2; //Button pin to pin 2 const int led = 3; //LED pin (via resistor) to pin 3 const int buzzer = 4; //Tweeter pin to pin 4 const int motorA1= 6; //positive (+) pin of motor A to pin 6 (PWM) (from module L298!) const int motorA2= 9; //negative pin (-) of motor A to pin 9 (PWM) const int motorB1=10; // positive (+) pin of motor B to pin 10 (PWM) const int motorB2=11; // negative pin (-) of motor B to pin 11 (PWM) Ultrasonic ultrasonic(A4 ,A5); //Create an object ultrasonic(trig pin,echo pin) Servo myservo; //Create a Servo object to control the servos //Variables int distance; //Variable for storing the distance to the object int checkRight; int checkLeft; int function=0; //Variable for storing the robot function: "1" - movement or "0" - stopped. Stopped by default int buttonState=0; //Variable to store the button state. Default "0" int pos=90; //variable to store the servo position. By default 90 degrees - the sensor will look forward int flag=0; //useful flag for storing the state of the button when the button is released void setup() ( myservo.attach(5); //The servo pin is connected to pin 5 myservo.write(pos); // tells the servo to go to the position in the variable " pos" pinMode(button, INPUT_PULLUP); pinMode(led, OUTPUT); pinMode(buzzer, OUTPUT); pinMode(motorA1,OUTPUT); pinMode(motorA2,OUTPUT); pinMode(motorB1, OUTPUT); pinMode(motorB2, OUTPUT) ; ) void loop() ( //Checking the button state buttonState = digitalRead(button); unsigned long currentMillis = millis(); //count... //Changes the main function (stopped/moving) when the button is pressed if (buttonState = = LOW) (//If the button is pressed once... delay(500); if (flag == 0)( function = 1; flag=1; //change the flag variable) else if (flag == 1)( / /If the button is pressed twice function = 0; flag=0; //change the flag variable again ) ) if (function == 0)( //If the button is released or pressed twice, then: myservo.write(90); //set for servo 90 degrees – the sensor will look forward stop(); //the robot remains motionless noTone(buzzer); //the beeper is turned off digitalWrite(led, HIGH);// and the diode is on ) else if (function == 1)(//If the button is pressed, then: //Read the distance... distance = ultrasonic.Ranging(CM); //Tip: Use "CM" for centimeters and "INC" for inches //Check for objects. .. if (distance > 10)( forward(); //Everything is clear, let's move forward! noTone(buzzer); digitalWrite(led,LOW); ) else if (distance<=10){ stop(); //Обнаружен объект! Останавливаемся и проверяем слева и справа лучший способ обхода! tone(buzzer,500); // издаём звук digitalWrite(led,HIGH); // включаем светодиод //Начинаем сканировать... for(pos = 0; pos =0; pos-=1){ //идём от 180 градусов к 0 myservo.write(pos); // говорим серво пройти на позицию в переменной "pos" delay(10); // ждём 10 мс, пока сервопривод достигнет нужной позиции } checkRight= ultrasonic.Ranging(CM); myservo.write(90); // Датчик снова смотрит вперёд //Принимаем решение – двигаться влево или вправо? if (checkLeft checkRight){ right(); delay(400); // задержка, меняем значение при необходимости, чтобы заставить робота повернуться. } else if (checkLeft <=10 && checkRight <=10){ backward(); //Дорога перекрыта... возвращаемся и идём налево;) left(); } } } } void forward(){ digitalWrite(motorA1, HIGH); digitalWrite(motorA2, LOW); digitalWrite(motorB1, HIGH); digitalWrite(motorB2, LOW); } void backward(){ digitalWrite(motorA1, LOW); digitalWrite(motorA2, HIGH); digitalWrite(motorB1, LOW); digitalWrite(motorB2, HIGH); } void left(){ digitalWrite(motorA1, HIGH); digitalWrite(motorA2, LOW); digitalWrite(motorB1, LOW); digitalWrite(motorB2, HIGH); } void right(){ digitalWrite(motorA1, LOW); digitalWrite(motorA2, HIGH); digitalWrite(motorB1, HIGH); digitalWrite(motorB2, LOW); } void stop(){ digitalWrite(motorA1, LOW); digitalWrite(motorA2, LOW); digitalWrite(motorB1, LOW); digitalWrite(motorB2, LOW); }

By clicking the "Edit" button, you can edit the sketch to suit your needs.

For example, by changing the value “10” of the measured distance to an obstacle in cm, you will decrease or increase the distance that the robot Arduino will scan in search of an obstacle.

If the robot does not move, it can change the contacts of the electric motors (motorA1 and motorA2 or motorB1 and motorB2).

Step 7: Completed Robot

Your homemade obstacle avoiding robot based on an Arduino microcontroller is ready.

People start learning Arduino by creating simple robots. Today I will talk about the simplest robot on Arduino Uno, which, like a dog, will follow your hand or any other object that reflects infrared light. This robot will also amuse the kids. My 3-year-old nephew eagerly played with the robot :)

I'll start by listing the parts that will be needed during construction - Arduino UNO;

Infrared rangefinders;

-3-volt motors with gearboxes and wheels;

- connectors for 3A batteries;

-battery (if there are not enough batteries);

-Relays to control the motors;

Well, and other materials that will be needed during the creation process.
First we make the base. I decided to make it out of wood. I sawed a wooden plank in such a way that the motors fit perfectly in the slots


Then I clamp the motors with a wooden strip, screwing this strip

Next on the body I placed an arduino, a relay, a Bradboard, rangefinders, and a rotating chassis under the base

Now we connect everything according to the diagram

At the end, upload the following sketch to the Arduino:

Const int R = 13; //pins to which IR rangefinders are connected const int L = 12; int motorL = 9; //pins to which the relay is connected int motorR = 11; int buttonState = 0; void setup() ( pinMode(R,INPUT); pinMode(L,INPUT); pinMode(motorR,OUTPUT); pinMode(motorL,OUTPUT); ) void loop() ( ( buttonState = digitalRead(L); if (buttonState == HIGH)( digitalWrite(motorR,HIGH); ) else ( digitalWrite(motorR,LOW); ) ) (( buttonState = digitalRead(R); if (buttonState == HIGH)( digitalWrite(motorL,HIGH); ) else ( digitalWrite(motorL,LOW); ) ) ) )

The principle of operation is very simple. The left rangefinder is responsible for the right wheel, and the right one for the left

To make it clearer, you can watch a video that shows the creation process and the operation of the robot

This robot is very simple and anyone can make it. It will help you understand the operating principles of modules such as relays and IR rangefinders and how best to use them.

I hope you liked this craft, remember that crafts are cool!

Hi all. This article is a short story about how do robot their hands. Why a story, you ask? This is due to the fact that for the manufacture of such crafts it is necessary to use a significant amount of knowledge, which is very difficult to present in one article. We'll walk through the build process, take a peek at the code, and ultimately bring a Silicon Valley creation to life. I advise you to watch the video to get an idea of ​​what you should end up with.

Before moving on, please note the following: during manufacturing crafts a laser cutter was used. You can avoid using a laser cutter if you have enough experience working with your hands. Precision is the key to completing the project successfully!

Step 1: How does it work?

The robot has 4 legs, with 3 servos on each of them, which allow it to move its limbs in 3 degrees of freedom. He moves with a “crawling gait.” It may be slow, but it is one of the smoothest.

First, you need to teach the robot to move forward, backward, left and right, then add an ultrasonic sensor, which will help detect obstacles/obstacles, and then a Bluetooth module, thanks to which control of the robot will reach a new level.

Step 2: Necessary Parts

Skeleton made of plexiglass 2 mm thick.

The electronic part of the homemade product will consist of:

  • 12 servos;
  • arduino nano (can be replaced with any other arduino board);

  • Shield for controlling servos;
  • power supply (in the project a 5V 4A power supply was used);

  • ultrasonic sensor;
  • hc 05 bluetooth module;

In order to make a shield you will need:

  • circuit board (preferably with common lines (buses) of power and ground);
  • inter-board pin connectors - 30 pcs;
  • sockets per board – 36 pcs;

  • wires.

Tools:

  • Laser cutter (or skilled hands);
  • Super glue;
  • Hot melt adhesive.

Step 3: Skeleton

Let's use a graphics program to draw the components of the skeleton.

After that, we cut out 30 parts of the future robot using any available method.

Step 4: Assembly

After cutting, remove the protective paper covering from the plexiglass.

Next we start assembling the legs. Fastening elements built into parts of the skeleton. All that remains to be done is to connect the parts together. The connection is quite tight, but for greater reliability you can apply a drop of superglue to the fastening elements.

Then you need to modify the servos (glue a screw opposite the servo shafts).

With this modification we will make the robot more stable. Only 8 servos need to be modified; the remaining 4 will be attached directly to the body.

We attach the legs to the connecting element (a curved part), and this, in turn, to the servo drive on the body.

Step 5: Making the shield

Making the board is quite simple if you follow the photographs presented in the step.

Step 6: Electronics

Let's attach the servo drive pins to the arduino board. The pins must be connected in the correct sequence, otherwise nothing will work!

Step 7: Programming

It's time to bring Frankenstein to life. First, let's load the legs_init program and make sure that the robot is in the position as in the picture. Next, let's load quattro_test to check if the robot responds to basic movements, such as moving forward, backward, left and right.

IMPORTANT: You need to add an additional library to the arduino IDE. The link to the library is provided below:

The robot must take 5 steps forward, 5 steps back, turn left 90 degrees, turn right 90 degrees. If Frankenstein does everything right, we're moving in the right direction.

P. S: Place the robot on the cup, like on a stand, so that you don’t have to put it at the starting point every time. Once the tests have shown the robot is working normally, we can continue testing by placing it on the ground/floor.

Step 8: Inverse Kinematics

Inverse kinematics is what actually drives the robot (if you are not interested in the math side of this project and are in a hurry to finish the project, you can skip this step, but knowing what drives the robot will always be useful).

In simple terms, inverse kinematics, or IR for short, is the “part” of trigonometric equations that determine the position of the sharp end of the leg, the angle of each servo, etc., which ultimately determine a couple of preliminary settings. For example, the length of each step of the robot or the height at which the body will be located during movement/rest. Using these predefined parameters, the system will extract the amount by which each servo should be moved in order to control the robot using the given commands.

The result is a rather funny robot that can see obstacles in front of it, analyze the situation and then, only having chosen the best route, moves on. The robot turned out to be very maneuverable. It is capable of turning 180 degrees, and the rotation angle is 45 and 90 degrees. The author used Iteaduino, which is an analogue of Arduino, as the main controller.

Materials and tools for making a robot:
- microcontroller (Arduino or similar Iteaduino);
- ultrasonic sensor;
- battery holder;
- Chinese toys for creating a wheelbase (you can buy a ready-made one);
- wire cutters;
- glue;
- wires;
- motors;
- fiberboard;
- jigsaw;
- transistors (D882 P).

Robot manufacturing process:

Step one. Creating a wheelbase
In order to create a wheelbase, the author bought two Chinese toy cars. However, you don’t have to worry about this if you have extra money, since you can buy a ready-made base. Using wire cutters, the cars were cut in two to create two drive axles. These parts were then glued together. However, in this case you can also use a soldering iron; the plastic can be soldered perfectly.

When choosing cars, it is best to take toys with regular wheels, since, according to the author, with spikes like his, the robot jumps a lot.

There is another moment when wires will come out from the motors; on one of them you need to remember to change the polarity.


Step two. Making the top cover
The top cover of the robot is made of fiberboard; thick cardboard can also be used for these purposes. You can see a rectangular hole in the cover; it should be located so that the axis of the servo drive, which will be inserted into it, is located symmetrically. As for the hole in the middle, the wires will come out through it.


Step three. Robot stuffing
It is best to use a separate power supply to connect the chassis, since the controller requires 9V to power it, while the motors only need 3V. In general, battery holders are already built into the chassis of such machines; they just need to be connected in parallel.








The motors are connected to the controller using D882 P type transistors. They were pulled out from the old machine control panel. It is best, of course, to use power transistors of the TIP120B type, but the author simply chose them based on suitable characteristics. All electronic parts are connected according to the specified diagram.

After flashing the robot's firmware, it will be ready for testing. In order for the robot to have time to turn at a certain angle, you need to choose the right operating time for the motors.

As for sensors, the ultrasonic one needs to be connected to the 7th digital output of the microcontroller. The servo motor is connected to the 3rd digital input, the base of the transistor of the left motor is connected to pin 11, and the base of the right one is connected to the 10th.

If Krona is used as power supply, then the minus is connected to GND, and the plus to VIN. You also need to connect the emitter of the transistor and the negative contact from the robot chassis power supply to GND.

Our dear readers, we are opening a series of articles dedicated to creating a robot based on Arduino. It is assumed that the reader is a beginner and has only basic knowledge of the subject. We will try to present everything as detailed and clear as possible.

So, an introduction to the problem:

Let's start with the concept: we want a robot that can independently move around the room, while avoiding all obstacles encountered along the way. The task was set.

Now let's figure out what we need:

  1. Platform (body). There are options here: do everything yourself, buy parts and assemble them, or buy ready-made ones. Choose whatever you like

The kit usually includes a platform and one motor for two driving wheels (caterpillar) and a compartment for batteries. There are all-wheel drive options - with a motor for 4 wheels. For beginners, we recommend taking tank-type platforms

Two driving wheels and a third support wheel.

  1. Next, we need a rangefinder. Sonar (aka rangefinder, aka Ultrasonic module) As a rangefinder, initially the choice was between ultrasonic and infrared. Since the ultrasonic characteristics are significantly better (maximum range is about 4-5 meters, versus 30-60 cm), and the price is approximately the same, the choice fell on Ultrasonic. The most common model is HC-SR04.

  1. Motor Driver.

What should I do? The first thing that comes to mind is to put a transistor at the output of the microcontroller and power the motors from it. This is good, of course, but it won’t work if we want to turn the motor in the other direction... But the H-bridge, which is a slightly more complex circuit than a pair of transistors, will cope well with this task. But in this case there are plenty of them in the form of ready-made integrated circuits, so I think there is no need to reinvent the wheel - we’ll buy a ready-made one. In addition, the price is 2-3 dollars... Let's move on. For these purposes, we will buy an L293D chip, or, even better, a Motor Shield based on it.

Motor shield on L298N chip

  1. Sound generation - piezo emitter

The simplest option for generating sound is to use a piezo emitter.

Piezoceramic emitters (piezo emitters) are electroacoustic sound reproduction devices that use the piezoelectric effect. (the effect of polarization of a dielectric under the influence of mechanical stresses (direct piezoelectric effect). There is also an inverse piezoelectric effect - the occurrence of mechanical deformations under the influence of an electric field.

Direct piezoelectric effect: in piezo lighters, to obtain high voltage across the spark gap;

Reverse piezoelectric effect: in piezo emitters (effective at high frequencies and have small dimensions);)

Piezo emitters are widely used in various electronic devices - alarm clocks, telephones, electronic toys, and household appliances. A piezoceramic emitter consists of a metal plate on which a layer of piezoelectric ceramics is applied, which has a conductive coating on the outside. The plate and the spray are two contacts. The piezo emitter can also be used as a piezoelectric microphone or sensor.

That's all we need at first. First, let's look at how to assemble and make these parts work individually in separate lessons.

Lesson 2. Working with an ultrasonic distance measuring sensor (range finder)

Lesson 3. Arduino and Motor Shield based on L298N

Lesson 4. Sound reproduction - piezo emitter

Lesson 5. Assembling the robot and debugging the program

Return

×
Join the “koon.ru” community!
In contact with:
I am already subscribed to the community “koon.ru”