0% found this document useful (0 votes)
2 views2 pages

program arduino flower line

The document contains an Arduino code for controlling a robot with two motors and two sensors. It sets up the motor and sensor pins, and in the loop, it adjusts the robot's movement based on sensor readings to follow a line. The robot moves forward, turns left or right, or stops based on whether the sensors detect a black line.

Uploaded by

khairulsani874
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

program arduino flower line

The document contains an Arduino code for controlling a robot with two motors and two sensors. It sets up the motor and sensor pins, and in the loop, it adjusts the robot's movement based on sensor readings to follow a line. The robot moves forward, turns left or right, or stops based on whether the sensors detect a black line.

Uploaded by

khairulsani874
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

int in1 = 7; // pin yang digunakan

int in2 = 6; // pin yang digunakan


int in3 = 9; // pin yang digunakan
int in4 = 8; // pin yang digunakan
int enA = 10; // pin yang digunakan motor kanan
int enB = 5; // pin yang digunakan motor kiri

int Sensor_Kanan = A1;


int Sensor_Kiri = A0;

int Motor_SpeedA = 0; // speed of motor 1


int Motor_SpeedB = 0; // speed of motor 2

void setup() {
// put your setup code here, to run once:
pinMode(enA, OUTPUT); // motor A sebelah kanan
pinMode(enB, OUTPUT); // motor B sebelah kiri
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);

pinMode(A1, INPUT); // sensor kanan


pinMode(A0, INPUT); // sensor kiri
}

void loop() {

Motor_SpeedA = 200; // Left Rotation Speed


Motor_SpeedB = 200; // Right Rotation Speed
analogWrite(enA, Motor_SpeedA); // speed of motor 1
analogWrite(enB, Motor_SpeedB); // speed of motor 2

int Sensor_KananA1= digitalRead(A1);


int Sensor_KiriA0= digitalRead(A0);

if((Sensor_KananA1==LOW)&&(Sensor_KiriA0==LOW))
{
//kedua sensor tidak mengenai garis hitam
//gerak maju
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
}
else if((Sensor_KananA1==HIGH)&&(Sensor_KiriA0==LOW))
{
//sensor kiri mendeteksi garis hitam
//belok kiri
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
}
else if((Sensor_KananA1==LOW)&&(Sensor_KiriA0==HIGH))
{
//sensor kanan mendeteksi garis hitam
//belok kanan
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
}
else{
//kedua sensor mendeteksi
//stop
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in4,LOW);
}
}

You might also like