First I can understand your feeling so far as a student in the school. All I want to know is you don' t have the coach from the teacher.Anyway I'm still a beginner for the Arduino. I purchase board from Taobao.com in China. And I'd like to share you some of my material for you. All the following is not exactly what you really need maybe, but I positively think you can start it up and just put the ultrasonic sensor together in the Arduino.
The vehicle platform. You also can visit the link(I don't mean a adv.) hope you don't mind the chinese web page. you can build the whole picture in this project.
http://trade.taobao.com/trade/itemlist/listBoughtItems.htm?action=itemlist/QueryAction&event_submit_do_query=1&prePageNo=1&clickMore=0&pageNum=2Attach the program code as following, please ignore the chinese comment. I manually comment in English, wish it's helpful to you.
void setup()
{
pinMode(8,OUTPUT);//定义I1接口 define I1 port
pinMode(9,OUTPUT);//定义I2接口 define I2 port
pinMode(10,OUTPUT);//定义EA(PWM调速)接口 define EA PWM
pinMode(5,OUTPUT);//定义EB(PWM调速)接口 define EB PWM
pinMode(6,OUTPUT);//定义I4接口 define I4
pinMode(7,OUTPUT);//定义I3接口 define I3
pinMode(3,INPUT);//定义左侧避障 define left aviod obstacle sensor
pinMode(4,INPUT);//定义中间避障 define middle aviod obstacle sensor
pinMode(11,INPUT);//定义右侧避障 define right aviod obstacle sensor
}
void qianjin(int a)//前进 go forward sub
{
analogWrite(10,a);//输入模拟值进行设定速度 analog value to set the speed
analogWrite(5,a);
digitalWrite(7,LOW);//使直流电机(右)顺时针转 enable Right DC Motor clockwise rotate
digitalWrite(6,HIGH);
digitalWrite(8,HIGH);//使直流电机(左)逆时针转 enable Left DC Motor counter-clockwise rotate
digitalWrite(9,LOW);
}
void youzhuan(int b)//右转 Turn right
{
analogWrite(10,b);//输入模拟值进行设定速度 analog value to set the speed
analogWrite(5,b);
digitalWrite(7,HIGH);//使直流电机(右)逆时针转 enable Right DC Motor counter-clockwise rotate
digitalWrite(6,LOW);
digitalWrite(8,HIGH);//使直流电机(左)顺时针转 enable Left DC Motor clockwise rotate
digitalWrite(9,LOW);
}
void zuozhuan(int c)//左转 Turn Left
{
analogWrite(10,c);//输入模拟值进行设定速度 analog value to set the speed
analogWrite(5,c);
digitalWrite(7,LOW);//使直流电机(右)顺时针转 enable Right DC Motor clockwise rotate
digitalWrite(6,HIGH);
digitalWrite(8,LOW);//使直流电机(左)顺时针转 enable Left DC Motor clockwise rotate
digitalWrite(9,HIGH);
}
void tingzhi()//停止 Stop
{
digitalWrite(7,HIGH);//使直流电机(右)停转 enable Right DC Motor stop
digitalWrite(6,HIGH);
digitalWrite(8,HIGH);//使直流电机(左)停转 enable Left DC Motor stop
digitalWrite(9,HIGH);
}
void houtui(int d)//后退 Go backward
{
analogWrite(10,d);//输入模拟值进行设定速度 analog value to set the speed
analogWrite(5,d);
digitalWrite(7,HIGH);//使直流电机(右)逆时针转 enable Right DC Motor counter-clockwise rotate
digitalWrite(6,LOW);
digitalWrite(8,LOW);//使直流电机(左)顺时针转 enable Left DC Motor clockwise rotate
digitalWrite(9,HIGH);
}
void loop()
{
int r,m,l;
r=digitalRead(11);
m=digitalRead(4);
l=digitalRead(3);
if(l==HIGH &&m==HIGH && r==HIGH)
qianjin(200);
if(l==LOW &&m==LOW && r==LOW )
{
houtui(200);
delay(300);
youzhuan(200);
delay(300);
}
if(l==LOW &&m==HIGH && r==LOW )
{
houtui(200);
delay(300);
youzhuan(200);
delay(300);
}
if(l==HIGH &&m==LOW && r==HIGH )
{
houtui(200);
delay(300);
youzhuan(200);
delay(300);
}
if(l==LOW &&m==LOW && r==HIGH )
youzhuan(200);
if(l==LOW && m==HIGH && r==HIGH)
youzhuan(200);
if(l==HIGH &&m==LOW && r==LOW )
zuozhuan(200);
if(l==HIGH &&m==HIGH && r==LOW )
zuozhuan(200);
}