Arduino ile Bluetooth Kontrollü Araba
Gerekli malzemeler:
-
Arduino UNO
-
HC-06 bluetooth
-
Jumper Kablo
-
L298 N Motor Sürücü
-
9 Volt Pil
Devre Şeması
Arduino Kodu:
String readString;
const int in1 = 7;
const int in2 = 6;
const int in3 = 5;
const int in4 = 4;
void setup(){
pinMode(in1, OUTPUT); //Tüm pinlerden güç çıkışı olacağı için OUTPUT olarak ayarladık.
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
Serial.begin(9600); /* Seri haberlesme baslatildi */
}
void loop()
{
while(Serial.available()){
delay(3);
char c= Serial.read();
readString+=c;
}
if(readString.length()>0){
Serial.println(readString);
if(readString=="a"){
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
if(readString=="b"){
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
if(readString=="c"){
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
if(readString=="d"){
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
if(readString=="e"){
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
readString="";
}
}