Arduino obstacle avoiding bluetooth car
ARDUINO BLUETOOTH OBSTACLE AVOIDING CAR
SAMPLE PHOTOS
Arduino Code
#include <Ultrasonic.h>
Ultrasonic u = Ultrasonic(3,4);
#include <Servo.h>
Servo s = Servo();
void setup() {
// put your setup code here, to run once:
s.attach(8);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
analogWrite(11,150);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
analogWrite(5,150);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int x = Serial.read();
if(x == '1'){
s.write(90);
delay(300);
int d = u.read();
if(d > 20){
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
delay(500);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
}
if(x == '2'){
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
delay(500);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
if(x == '3'){
s.write(30);
delay(300);
int d = u.read();
if(d > 20){
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
delay(500);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
s.write(90);
}
if(x == '4'){
s.write(120);
delay(300);
int d = u.read();
if(d > 20){
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
delay(500);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
s.write(90);
}
}
Comments
Post a Comment