The experience of creating the first robot at Arduino (robot "hunter")


    In this article I want to describe the process of assembling my first arduino robot. The material will be useful to other newcomers, just like me, who will want to make some kind of "self-running trolley." The article is a description of the stages of working with my additions on various nuances. The link to the final code (most likely not the most ideal) is given at the end of the article.

    As far as possible I attracted my son (8 years) to participate. What exactly happened to him, and what not - I singled out a part of the article for this, perhaps, someone will come in handy.

    General description of the robot

    First, a few words about the robot itself ( idea ). I didn’t really want to collect something typical at the start. At the same time, the set of components was fairly standard - chassis, engines, ultrasonic sensor, line sensor, LEDs, squeaker. First, a robot was created from this “soup set” that guards its territory. He rides on the intruder, who crossed the line of the circle, and then returns to the center. However, in this version, a drawn line was needed, plus extra math to stay in the circle.

    Therefore, after some deliberation, I somewhat changed the idea and decided to make a “hunter” robot. At the start, he turns around his axis, choosing a target (person) nearby. If the "victim" is found, the "hunter" turns on the flasher and siren, and begins to go on it. When a person moves away / runs off, the robot selects a new target and pursues it, and so on. Such a robot does not need a limited circle, and it can work in an open area.

    As you can see, this is a lot like a catch-up game. Although in the end, the robot did not turn out to be quite frisky, but it honestly interacts with the people around it. Children especially like it (sometimes, it is true, it seems that they are about to crush it, as much as your heart beats ...). I think for the promotion of technical design is a good solution.

    Structure of the robot

    So, we decided on the idea, move on to the layout . The list of elements is formed from what the robot should be able to do. Everything is quite obvious here, so let's take a quick look at the numbering: The

    “brains” of the robot are the arduino uno (1) board; Was in the set ordered from China. For our purposes, it is quite enough (focusing on the number of pins used). From the same set we took the finished chassis (2), on which two driving wheels (3) and one rear (freely rotating) (4) are mounted. Also in the set was a ready battery compartment (5). The robot has an ultrasonic sensor (HC-SR04) (6) in front, an engine driver (L298N) (7) at the rear, a LED flasher (8) in the center, and a little squeaker (9).

    At the layout stage, we look at:

    - so that everything fits
    - so that it is balanced
    - so that it would be rationally located.

    In part, the Chinese colleagues have already done this for us. Thus, the heavy battery compartment is placed in the center, and drive wheels are located approximately below it. All other boards are light, they can be placed on the periphery.


    1. In the chassis of the set there are many factory openings, but what is the logic in them - I never figured it out. The engines and the battery pack were fixed without problems, then the “fit” began with the drilling of new holes to fix this or that board.
    2. The brass pillars and other fasteners from the storerooms came to the rescue (sometimes they had to be twisted).
    3. Tires from each board passed through the clamps (again found in the vaults). Very convenient, all the wires are beautiful and do not hang out.

    Individual blocks

    Now I will go through the blocks and tell personally about each.

    Battery compartment

    It is clear that the robot must have a good source of energy. The options may be different, I chose the version with 4 AA batteries. In total, they give about 5 V, and this voltage can be directly applied to the pin 5V of the arduino board (bypassing the stabilizer).

    Of course, I had some wariness, but this solution is quite workable.

    Since power is needed everywhere, for convenience, I made two connectors in the center of the robot: one “distributes” the ground (on the right), and the second - 5 V (on the left).

    Engines and driver

    First, about the engine mount. Fastening factory, but made with large tolerances. In other words, engines can "wobble" a couple of millimeters left-right. For our task, this is not critical, but somewhere it may influence (the robot will begin to be diverted). Just in case, I put the engines strictly parallel and fixed with glue.

    To control the engines, as I wrote above, the driver L298N is used. According to the documentation, he has three pins for each engine: one for changing the speed and a pair of pins for the direction of rotation. There is one important point. It turns out that if the supply voltage is 5 V, then the speed control simply does not work! That is, it either does not twist at all, or twists to the maximum. This is the feature that caused me to “kill” a couple of evenings. In the end, found a mention somewhere on one of the forums.

    Generally speaking, I needed a low rotational speed when the robot turned around - so that it had enough time to scan the space. But, since with this idea nothing happened, we had to do it differently: a small turn - stop - turn - stop, etc. Again, not so elegant, but workable.

    Still here I will add that after each pursuit the robot chooses a random direction of a new turn (clockwise or counterclockwise).

    Ultrasonic sensor

    Another piece of iron where I had to find a compromise solution. Ultrasonic sensor on real obstacles gives unstable numbers. Actually, it was expected. Ideally, it works somewhere in competitions, where there are smooth, even and perpendicular surfaces, but if someone's feet “flash” in front of him, then additional treatment should be introduced.

    As such processing, I put the median filter on three counts. Based on tests on real children (during the tests, no child was hurt!), It was quite enough to normalize the data. The physics here is simple: we have the signals reflected from the needed ones.objects (giving the required distance) and reflected from more distant, for example, walls. The latter are random outliers in measurements of the form 45, 46, 230 , 46, 46, 45, 45, 310 , 46 ... It is their median filter that cuts off.

    After all the processing, we get the distance to the nearest object. If it is less than a certain threshold value - then we turn on the alarm and go straight to the "offender".

    Flasher and siren

    Perhaps the simplest elements of all of the above. They can be seen in the photos above. There is nothing to write about the hardware here, so now let's move on to the code .

    Management program

    I don't see the meaning of the code in detail, who needs it - the link is at the end of the article, everything is quite readable there. But the general structure would be nice to explain.

    The first thing that had to be understood was that a robot is a real-time device. More precisely, to remember, because I still do electronics before and now. So, we immediately forget about the call delay () , which they like to use in example sketches, and which simply “freezes” the program for a specified period of time. Instead, as advised by experienced people, we introduce timers for each block. Passed the required period - performed the action (increased the brightness of the LED, turned on the engine and so on).

    Timers can be interconnected. For example, the squeaker works synchronously with the flasher. This slightly simplifies the program.

    Naturally, everything is divided into separate functions (flasher, sound, turn, movement forward and so on). If you do not do this, then you can’t figure out what comes from where or where.

    Nuances of pedagogy

    All that was described above, I did in my free time in the evenings. In a slow mode, I spent about three weeks on the robot. This could be the end, but I still promised to tell you about working with the child. What is doable at that age?

    Work on the instructions.

    We first checked each part separately - LEDs, beeper, motors, sensors, etc. There are a large number of ready-made examples - some right in the development environment, others can be found on the Internet. This undoubtedly pleases. We take the code, we connect the part, we are convinced that it works, then we are already starting to change for our task. Connections under the scheme and under some of my control the child makes himself. It's good. Work well according to the instructions, too, must be able to.

    The order of work ("from the particular to the general")

    This is a difficult item. It is necessary to teach that a big project (“make a robot”) consists of small tasks (“connect a sensor”, “connect motors” ...), and those in turn from even smaller steps (“find a program”, “ connect fee "," download firmware "...). In carrying out more or less understandable tasks of the lower level, we “close” the tasks of the average level, and of them the general result is already taking shape. I explained, but, I think, awareness will not come soon. Somewhere, probably, to adolescence.


    Drilling, threads, screws, nuts, soldering and the smell of rosin - where do without it. The child received the basic skill "Working with a soldering iron" - it was possible to solder several connections (I helped a little, I will not hide it). Do not forget the explanation of safety.

    Computer work

    I wrote the program for the robot, but I managed to achieve some kind of passing results.

    First: English. At school, he was just started, so we sorted out what is pishalka, migalka, yarkost and other transliteration. Understood at least this. I deliberately did not use my native English words, since we had not yet reached this level.

    Second: effective work. They learned hot key combinations how to quickly perform typical operations. Periodically, when we wrote the program, we changed places with the son, and I said that we need to do (replacement, search, etc.). We had to repeat again and again: “select with a double click”, “hold Shift”, “hold Ctrl” and so on. The learning process is not fast here, but I think the skills will gradually be deposited "in the subcortex".

    Hidden text
    Вы можете сказать, что описанное выше — это почти очевидно. Но, честно, этой осенью мне довелось вести информатику в 9-х классах в одной школе. Это ужас. Ученики не знают таких элементарных вещей, как Ctrl + Z, Ctrl + C и Ctrl + V, выделения текста с зажатым Shift-ом или двойным кликом на слове и прочего. Это при том, что у них шел третий год обучения информатике… Вывод сделайте сами.

    Third: blind printing. Comments in the code I trusted to print to the child (let it train). Immediately put the right hands, so that the fingers gradually memorized the location of the keys.

    As you can see, we are still just beginning. Skills and knowledge will hone further, in life will be useful.

    By the way, about the perspective ...

    Further development

    The robot is made, goes, flashes and beeps. What now? Inspired by what we have achieved, we plan to refine it further. There is an idea to make a remote control - like a lunar rover. It would be interesting, sitting at a conventional panel, to control the movement of a robot that travels in a completely different place. But it will be a separate story ...

    And at the end, in fact, the heroes of this article (click-through video): Thank you for your attention! → Link to code

    Also popular now: