RUNNING TEXT

SELAMAT DATANG DI BLOG FISIKA dan TIK KELAS XI SMA SANTA MARIA SURABAYA PIN BB paKetut: 5B3604D2 WA: 081938467743 NO HP: 081330525027

Rabu, 11 Januari 2017

MERAKIT RELAY-SENSOR KE ARDUINO



GAMBAR DI ATAS MERAKIT SENSOR KIRI-KANAN

GAMBAR DI ATAS LAMBANG KOMPONEN HUBUNGAN ATAR RELAY

GAMBAR DI ATAS HUBUNGAN ANTAR KOMPONEN ROBOT DAN SENSOR
PROGRAM PENGECEKAN ROBOT
int x;
int y;
void setup (){
Serial.begin(9600);
pinMode(6,OUTPUT);  //roda kiri
pinMode(7,OUTPUT);  //roda kiri
pinMode(8,OUTPUT);  //roda kanan
pinMode(9,OUTPUT);  //roda kanan
pinMode(10,OUTPUT);  //power mengantur kecepatan putaran roda

}

void mundur(){
analogWrite(10,255);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
}
void maju(){
analogWrite(10,255);  
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
}
void belokiri(){
analogWrite(10,120);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
}

void luruskanan(){
analogWrite(10,110);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,LOW); 
}
void belokanan(){
analogWrite(10,120);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
}
void luruskiri(){
analogWrite(10,110);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
}
void diam (){
analogWrite(10,255);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
}

void loop (){
    int y=analogRead(A0);
    int x=analogRead(A1);
  //  Serial.print("SensorA0= ");
  //   Serial.print(y);
  //    Serial.print(" SensorA1= ");
  //    Serial.println(x); 
  //    delay(500); */
  if ( y<200 && x<200) 
      {maju();}
   else if (y>200 && x>200)
      {maju();} 
     else if (y <200 && x>200) 
        {belokanan();
         luruskiri();} 
       else if (y>200 && x<200)
         {belokiri();
           luruskanan();} 
      } 

Tidak ada komentar:

Poskan Komentar