LAMPIRAN A
PROGRAM MIKROKONTROLER ARDUINO UNO
A.1 final.ino
#include <Sim800l.h>
#include <SoftwareSerial.h> //library!!
Sim800l Sim800l; //declare the library
//char* text;
//char* number;
bool error; //to catch the response of sendSms
#include "hx711.h"
int pirhasil=0;
int inputPin = 3; // choose the input pin
(for PIR sensor)
int pirState = LOW; // we start, assuming no
motion detected
int val = 0;
Hx711 scale(A0, A1);
void setup() {
Sim800l.begin();
Serial.begin(9600);
pinMode(inputPin, INPUT); // declare sensor as
input
}
void pir(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is
HIGH
if (pirState == LOW) {
// just turned on
pirhasil=1;
// print on the output change, not state
pirState = HIGH;
}
} else {
if (pirState == HIGH){
// we have just turned of
pirhasil=0;
// We only want to print on the output change, not
state
pirState = LOW;
}
}
}
void pintu(){
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(6, 255);
delay(1000);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
analogWrite(6, 150);
delay(1000);
}
void loop() {
int cahaya=analogRead(A2);
//<200 ada cahaya
int beban=scale.getGram();
//>13.5 ada beban
pir();
Serial.println(pirhasil);
delay(10);
if(beban>=7 ){
pir();
Serial.println(beban);
if(pirhasil=1||cahaya>200){
pintu();
Serial.println(pirhasil);
Serial.println(cahaya);
error=Sim800l.sendSms("082144308481","target
trapped ");
}
}
}