Alat Kendali Servo dan Monitor Jarak HC-SRF04 + SMS Gateway
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan posisi servo dan monitor jarak serta alat ini juga bisa melakukan sms jika jarak kurang dari 10 cm. untuk lebih jelasnya berikut adalah program dan daftar komponennya.
a. Arduino Uno
b. Motor Servo
c. Sensor Jarak HC-SRF04
d. Modul SMS SIM900A
e. Program Arduino IDE
#include "SIM900.h"
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Servo.h>
#define trigPin1 6
#define echoPin1 7
#include "sms.h"
SMSGSM sms;
long duration1, distance1;
Servo myservo1;
int relay1 = 4;
int relay2 = 5;
int buzzer = 10;
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
void setup() {
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400)) {
Serial.println("\nstatus=READY");
started=true;
} else Serial.println("\nstatus=IDLE");
if(started) {
//Enable this two lines if you want to send an SMS.
if (sms.SendSMS("085733400808", "Alat Ready"))
Serial.println("\nSMS sent OK");
}
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
myservo1.attach(9);
myservo1.write(100);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
pinMode(buzzer,OUTPUT);
digitalWrite(buzzer,HIGH);
}
void loop() {
//goreng krupuk
myservo1.write(100);
delay(3000);
digitalWrite(relay1,LOW);
delay(20000);
//angkat krupuk
digitalWrite(relay1,HIGH);
delay(1000);
myservo1.write(150);
delay(3000);
digitalWrite(trigPin1, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = (duration1/2) / 29.1;
Serial.println(distance1);
if(distance1 < 10){
if (sms.SendSMS("085733400808", "Tempat Krupuk Penuh"))
Serial.println("\nSMS sent OK");
digitalWrite(buzzer,LOW);
berhenti();
}
if(distance1 > 10){
digitalWrite(buzzer,HIGH);
}
}
void berhenti(){
digitalWrite(trigPin1, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = (duration1/2) / 29.1;
Serial.println(distance1);
myservo1.write(100);
digitalWrite(relay1,HIGH);
if(distance1 > 10){
return;
}
berhenti();
}
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Servo.h>
#define trigPin1 6
#define echoPin1 7
#include "sms.h"
SMSGSM sms;
long duration1, distance1;
Servo myservo1;
int relay1 = 4;
int relay2 = 5;
int buzzer = 10;
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
void setup() {
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400)) {
Serial.println("\nstatus=READY");
started=true;
} else Serial.println("\nstatus=IDLE");
if(started) {
//Enable this two lines if you want to send an SMS.
if (sms.SendSMS("085733400808", "Alat Ready"))
Serial.println("\nSMS sent OK");
}
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
myservo1.attach(9);
myservo1.write(100);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
pinMode(buzzer,OUTPUT);
digitalWrite(buzzer,HIGH);
}
void loop() {
//goreng krupuk
myservo1.write(100);
delay(3000);
digitalWrite(relay1,LOW);
delay(20000);
//angkat krupuk
digitalWrite(relay1,HIGH);
delay(1000);
myservo1.write(150);
delay(3000);
digitalWrite(trigPin1, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = (duration1/2) / 29.1;
Serial.println(distance1);
if(distance1 < 10){
if (sms.SendSMS("085733400808", "Tempat Krupuk Penuh"))
Serial.println("\nSMS sent OK");
digitalWrite(buzzer,LOW);
berhenti();
}
if(distance1 > 10){
digitalWrite(buzzer,HIGH);
}
}
void berhenti(){
digitalWrite(trigPin1, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = (duration1/2) / 29.1;
Serial.println(distance1);
myservo1.write(100);
digitalWrite(relay1,HIGH);
if(distance1 > 10){
return;
}
berhenti();
}
f. VIDEO HASILNYA
No comments:
Post a Comment