Arduino. The project "Robot car RoboCar4W"

 3r3998. 3r3-31. 3r33985.
You understand, ”the editor explained,“ it must be entertaining, fresh, full of interesting adventures So that the reader could not tear himself away.
3r33983.  3r3998. I. Ilf, E. Petrov 3-333200. "How Robinson was created"
. 3r33987. 3r33983.  3r3998. 3r33985. Getting started with Arduino, as with any other software or hardware platform, is always more interesting from a real project. At the same time, programmers write code that displays “Hello, world”, arduinists blink an LED. And everyone is happy as children. 3r33987. 3r33983.  3r3998. 3r33985. I decided to start with an advanced project, including with the secret hope of tearing the younger generation from Counter-Strike (it did not work). 3r33987. 3r33983.  3r3998. 3r33985. As you can guess from the name RoboCar4W, the first project was a robot machine about four wheels. Starting work, I already had programming experience, I was once able to solder, but I didn’t even know the Arduino pinouts and didn’t read the documentation at all. All the wisdom studied in the course of the play and Google to help. 3r33987. RoboCar4W-1.ino . 3r33987. 3r33983.  3r3998. 3r3144.  3r3998. 3r33869. Measure the distance to the obstacle ahead. 3r33838.  3r3998. 3r33869. If this measured distance is less than DST_TRH_BACK (short for distance threshold), then we stop and drive in reverse while turning. The direction of rotation is chosen as follows: if you have previously turned left, then turn right and vice versa. 3r33838.  3r3998. 3r33869. If the measured distance is more than DST_TRH_BACK but less than 3r3952. DST_TRH_TURN then just turn around. The direction of rotation is chosen randomly. 3r33838.  3r3998. 3r33869. If the obstacle is far away, then just go ahead. 3r33838.  3r3998. 3r33869. Repeat all over again. 3r33838.  3r3998. 3r3167. 3r33983.  3r3998. 3r33985. What good is that we have 4 wheels and all the leading? We can perform (program) several types of turns:
3r33983.  3r3998. 3r33855.  3r3998. 3r33869. Smooth turn. All wheels rotate, but the wheels on the one hand rotate faster. 3r33838.  3r3998. 3r33869. Sharp turn. Wheels rotate on one side only. 3r33838.  3r3998. 3r33869. Turn on the spot. Like a tractor, the wheels of one side rotate back and the other - forward. 3r33838.  3r3998.
3r33983.  3r3998. 3r33985. In the second version of the program, when operating from an Android phone, safe mode, when the robot tries to prevent frontal collisions, can be disabled if the program presses the button 3r38383 twice.  3r3998. 3r3191. 3r33987. 3r33983.  3r3998. 3r33985. and turned it back on by pressing it once. 3r33987. 3r33983.  3r3998. 3r33985.
Important note
. All logic is controlled by Arduino. Android here simply acts as a gaming console (without brains) from the console, its task is to stupidly transmit button presses (i.e. commands) via Bluetooth to the Arduino RoboCar4W. 3r33987. 3r33983.  3r3998.
Components
3r33983.  3r3998. 3r33985. Initially, the machine included a servo drive, which turned the ultrasonic distance meter at a certain angle for measurements in three directions. But during the tests, due to careless handling, the servo burned down, so now the distance sensor is simply rigidly fixed in front of the case. 3r33987. 3r33983.  3r3998. 3r33985. Every cloud has a silver lining, but the sketch has become a little easier. 3r33987. 3r33983.  3r3998. 3r33985. For the future, buy the servo the simplest and cheapest, special power, speed and accuracy of rotation at a given angle are not needed, and it is quite easy to turn the servo out of order, as it turned out. A SG90 worth $ 2 is fine. 3r33987. 3r33983.  3r3998. 3r33985. So the components of the project RoboCar4W, the description in English is given to facilitate the search on ebay and others like it:
3r33983.  3r3998. 3r33855.  3r3998. 3r33869. Arduino UNO R3
 3r3998. 3r33869. Ready chassis 4 Wheel Drive Mobile Arduino Compatible Smart Car Chassis Platform Smart
 3r3998. 3r33869. DC motors (DC) with rotation in both directions - 4 pcs. 3r33838.  3r3998. 3r33869. Wheels - 4 pcs. 3r33838.  3r3998. 3r33869. Board to control 4 DC Motor Drive Shield L293D motors
 3r3998. 3r33869. Ultrasonic Module Distance Measuring Sensor HC-SR04 3s3r3870.  3r3998. 3r33869. Ni-MH 1.2 V batteries - 8 pcs. 3r33838.  3r3998. 3r33869. Plastic battery box holder, Battery Box holder 4 AA Batteries - 2 pcs. 3r33838.  3r3998. 3r33869. Battery type "Krona" 8.4 V - 1 pc. 3r33838.  3r3998. 3r33869. Optional toggle switch - power switch
 3r3998.
