Riko Putro Nugroho
Published © GPL3+

Tugas Orkom - Gembok Sepeda Pintar Dengan Sensor

Berikut ialah langkah-langkah dan penjelasan tentang gembok sepeda pintar

EasyWork in progress2 hours232
Tugas Orkom - Gembok Sepeda Pintar Dengan Sensor

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Vibration Sensor Module - SW-420
×1
Buzzer
Buzzer
×1
Jumper wires (generic)
Jumper wires (generic)
×1
9V Battery Clip
9V Battery Clip
×1
9V battery (generic)
9V battery (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

PIR , Buzzer and SW-420

Tugasorkom fxqu6op8pg

Code

Code

Arduino
int ledPin = 13;                                           // Memilih pin indikator LED
int inputPin = 2;                                         // Memilih input PIR Sensor
int pirState = LOW;                                 // Pada saat mulai, Matikan sensor
int val = 0;                                               // Variable pembaca status pin
int pinSpeaker = 10;                               // Memilih pin buzzer, dengan pin PWM
void setup() {
  pinMode(ledPin, OUTPUT);                // jadikan LED sebagai Output
  pinMode(inputPin, INPUT);               // jadikan Sensor sebagai Input
  pinMode(pinSpeaker, OUTPUT);      // jadikan buzzer sebagai output
  Serial.begin(9600);
}
void loop(){
  val = digitalRead(inputPin);
  if (val == HIGH) {
    digitalWrite(ledPin, HIGH);
    playTone(300, 160);
    delay(150);
  
    if (pirState == LOW) {
      Serial.println("Terdeteksi suatu pergerakan!");
      pirState = HIGH;
    }
  } else {
      digitalWrite(ledPin, LOW);
      playTone(0, 0);
      delay(300);   
      if (pirState == HIGH){
      Serial.println("Motion ended!");
      pirState = LOW;
    }
  }
}
void playTone(long duration, int freq) {
    duration *= 1000;
    int period = (1.0 / freq) * 1000000;
    long elapsed_time = 0;
    while (elapsed_time < duration) {
        digitalWrite(pinSpeaker,HIGH);
        delayMicroseconds(period / 2);
        digitalWrite(pinSpeaker, LOW);
        delayMicroseconds(period / 2);
        elapsed_time += (period);
    }
}

Credits

Riko Putro Nugroho

Riko Putro Nugroho

0 projects • 0 followers

Comments

Add projectSign up / Login