本课是在前面两课的基础之上进行的,所以前面两课中已经安装的部件可以原封不动,本课只需安装舵机、超声波模块。在本课中我们将介绍如何利用超声波和舵机让 小车拥有一双“慧眼”,在运动过程中能够避开的障碍物,也就是避障功能。舵机带动超声波模块一起转动,检测前方和左右两边距离,当距离低于一定值时候,小车选择最优路径运动。
Device Name
|
picture
|
qty
|
Arduino UNO
|
补部件图片100 x 100
|
1
|
Motor with wires
|
补部件图片100 x 100
|
4
|
L298N MOTOR driver module
|
补部件图片100 X 100
|
1
|
Box for 18650 3.7V battery+
DC power connector
|
补部件图片100 x 100
|
1
|
voltage meter
|
补部件图片100 X 100
|
1
|
SG90 Servo Motor
|
补部件图片100 X 100
|
1
|
超声波
|
补部件图片100 X 100
|
1
|
云台
|
补部件图片100 X 100
|
1
|
Jumper wires(male-male,male-female,female-female)
|
补部件图片100 X 100
|
若干
|
底盘
|
补部件图片100 X 100
|
1
|
1) 底盘、电机、L298N电机驱动板以及Arduino UNO等安装,请参考第一课、第二课中的介绍:
OSOYOO Robot Car Starter Kit Lesson 1: Install UNO R3 Board and Motors on Chassis
2) 安装舵机
取出3颗M3*10螺丝、3颗M3螺帽和舵机固定片
将舵机固定片安装于较短一块底盘背面
将舵机用两颗M2*10螺丝固定在舵机固定片的舵机孔位中
2)安装超声波模块
用4颗M1.5*8螺丝将超声波模块安装在超声波支架上
3)舵机接线
舵机有三条线,电源线、地和信号线,为了避免舵机在转动的瞬间把电压拉的很低,而影响Arduino UNO正常工作,在此,需要把舵机接到L298N上供电,信号线引脚从Arduino UNO上引到L298N上,这样舵机就可以直接插在L298N上了。
本课程中用的SG90舵机能旋转180度,即左右各能旋转90度,在安装超声波模块之前,需要将舵机旋转到中间位置,烧录下面的程序就可以让舵机回到中间位置。
调整舵机程序:https://osoyoo.com/driver/servo_adjust.zip
下载上面程序解压,烧录到Arduino uno中,打开电池盒侧面开关,舵机会转到90度位置(中间位置)
4) 取出舵机包装袋中的页片和两颗自攻螺丝
将页面按照图示样子套在舵机轴承上,
并将2颗自攻螺丝拧在舵机页面与固定支架上,最后用一颗M2*10的自攻螺丝将支架与舵机轴承拧紧(即正中间一颗螺丝)
5) 超声波接线
超声波模块与UNO之间按照下图连接
Step 1: Install latest Arduino IDE (If you have Arduino IDE version after 1.1.16, please skip this step)
Download Arduino IDe from https://www.arduino.cc/en/Main/Software?setlang=en , then install the software.
Step 2:Download Lesson One sample code fromhttps://osoyoo.com/driver/smartcar-lesson3.zip , unzip the download zip file smartcar-lesson3.zip, you will see a folder called smartcar-lesson3 .
Step 3: Connect Arduino UNO to PC with USB cable, use Arduino IDE to open the file smartcar-lesson3.ino in smartcar-lesson3 folder, load the code into arduino.
Final Testing :
打开电池盒侧面电源开关,超声波模块会转到面朝正前方的位置,如果前方没有障碍物,小车会直行,在直行过程中如果出现障碍物,小车先后退一端距离,超声波会左右旋转,检测小车左右是否有障碍物;如果左边有障碍物,小车会右转,若右边有障碍物小车会左转;如果左右都有障碍物,小车会后退。
DownLoad Url osoyoo.com
You must be logged in to post a comment.
After mounting my ultrasonic module to my servo, the servo does not work anymore. I believe the servo broke when mounting, is there a way that I can get a new one? Also, my buzzer does not make any noise.
Nevermind, the servo works now. Buzzer still does not make noise though
Arduino:1.8.11 Hourly Build 2019/11/11 03:33 (Windows 10), לוח:”Arduino Uno”
smartcar-lesson3:1:10: error: Servo.h: No such file or directory
compilation terminated.
exit status 1
Servo.h: No such file or directory
“Show verbose output during compilation”
Please Download and install the servo library from:
https://osoyoo.com/driver/Servo.zip
Arduino:1.8.11 Hourly Build 2019/11/11 03:33 (Windows 10), לוח:”Arduino Uno”
smartcar-lesson3:1:10: error: Servo.h: No such file or directory
compilation terminated.
exit status 1
Servo.h: No such file or directory
“Show verbose output during compilation”
It seems that your Arduino IDE version does not support Servo library. Normally Servo library should come with Arduino IDE.
I suggest you install the latest Windows Arduino IDE version and re-compile the sketch again. Do not use Arduino IDE in linux. Linux Arduino IDE might lack many libaries.
Thanks a lot for your help everything works fine I’ll continue to the next step
Wired it and uploaded the program, turned it on and it beeped. Then it proceeded to shoot backwards.. how do I troubleshoot this?
does the robot rotate the two big eyes(ultrasonic sensor)?
It moves the eyes once off to the side.
In order to make sure beginning orientation of your ultrasonic sensor(two BIG EYES) facing to front, the first two seconds after you turning on the battery, the servo will rotate to 90degree position(stay there for 2 seconds). So if your ultrasonic sensor is not facing the front at the beginning two seconds, you need to turn off the battery. release your ultrasonic sensor from servo and reposition it. Make it facing front and fasten it.
If your ultrasonic sensor does not facing front at the beginning, the car can not properly do obstacle avoidance.