3r33983.  3r3998. 3r33985. Chassis, DC motors and wheels were purchased immediately in the kit and even with assembly instructions. 3r33987. 3r33983.  3r3998.
Pinout 3r31414. 3r33983.  3r3998. 3r33985. Analog inputs can be used as digital pins on I /O ports. Arduino pins corresponding to the analog inputs have numbers from 14 to 19. This applies only to Arduino pins, and not to the physical pin numbers of the Atmega microcontroller. 3r33987. 3r33983.  3r3998. 3r33985. It is not necessary to draw, you can simply reduce everything to a table. I did it. 3r33987. 3r33983.  3r3998. 3r33985. Arduino. The project "Robot car RoboCar4W" 3r33987. 3r33983.  3r3998. 3r33985. Pins D? D? D? D12 will be occupied if any DC or step motors are used. 3r33987. 3r33983.  3r3998. 3r33985. Pins D9 (Servo # 1 control), D10 (Servo # 2 control) will be occupied only if servos are used. 3r33987. 3r33983.  3r3998. 3r33985. By itself, the board for controlling the Motor Drive Shield L293D motors is not occupied by Arduino pins. 3r33987. 3r33983.  3r3998. 3r33985. The 3.3 V, 5 V and ground pins are duplicated on the Motor Drive Shield in sufficient quantities. Therefore, there is no need to worry about their shortage. 3r33987. 3r33983.  3r3998. 3r33985. If you still want to paint beautifully, then the free Fritzing program will help you. 3r33987. 3r33983.  3r3998. 3r33333. Food 3r33914. 3r33983.  3r3998. 3r33985. This is the second very important point. A lot depends on nutrition. For example, a servo-motor starts to consume a large current when the shaft turns through a given angle. Moreover, if the servo is connected to the 5 V power supply of the Arduino, then the voltage drops and the rest of the circuit starts to fail, and the Arduino can even reboot at the same time. 3r33987. 3r33983.  3r3998. 3r33985. In any case, if you use motors in an odd job, the Motor Drive Shield is necessary (or a similar scheme). 3r33987. 3r33983.  3r3998. 3r33985. So, we have 4 DC motors (DC), a servo drive, the Arduino board itself, and several sensors. The motors are the most voracious, but the sensors can be successfully powered from the connectors of the Arduino board itself, so everything is simple with them. For convenience, I brought the whole economy in one table. 3r33987. 3r33983.  3r3998. 3r33333.  3r3998. 3r33333.  3r3998.
 3r3998. 3r33333. 3r33336.  3r3998. 3r33333. Recommended or typical voltage. Current consumption
 3r3998. 3r33333. The maximum voltage is
 3r3998. 3r33333. What is planned to feed
 3r3998. 3r33333. Notes
 3r3998.
 3r3998. 3r33333.  3r3998. 3r33333.  3r3998.
 3r3998.
Arduino UNO R3
board.  3r3998.
7 - 12V, 200mA (average)
 3r3998.
6-20
 3r3998.
“Krone 9V” Li-ion 650mAh, 8.4V
 3r3998.
Connector with a plus in the center 3r3454.  3r3998.
 3r3998.
 3r3998.
Servomotor MG-995
 3r3998.
5-6 V, 0.1 - 0.3A (peak)
 3r3998.
4.8 - ???r3454.  3r3998.
Batteries (5) pcs. Ni-Mh 1.2V = 6V
 3r3998.
Food only from a separate source. If powered with Arduino, then everything will be buggy. Ni-Mh battery voltage 4pcs. * 1.2V = 4.8V is not enough. Some argue that this servo should not be used on 6 volts, only ???r3r3454.  3r3998.
 3r3998.
 3r3998.
DC motors (4 pcs.)
 3r3998.
6 - 8V, current from 70mA to 250mA
 3r3998.
3–12
 3r3998.
batteries (5 + 3) pcs. Ni-Mh 1.2V = 9.6V
 3r3998.
You will not be able to start the engines from a 9V battery normally, so don't even waste time (and batteries)!
 3r3998.
 3r3998.
 3r3998.
Motor Drive Shield L293D
 3r3998.
not required 3r3454.  3r3998.
4.5 - 36 3r3454.  3r3998.
not required 3r3454.  3r3998.
 3r3998.
 3r3998.
 3r3998.
Bluetooth module HC-0506
 3r3998.
3.3 V, 50 mA
 3r3998.
1.8–???r3r3454.  3r3998.
With pin 3.3V Arduino
 3r3998.
 3r3998.
 3r3998.
 3r3998.
Ultrasonic distance meter HC-SR04
 3r3998.
5 V, 2 mA
 3r3998.
5
 3r3998.
With pin 5V Arduino
 3r3998.
 3r3998.
 3r3998.
 3r3998. 3r33460. 3r33983.  3r3998. 3r33985. I did not have a DC /DC voltage converter. Krone 9V was not a very good power source, I just had it already. 3r33987. 3r33983.  3r3998. 3r33985. But I refused to use high-capacity Li-ion batteries. First, because of the high cost, and secondly, in Chinese online shops it is easy to run into a fake. More precisely, not "easy", but "always." In addition, Li-ion requires special handling, and it is not safe. 3r33987. 3r33983.  3r3998. 3r33985. So, as we can see from the table, we need 3 independent power sources:
3r33983.  3r3998. 3r33855.  3r3998. 3r33869. For Arduino board and sensors. 3r33838.  3r3998. 3r33869. For servomotor. 3r33838.  3r3998. 3r33869. For 4 DC motors. 3r33838.  3r3998.
3r33983.  3r3998. 3r33985. Where is stHow to dial? In any case, the Arduino board itself must be powered from a separate source, since when the voltage drops, for example, from switching on the motors, the board can reboot or simply fail. Here we use the battery of the “Kron 9V” form factor, and the connector that will be connected to the Arduino should be with a “plus in the center”. 3r33987. 3r33983.  3r3998. 3r33985. For servomotor and 4-DC motors, you can do with one power source. The only problem is that the servomotor is designed for a voltage of 5-6V (maximum 7.2V) and a current of 100-300mA (peak), and DC motors require 6-8V (maximum 12V) and a current of 250mA. 3r33987. 3r33983.  3r3998. 3r33985. To solve the problem, there are DC-DC converters, but I did not have such. As a result, I applied my “proprietary” connection scheme (without any downward electronic circuits, only environmentally friendly voltage and current!): I connected 8 pcs. 1.2V batteries in series and made taps in the right places, as shown in the diagram. 3r33987. 3r33983.  3r3998. 3r33985. 3r3502. 3r33987. 3r33983.  3r3998. 3r33985. 6B went to the servomotor, and 9.6 to DC motors. It is clear that the batteries 1--5 will experience increased load. 3r33987. 3r33983.  3r3998. 3r33985. To control the servo and DC motors, I used a 4-channel Motor Drive Shield based on the L293D chip. 3r33987. 3r33983.  3r3998. 3r???. Build 3r33914. 3r33983.  3r3998. 3r33985. Assembling the finished chassis is a small problem. But do not think that without finishing, everything will come together at once. Therefore, prepare the files. 3r33987. 3r33983.  3r3998. 3r33985. 3r33535. 3r33987. 3r33983.  3r3998. 3r33985. 3r33528. 3r33987. 3r33983.  3r3998. 3r33985. Connect normally several motors, servomotor or stepper directly to the Arduino will not succeed. Since the pins (conclusions) Arduino are weak. To solve the problem, there is an additional drive control module - Motor Drive Shield based on the L293D chip, which is one of the most common chips designed for this purpose. The L293D chip is also known as the H-Bridge. 3r33987. 3r33983.  3r3998. 3r33985. I used a board that provides 4 channels to connect on two L293D chips and a shift register. Purchased on eBay for $ 5. 3r33987. 3r33983.  3r3998. 3r33985. This drive control module board has the following characteristics. 3r33987. 3r33983.  3r3998. 3r33855.  3r3998. 3r33869. L293D Motor Drive Shield is compatible with Arduino Mega 1280 and 256? UNO, Duemilanove, Diecimila
 3r3998. 3r33869. 4 channel control
 3r3998. 3r33869. motor power from 4.5V to 36V
 3r3998. 3r33869. the permissible load current is 600 mA per channel, the peak current is 1.2A
 3r3998. 3r33869. overheating protection
 3r3998. 3r33869. 2 interfaces with a precise Arduino timer (no “jitter”) for connecting servomotors to a voltage of 5V, if the supply voltage needs to be higher, then the power supply connection needs to be redone as described below.  3r3998. 3r33869. 4 bi-directional DC collector motors or 2 stepper and 2 servomotors can be controlled simultaneously.  3r3998. 3r33869. 4 bi-directional DC motors are each connected to an 8-bit bus to select an individual speed of 3r33870.  3r3998. 3r33869. Connect up to 2 stepper drives (unipolar or bipolar), with one coil, double coil, or alternating pitch 3r33870.  3r3998. 3r33869. connector for connecting an external source for separate supply of control logic and motors
 3r3998. 3r33869. RESET Arduino button
 3r3998. 3r33869. Adafruit AFMotor library is used for management. 3r33838.  3r3998.
3r33983.  3r3998. 3r33985. Motor Drive Shield requires a little work in order to be able to connect anything after it. I soldered on top of the necessary connectors, I got this. 3r33987. 3r33983.  3r3998. 3r33985. 3r33590. 3r33987. 3r33983.  3r3998. 3r33985. Motors can be connected to an additional power supply with respect to the Arduino board. I recommend this type of connection. To do this, remove, open the jumper, as shown in the picture. 3r33987. 3r33983.  3r3998. 3r33985. 3r3599. 3r33987. 3r33983.  3r3998. 3r33985. In this case, the Arduino is powered and the motors are powered independently of each other. 3r33987. 3r33983.  3r3998. 3r33985. The LED on the motor-shield glows when there is power to the motors, if it is off, the motors will not work. 3r33987. 3r33983.  3r3998. 3r33985. New problem. 3r33987. 3r33983.  3r3998. 3r33985. The position of the power jumper does not concern the servos, they will still be powered by 5V Arduino. Since servomotors usually consume a large current and if there is not enough power, the whole device starts to fail, in the "best" case only the servo will fail - it will not turn at a given angle, or all the time before each turn, turn first to 0 degrees, and only then at a given angle (and if you have time). Therefore, I recommend powering the servo also from an additional power source. To do this, you will have to alter the connection circuit a little: bite the positive wire (usually red) from the standard connector and connect it directly to the power source. 3r33987. 3r33983.  3r3998. 3r33985. 3r3620. 3r33987. 3r33983.  3r3998. 3r33985. When connecting Motor Drive Shield analog pins are not used. Digital pins ? 13 are not used. 3r33987. 3r33983.  3r3998. 3r33985. The following pins are used only if the corresponding DC motors or stepper motors (Stepper) are connected and used:
3r33983.  3r3998. 3r33855.  3r3998. 3r33869. D11: DC Motor # 1 /Stepper # 1 (activation and speed control)
 3r3998. 3r33869. D3: DC Motor # 2 /Stepper # 1 (activation and speed control) 3r33838.  3r3998. 3r33869. D5: DC Motor # 3 /Stepper # 2 (activation and speed control)
 3r3998. 3r33869. D6: DC Motor # 4 /Stepper # 2 (activation and speed control) 3r33838.  3r3998.
3r33983.  3r3998. 3r33985. These pins will be occupied if any DC /steppers are used: D? D? D? D12. 3r33987. 3r33983.  3r3998. 3r33985. The following pins will be occupied only if the corresponding servomotors are used:
3r33983.  3r3998. 3r33855.  3r3998. 3r33869. D9: Servo # 1 management
 3r3998. 3r33869. D10: Servo # 2 running
 3r3998.
3r33983.  3r3998. 3r33985. 3r3669. 3r33987. 3r33983.  3r3998. 3r33985. To get started with Motor Drive Shield, you need to download and install the library. Adafruit AFMotor . 3r33987. 3r33983.  3r3998. 3r33985. Example code for controlling motors:
3r33983.  3r3998. 3r3951. 3r3952. #include Sketch for manual control on bluetooth download here . The sketch has no debug mode, since everything is transparent there. You press the button - the robot is going. 3r33987. 3r33983.  3r3998. 3r33985. Program for Adnroid Bluetooth RC Car . 3r33987. 3r33983.  3r3998. 3r33985. Well that's all! Happy road! 3r33987. 3r33983.  3r3998. 3r33985. 3r33986. 3r33987. 3r3994. 3r3998. 3r3998. 3r3991. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d,! 1): e.attachEvent ("onload", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r3992. 3r3998. 3r3994. 3r3998. 3r3998. 3r3998. 3r3998.
+ 0 -

Add comment