0
2019
Yahboom Arduino Batmobile
Arduino IDE Programming Tutorials
Page 1: ...0 2019 Yahboom Arduino Batmobile Arduino IDE Programming Tutorials...
Page 2: ...ead 2 2 Button start 6 3 Line Walking 12 4 Infrared obstacle avoidance 19 5 Tracking 26 6 Ultrasonic distance measurement 32 7 Ultrasonic check obstacle and avoid 37 8 Line Walking and check obstacle...
Page 3: ...e for output mode pinMode Left_motor_go OUTPUT pinMode Left_motor_back OUTPUT pinMode Right_motor_go OUTPUT pinMode Right_motor_back OUTPUT void run int time go ahead digitalWrite Left_motor_en HIGH s...
Page 4: ...ino click under the menu bar to compile the code and wait for the word Done compiling in the lower right corner as shown in the figure below 2 In the menu bar of Arduino IDE we need to select Tools P...
Page 5: ...the selection is completed you need to click under the menu bar to upload the code to the Arduino UNO board When the word Done uploading appears in the lower left corner the code has been successfully...
Page 6: ...5 4 After the program is successfully uploaded as shown in Figure 1 press the power switch you can see that the BatCar starts moving forward after 2 seconds Figure 1 Figure 2...
Page 7: ...et Button port int key 4 Set BUZZER port int beep 3 void setup Initialize motor drive for output mode pinMode Left_motor_go OUTPUT pinMode Left_motor_back OUTPUT pinMode Right_motor_go OUTPUT pinMode...
Page 8: ...W analogWrite Left_motor_go 0 analogWrite Left_motor_back 0 delay time 100 void spin_left int time Left rotation digitalWrite Right_motor_go HIGH right motor go ahead digitalWrite Right_motor_back LOW...
Page 9: ...rite Right_motor_back 150 PWM Pulse Width Modulation 0 255 control speed digitalWrite Left_motor_go LOW left motor back off digitalWrite Left_motor_back HIGH analogWrite Left_motor_go 0 analogWrite Le...
Page 10: ...ht rotation for 2s brake 5 stop for 0 5s Experimental steps 1 We need to open the code of this experiment Button_start ino click under the menu bar to compile the code and wait for the word Done compi...
Page 11: ...you need to click under the menu bar to upload the code to the Arduino UNO board When the word Done uploading appears in the lower left corner the code has been successfully uploaded to the Arduino U...
Page 12: ...le put the BatCar in an open place turn on the power switch and the BatCar is still at rest until the start button K1 is pressed After a short whistle the BatCar starts to move forward and backward Tu...
Page 13: ..._en 8 int Left_motor_en 7 Set Button port int key 4 Set BUZZER port int beep 3 Line Walking const int SensorRight A3 Set Right Line Walking Infrared sensor port const int SensorLeft A2 Set Left Line W...
Page 14: ...ck LOW void left turn left digitalWrite Right_motor_go HIGH right motor go ahead digitalWrite Right_motor_back LOW analogWrite Right_motor_go 100 analogWrite Right_motor_back 0 PWM Pulse Width Modulat...
Page 15: ...LOW analogWrite Left_motor_go 200 analogWrite Left_motor_back 0 PWM Pulse Width Modulation 0 255 control speed delay time 100 void back int time back off digitalWrite Right_motor_go LOW right motor ba...
Page 16: ...alRead SensorLeft Left Line Walking Infrared sensor against white undersurface then LED L3 light illuminates and while against black undersurface LED L3 goes off if SL LOW SR LOW Black lines were not...
Page 17: ...16 2 In the menu bar of Arduino IDE we need to select Tools Port selecting the port that the serial number displayed by the device manager just now as shown in the figure below...
Page 18: ...you need to click under the menu bar to upload the code to the Arduino UNO board When the word Done uploading appears in the lower left corner the code has been successfully uploaded to the Arduino U...
Page 19: ...am is successfully downloaded adjust potentiometers SW3 and SW4 to the correct angle 5 Put the BatCar on the patrol tarck and press the start button K1 With a short whistle the BatCar starts running a...
Page 20: ...alking const int SensorRight A3 Set Right Line Walking Infrared sensor port const int SensorLeft A2 Set Left Line Walking Infrared sensor port int SL State of Left Line Walking Infrared sensor int SR...
Page 21: ...lWrite Right_motor_go LOW digitalWrite Right_motor_back LOW digitalWrite Left_motor_go LOW digitalWrite Left_motor_back LOW void left turn left digitalWrite Right_motor_go HIGH right motor go ahead di...
Page 22: ...otor_go HIGH left motor go ahead digitalWrite Left_motor_back LOW analogWrite Left_motor_go 200 analogWrite Left_motor_back 0 PWM Pulse Width Modulation 0 255 control speed delay time 100 void back in...
Page 23: ...L5 light illuminates and otherwise it goes off SL_2 digitalRead SensorLeft_2 Left infrared sensor detects the obstacle then LED L4 light illuminates and otherwise it goes off if SL_2 HIGH SR_2 HIGH Th...
Page 24: ...23 2 In the menu bar of Arduino IDE we need to select Tools Port selecting the port that the serial number displayed by the device manager just now as shown in the figure below...
Page 25: ...you need to click under the menu bar to upload the code to the Arduino UNO board When the word Done uploading appears in the lower left corner the code has been successfully uploaded to the Arduino U...
Page 26: ...ploaded debug the BatCar as shown below 5 Place the BatCar in an open space and place some cartons as obstacles Turn on the BatCar s power switch press the start button K1 and after hearing the short...
Page 27: ...beep 3 Line Walking const int SensorRight A3 Set Right Line Walking Infrared sensor port const int SensorLeft A2 Set Left Line Walking Infrared sensor port int SL State of Left Line Walking Infrared...
Page 28: ...lWrite Right_motor_go LOW digitalWrite Right_motor_back LOW digitalWrite Left_motor_go LOW digitalWrite Left_motor_back LOW void left turn left digitalWrite Right_motor_go HIGH right motor go ahead di...
Page 29: ...otor_go HIGH left motor go ahead digitalWrite Left_motor_back LOW analogWrite Left_motor_go 200 analogWrite Left_motor_back 0 PWM Pulse Width Modulation 0 255 control speed delay time 100 void back in...
Page 30: ...ht illuminates and otherwise it goes off SL_2 digitalRead SensorLeft_2 Left infrared sensor detects the obstacle then LED L4 light illuminates and otherwise it goes off if SL_2 LOW SR_2 LOW Black line...
Page 31: ...30 2 In the menu bar of Arduino IDE we need to select Tools Port selecting the port that the serial number displayed by the device manager just now as shown in the figure below...
Page 32: ...ears in the lower left corner the code has been successfully uploaded to the Arduino UNO board as shown in the figure below 4 After the program download is successful debug potentiometers SW1 and SW2...
Page 33: ...rt int Trig A0 Set Trig port int Distance 0 void setup Serial begin 9600 Set Serial baud rate 9600 pinMode Echo INPUT Set Ultrasonic echo port as input pinMode Trig OUTPUT Set Ultrasonic trig port as...
Page 34: ...loop Distance_test Measure and display distance delay 200 Experimental steps 1 We need to open the code of this experiment Ultrasonic_distance_measurement ino click under the menu bar to compile the c...
Page 35: ...you need to click under the menu bar to upload the code to the Arduino UNO board When the word Done uploading appears in the lower left corner the code has been successfully uploaded to the Arduino U...
Page 36: ...35 4 After the program is successfully uploaded do not unplug the USB cable Click on the serial port monitor as shown below 5 The serial port baud rate is 9600 as shown below...
Page 37: ...easured by the ultrasonic sensor is refreshed every 200 milliseconds in the serial monitor and the data is slowly moved forward by the hand in front of the ultrasonic sensor and the data measured by t...
Page 38: ...the whistle BatCar starts using the ultrasonic sensor to detect obstacles in front and avoid obstacles List of components required for the experiment BatCar 1 USB data cable 1 ultrasonic sensor 1 Expe...
Page 39: ...usted to control speed analogWrite Right_motor_back 0 digitalWrite Left_motor_go HIGH set left motor go ahead digitalWrite Left_motor_back LOW analogWrite Left_motor_go 100 PWM Pulse Width Modulation...
Page 40: ...Pulse Width Modulation 0 255 control speed void spin_right int time Right rotation digitalWrite Right_motor_go LOW right motor back off digitalWrite Right_motor_back HIGH analogWrite Right_motor_go 0...
Page 41: ...ront distance digitalWrite Trig LOW set trig port low level for 2 s delayMicroseconds 2 digitalWrite Trig HIGH set trig port high level for 10 s at least 10 s delayMicroseconds 10 digitalWrite Trig LO...
Page 42: ...stance else run There is nothing obstacled Go ahead Experimental steps 1 We need to open the code of this experiment Ultrasonic_check_obstacle_and_avoid ino click under the menu bar to compile the cod...
Page 43: ...you need to click under the menu bar to upload the code to the Arduino UNO board When the word Done uploading appears in the lower left corner the code has been successfully uploaded to the Arduino U...
Page 44: ...rn on the BatCar s power switch press the start button K1 and after hearing the whistle BatCar starts using the ultrasonic sensor to detect obstacles in front and avoid obstacles If the front distance...
Page 45: ...e black line List of components required for the experiment BatCar 1 USB data cable 1 Patrol tarck 1 Ultrasonic sensor 1 Experimental code analysis int Left_motor_back 9 int Left_motor_go 5 int Right_...
Page 46: ...t_motor_back LOW analogWrite Right_motor_go 100 PWM Pulse Width Modulation 0 255 It can be adjusted to control speed analogWrite Right_motor_back 0 digitalWrite Left_motor_go HIGH set left motor go ah...
Page 47: ...Write Left_motor_back 0 PWM Pulse Width Modulation 0 255 control speed void spin_right int time Right rotation digitalWrite Right_motor_go LOW right motor back off digitalWrite Right_motor_back HIGH a...
Page 48: ...front distance digitalWrite Trig LOW set trig port low level for 2 s delayMicroseconds 2 digitalWrite Trig HIGH set trig port high level for 10 s at least 10 s delayMicroseconds 10 digitalWrite Trig L...
Page 49: ...ad else if SL LOW SR HIGH Left sensor against white undersurface and right against black undersurface the car left off track and need to adjust to the right right else if SR LOW SL HIGH Rihgt sensor a...
Page 50: ...you need to click under the menu bar to upload the code to the Arduino UNO board When the word Done uploading appears in the lower left corner the code has been successfully uploaded to the Arduino U...
Page 51: ...atrol tarck after debugging according to the following figure 5 After turning on the power switch and pressing the start button K1 BatCar starts to patrol the black line If the ultrasonic sensor detec...
Page 52: ...the experiment BatCar 1 USB data cable 1 Infrared remote control 1 Experimental code analysis Infrared Remote contorl Experiment include IRremote h Infrared Remote Control int RECV_PIN 2 Set Infrared...
Page 53: ...ght_motor_go LOW digitalWrite Right_motor_back LOW digitalWrite Left_motor_go LOW digitalWrite Left_motor_back LOW void left turn left digitalWrite Right_motor_go HIGH right motor go ahead digitalWrit...
Page 54: ...50 make sure receive signal on on Sign position reversal digitalWrite 13 on HIGH LOW LED blink dump results decode if results value run_car key 2 run go ahead if results value back_car key 8 back back...
Page 55: ...54 2 In the menu bar of Arduino IDE we need to select Tools Port selecting the port that the serial number displayed by the device manager just now as shown in the figure below...
Page 56: ...hen the word Done uploading appears in the lower left corner the code has been successfully uploaded to the Arduino UNO board as shown in the figure below 4 After the program of Remote contorl is uplo...
Page 57: ...remote control Remote control button Corresponding user code value The program controls the action of the BatCar 0 0x00FF6897 No control action 0x00FF9867 No control action C 0x00FFB04F No control act...