const int dirpin = 3;
const int steppin = 2;
const int stepsPerRevolution = 200; //jumlah putaran motor
int pirsensor = 1;
int pirstatus = 0;
int led = 4;
void setup() {
// put your setup code here, to run once:
pinMode( 3, OUTPUT);
pinMode( 2, OUTPUT);
pinMode( 1, INPUT);
pinMode( 4, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite( dirpin, HIGH); // PROGRAM UNTUK MOTOR
for (int x=0; x < stepsPerRevolution; x++) // MOTOR MULAI BERGERAK
{
digitalWrite( steppin, HIGH);
delayMicroseconds(20000);
digitalWrite( steppin, LOW);
delayMicroseconds(20000);
}
delay(1000);
pirstatus = digitalRead(pirsensor); // PROGRAM SENSOR GERAK
if (pirstatus == HIGH)
{
Serial.println("Ada Gerakan Terdeteksi");
digitalWrite(4, HIGH);
delay(5000);
}
else {
Serial.println("Tidak Ada Gerakan Terdeteksi");
digitalWrite(4, LOW);
}
delay(1000);
}