Before starting your own project, you must download the Smart_Car_for_Arduino.zip package on our website by visiting LEARN -> Get Tutorials -> Smart Car Kit for Arduino and unzip it.
Arduino is an open source platform that applies simple software and hardware. You can get it in a short even when you know little of it. It provides an integrated development environment (IDE) for code editing and compiling, compatible with multiple control boards. So you can just download the Arduino IDE, upload the sketches (i.e. the code files) to the board, and then you can see experimental phenomena. For more information, refer to http://www.arduino.cc.
Arduino Board – SunFounder Compatible
In this kit, SunFounder Uno R3 board is used and it is completely compatible with Arduino Uno Board.
Install Arduino IDE
The code in this kit is made based on Arduino, so you need to install the IDE first. Skip it if you have done this.
Now go to the arduino.cc website and click DOWNLOAD. On the page, check the software list on the right side under Download the Arduino Software.
Find the one that suits your operation system and click to download. There are two versions of Arduino for Windows: Installer or ZIP file. You’re recommended to download the former. Just download the package, and run the executable file to begin installation. It will download the driver needed to run Arduino IDE. Then do the install as suggested. For details of steps, refer to the guide on Learning->Getting Started ->Arduino, scroll down and see Install the Arduino Software.
After install is done, you can see an Arduino icon on your desktop. Double click to open it.
1) Select Sketch -> Include Library -> Add ZIP Library
2) Find the file MsTimer2.zip under Smart Car for Arduino\Code\library. Click it open and then you’ll be prompted by “Library added to your libraries. Check ‘Import libraries’”. You also can see the libraries just imported have appeared on the list by Sketch->Include Library->MsTimer2.
Servo is a set of automatic control system composed of DC motors, reduction gear set, sensors and control circuits. The output shaft can be rotated to a certain angle by sending signals. The servo can only rotate in a certain range, for example, 180°. It cannot rotate any circles like the DC motor. The servo enables you to easily rotate an object in a certain angle, so it is widely used in model planes and robot joints.
In this car kit, two types of servo are used: Tower Pro Micro Servo (blue ones) for obstacle avoidance experiment, and Micro Servo MG995 SG90 (black) in the car front to control the its direction.
1) You may find a long rocker arm packaged with the servo, mount it onto the servo, and spin it to the maximum angle.
2) Connect the circuit as follows:
3) Connect the SunFounder Uno board to your computer via a USB cable. Open the file Car_Forward.ino under the path Smart Car for Arduino\Code\1.Car_Forward\ Car_Forward. Before uploading the sketch to the board, you need to select the right Board and Port through Tools->Board->Arduino/Genuino Uno.
Then click to Tools->Port->COM29 (your port may be different)
4) Click the Upload icon. The code is uploaded successfully when you are prompted “Done Upload” at the bottom.
5) After uploading the code successfully, you can hear a sound of the gear moving when the servo rotates. It means the adjustment succeeds.
It is convenient to place components on a breadboard. However, you need to have some electronic foundation to build various kinds of circuit. By using this sensor shield, you only need to wire components to the shield with some jumper wires, and then you can build your own project quickly. The sensor shield is one of the most common Arduino peripheral devices, as shown below:
Its schematic diagram is as shown below: note that VCC only supplies power to the devices connected to D2 (hooked to the black servo) and D3. Other components are powered by 5V.
Motor Driver Module
The motor driver module is used to drive two motors to rotate. The driver chip used here is L298N.
Its schematic diagram is as shown below:
L298N is a high voltage, large current driver chip manufactured by ST, which uses a 15-pin package.
Its main features are as follows:
- • High operating voltage, which can be up to 40 volts;
- • Large output current – the instantaneous peak current can be up to 3A;
- • With 25W rated power;• Using standard logic level signal to control.
- • Two built-in H-bridge, high voltage, large current, full bridge driver, which can be used to drive DC motors, stepper motors, relay coils and other inductive loads.
- • Able to drive a two-phase or four-phase stepper motor, and two-phase DC motors.
Its pin functions are as shown below:
|115||Sense ASense B||The sense resistor is connected between this pin and ground to control the current of the load.|
|23||Out 1Out 2||Outputs of the Bridge A; the current that flows through the load connected between these two pins is monitored at pin 1.|
|4||Vs||Supply Voltage for the Power Output Stages.A non-inductive 100nF capacitor must be connected between this pin and ground.|
|57||Input1Input2||TTL Compatible Inputs of the Bridge A.|
|611||Enable A Enable B||TTL Compatible Enable Input: the L state disables the bridge A (enable A) and/or the bridge B (enable B).|
|9||Vss||Supply Voltage for the Logic Blocks. A100nF capacitor must be connected between this pin and ground.|
|1012||Input3Input4||TTL Compatible Inputs of the Bridge B.|
|1314||Out 3Out 4||Outputs of the Bridge B. The current that flows through the load connected between these two pins is monitored at pin 15.|
The driver module can drive two motors. The enabled terminals ENA and ENB are effective at high level. The control mode and state of motor A are as shown below:
|ENA||IN1||IN2||The State of DC Motor A|
If you want to regulate the speed of motor A by PWM, you need to set IN1 and IN2, confirm the rotational direction of the motor, and then output PWM pulses for enabled terminals. Please note that the motor is in the free stop state when the signal of enabled terminal is 0. When the enabled signal is 1, if IN1 and IN2 are 00 or 11, the motor is in brake state, and the motor stops rotating. If IN1 is 0 and IN2 is 1, the motor A rotates clockwise; if IN1 is 1 and IN2 is 0, the motor A rotates counterclockwise. This is the control method for motor A. The control method for motor B is the same as that for motor A.
Step-down DC-DC Converter Module
The DC-DC module is used to reduce the input voltage and output a stable 5 volts voltage. Here the LM2596 switching voltage regulator is used to regulate the voltage.
The corresponding schematic diagram:
The LM2596 regulator is a monolithic integrated circuit ideally suited for easy and convenient design of a step−down switching regulator (buck converter). It is capable of driving a 3.0A load with excellent line and load regulation. It is internally compensated to minimize the number of external components to simplify the power supply design.
Since LM2596 converter is a switch−mode power supply, its efficiency is significantly higher in comparison with popular three−terminal linear regulators, especially with higher input voltages. The LM2596 operates at a switching frequency of 150 kHz thus allowing smaller sized filter components than what would be needed with lower frequency switching regulators. It is available in a standard 5−lead TO−220 package with several different lead bend options, and D2PAK surface mount package.
• Fixed Output Voltage: 5V
• Guaranteed 3.0 A Output Load Current
• Wide Input Voltage Range up to 40 V
• 150 kHz Fixed Frequency Internal Oscillator
• TTL Shutdown Capability
• Low Power Standby Mode, typically 80 μA
• Thermal Shutdown and Current Limit Protection
Its pin functions are as shown below:
|1||VIN||This is the positive input supply for the IC switching regulator. A suitable input by pass capacitor must be present at this pin to minimize voltage transients and to supply the switching currents needed by the regulator.|
|3||OUTPUT||Internal switch. The voltage at this pin switches between (+V IN − V SAT) and approximately −0.5V, with a duty cycle of approximately V OUT /V IN. To minimize coupling to sensitive circuitry, the PC board copper area connected to this pin should be kept to a minimum|
|4||Feedback||Senses the regulated output voltage to complete the feedback loop|
|5||ON/OFF||Allows the switching regulator circuit to be shut down using logic level signals thus dropping the total input supply current to approximately 80 µA. Pulling this pin below a threshold voltage of approximately 1.3V turns the regulator on, and pulling this pin above 1.3V (up to a maximum of 25V) shuts the regulator down. If this shutdown feature is not needed, the ON /OFF pin can be wired to the ground pin or it can be left open; in either case the regulator will be in the ON condition|
The switch module is used to turn on/off the power. A self-locking switch is used. It is a single-pole double-throw switch. When the button is not pressed, pin 1 and 3 are connected, and pin 4 and 6 are connected, as shown in figure (a). When the button is pressed, pin 2 and 3 are connected, and pin 4 and 5 are connected, as shown in figure (b).
(a) When the button is NOT PRESSED (b) When the button is PRESSED
This is a photoelectric sensor including both transmitting and receiving parts. You can adjust the sensor as required if you want to detect a distance. With the advantage of long detection distance, less interference by visible light, cheap price, and easiness to assemble and use, it can be widely applied in robot obstacle avoidance, assembly line piece counting, and many other occasions.
Electrical Feature Lead Description
Voltage: 5VDC Red: Positive Pole
Current: 100mA Green: Negative Pole
Distance: 3-80CM Yellow: Signal Output
The resistance of the photoresistor decreases as the incident light intensity increases. The stronger the light is, the lower the resistance of the photoresistor is, and the voltage division on the analog port is larger. Also the value transformed from the voltage on the analog port to digital value by A/D convertor increases. The change of the light intensity can be displayed on LED bar by programming.
The schematic diagram for photosensitive module is as shown below. D is connected to the analog port of the sensor shield.
Obstacle Avoidance Module
The detection distance of IR obstacle avoidance module is 3-30 cm.
After power on, the LED on the board goes out and enters into operating state after blinking once. Pin EN is at high level by default and the enabled sensor works. When an obstacle is detected ahead, the LED on the board will light up and the pin OUTPUT will output low level signals. When no obstacle is detected, the LED on the board keeps off and the pin OUTPUT outputs high level signals.
• Various installations and connections (vertical or horizontal), expanding applications.
• With a potentiometer, able to adjust the detection distance.
• Sensors with an enabled port, convenient for signal lines used as bus applied in circuits.
• After power on, the enabled port is at high level by default. The enabled sensor detects output signals.
Its pin functions are as shown below:
|2||VCC||Power supply (5V)|
|3||OUT||Signal output pin|
|4||EN||Signal output pin, enabled terminal|
The schematic diagram:
The TCRT5000 sensor (or infrared photoelectric sensor) is used, including a blue transmitting tube and a black receiving tube (its resistance will change with the amount of infrared light received).
The IR transmitting tube of TCRT5000 sensor constantly launches infrared light. Since the black receiving tube absorbs light, when the IR transmitting tube shines on a black surface, the reflected light is less and the IR rays received by the receiving tube is less. This indicates the resistance gets larger, the comparator outputs high level, and the indicator LED goes out. Similarly, when it shines on a white surface, the reflected light is more, which indicates the resistance of the receiving tube is lower, the comparator outputs low level, and the indicator LED lights up.
The pin functions are as shown below:
|3||D0||TTL switching signal output|
|4||A0||Analog signal output|
The schematic diagram for tracking module: