Thursday, December 21, 2017

Arduino Car 1

                                         
                          Arduino ultrasonic sensor car 1





Using parts(අවශ්ය උපාන්ග)

Arduino uno bord .................1
L298N motor control bord ...1
Ultra sonic sensor ..................1
DC Mini motro ......................2
car chesi
power battery 
wire clip
Using circuit diagram ...>>>>>>>>>>>>>>>>>

පින් 8 හි සදහන් echo pin පින් 9 ට සම්බන්ද කරන්න

Using this Code   ...>>>>>>>>>>>>>>>>>>>>>>>

ARDUINO CODE (කේතය)

//EDIT BY  PRADEEP SANJEEWA//
#define trig 2//tri pin
#define echo 9 //echo pin
void setup() {
pinMode(4, OUTPUT);  //in 1//
pinMode(5, OUTPUT);//in2//
pinMode(6, OUTPUT);//in3//
pinMode(7, OUTPUT);//in4//
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
Serial.begin(9600);
}

void loop() {

digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);

long t = pulseIn(echo, HIGH);

long inches =t/10/2;
long cm =t/100/2;

Serial.print(inches);
Serial.print ("in\t");
Serial.print(cm);
Serial.print("cm");
delay(100);

 if(cm<20){

 digitalWrite (7,LOW);
 digitalWrite (5,LOW);
 delay(100);
 digitalWrite (6,HIGH);
 digitalWrite (4,HIGH);



}
else

 digitalWrite (6,LOW);
 digitalWrite (4,LOW);

 digitalWrite (7,HIGH);
 digitalWrite (5,HIGH);


}

No comments:

Post a Comment