Вы находитесь на странице: 1из 18

LAMPIRAN

Lampiran 1 Datasheet Komponen


Sensor Suara
Sensor Suhu MLX90614
Modul DFPlayer Mini
Motor servo
Lampiran 2 Skema Sistem Keseluruhan
Lampiran 3 Listing Program
Program Pada NodeMCU

#include <CTBot.h>
#include <CTBotDataStructures.h>
#include <CTBotInlineKeyboard.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#define PIN_BUSY D5
#include "CTBot.h"
#include <Servo.h>
CTBot myBot;
CTBotInlineKeyboard myKbd; // custom inline keyboard object helper

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

# define Start_Byte 0x7E


# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00:
no info]

#define SUHU_OBJEK "Suhu Objek"


#define SUHU_SEKITAR "Suhu Sekitar"

#define SEBELUM "Lagu Selanjutnya"


#define PLAY "Play"
#define PAUSE "Pause"
#define SELANJUT "Lagu Sebelumnya"
#define SERVO "Putar Servo"

float suhu_objek, suhu_sekitar;


char ssid[] = "#PersibBandung";
char password[] = "saepulh98";
String token = "768167303:AAESj-nO2pnVWK66IC50-Zwr6OSzMAMOiaE";
// REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN
int lagu;
String chat_id = "736244177";

Servo myservo;
int pos = 0;

SoftwareSerial mySerial(D1, D2); // RX and TX


WiFiClientSecure client;
UniversalTelegramBot bot(token, client);

void setup() {
Serial.begin(250000);
pinMode(D0,OUTPUT);
myservo.attach(D4);
mySerial.begin(9600);
setVolume(20);
Serial.println("Starting TelegramBot...");
Wire.begin(D6, D7); //(SDA,SCL)
Serial.println("Adafruit MLX90614 test");
mlx.begin();
Serial.println("Setting up software serial");
// set the telegram bot token
myBot.setTelegramToken(token);
// check if all things are ok
if (myBot.testConnection())
Serial.println("\nTelegram Terhubung!");
else
Serial.println("\nTelegram Tidak Terhubung!");

myKbd.addButton("MENU SUHU","saepulassegaf05@gmail.com",
CTBotKeyboardButtonURL);
myKbd.addRow();
myKbd.addButton("SUHU OBJEK", SUHU_OBJEK,
CTBotKeyboardButtonQuery);
myKbd.addButton("SUHU SEKITAR", SUHU_SEKITAR,
CTBotKeyboardButtonQuery);
myKbd.addRow();
myKbd.addButton("MUSIC PLAYER","saepulassegaf05@gmail.com",
CTBotKeyboardButtonURL);
myKbd.addRow();
myKbd.addButton("< PREV", SEBELUM, CTBotKeyboardButtonQuery);
myKbd.addButton("PLAY", PLAY, CTBotKeyboardButtonQuery);
myKbd.addButton("PAUSE", PAUSE, CTBotKeyboardButtonQuery);
myKbd.addButton("NEXT >", SELANJUT, CTBotKeyboardButtonQuery);
myKbd.addRow();
myKbd.addButton("SERVO","saepulassegaf05@gmail.com",
CTBotKeyboardButtonURL);
myKbd.addRow();
myKbd.addButton("Putar Servo", SERVO, CTBotKeyboardButtonQuery);
}

void loop() {
while(Serial.available()>0){
char nilai = Serial.read();
if(nilai == '1'){
Serial.print(nilai);
mengirimpesan();
// putarservo();
}
else if (nilai == '0'){
Serial.print(nilai);
digitalWrite(D0,LOW);
}
}

suhu_objek = mlx.readObjectTempC();
suhu_sekitar = mlx.readAmbientTempC();
// a variable to store telegram message data
TBMessage msg;

Serial.print("Ambient = "); Serial.println(suhu_sekitar);


Serial.print("*C\tObject = "); Serial.println(suhu_objek);

Serial.println();
delay(100);

// if there is an incoming message...


if (myBot.getNewMessage(msg)) {
// check what kind of message I received
if (msg.messageType == CTBotMessageText) {
// received a text message
if (msg.text.equalsIgnoreCase("Tampilkan Menu")) {
// the user is asking to show the inline keyboard --> show it
myBot.sendMessage(msg.sender.id, "MENU ", myKbd);
}
else {
// the user write anithing else --> show a hint message
myBot.sendMessage(msg.sender.id, "Ketik 'Tampilkan Menu' . .");
}
} else if (msg.messageType == CTBotMessageQuery) {
// received a callback query message
if (msg.callbackQueryData.equals(SUHU_OBJEK)) {
myBot.sendMessage(msg.sender.id, "Suhu Objek: "+ String(suhu_objek)+
" C"); // notify the sender
// terminate the callback with an alert message
} else if (msg.callbackQueryData.equals(SUHU_SEKITAR)) {
myBot.sendMessage(msg.sender.id, "Suhu Sekitar: "+
String(suhu_sekitar)+ " C"); // notify the sender
} else if (msg.callbackQueryData.equals(SEBELUM)) {
myBot.endQuery(msg.callbackQueryID, "Lagu Sebelumnya");
playPrevious();
} else if (msg.callbackQueryData.equals(PLAY)) {
myBot.endQuery(msg.callbackQueryID, "Lagu diputar");
play();
} else if (msg.callbackQueryData.equals(PAUSE)) {
myBot.endQuery(msg.callbackQueryID, "Lagu Dijeda"); // notify the
sender
pause();
} else if (msg.callbackQueryData.equals(SELANJUT)) {
myBot.endQuery(msg.callbackQueryID, "Lagu Selanjutnya"); // notify the
sender
playNext();
} else if (msg.callbackQueryData.equals(SERVO)) {
myBot.endQuery(msg.callbackQueryID, "Putar Servo"); // notify the
sender
putarservo();
}
}
}
// wait 500 milliseconds
delay(500);

void playFirst()
{
execute_CMD(0x3F, 0, 0); // Initialize system
delay(100);
setVolume(20);
delay(100);
execute_CMD(0x11,1,1);
//delay(500);
}

void play()
{
// 0x0D command to play and the folder 00 and the file 001
execute_CMD(0x0D,0,1);
delay(100);
}
void playNext()
{
execute_CMD(0x01,0,1);
delay(100);
}
void playPrevious()
{
execute_CMD(0x02,0,1);
delay(100);
}
void pause()
{
execute_CMD(0x0E,0,0);
delay(100);
}
void setVolume(int volume)
{
// 0x06 - Command to set volume
execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
delay(100);
}

void execute_CMD(byte CMD, byte Par1, byte Par2)


// Excecute the command and parameters
{
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge
+ Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length,
CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
//Send the command line to the module
for (byte k=0; k<10; k++)
{
mySerial.write( Command_line[k]);
}

}
void mengirimpesan(){
digitalWrite(D0,HIGH);
delay(500);
digitalWrite(D0,LOW);
delay(500);
bot.sendMessage(chat_id, "Bayi Menangis", "");
delay(10000);
}

void putarservo() {

for(pos = 0; pos < 180; pos += 3)


{
myservo.write(pos);
delay(15);
}
for(pos = 180; pos>=0; pos-=3)
{
myservo.write(pos);
delay(15);
}
}

Program Pada Arduino Uno

int led = 3;
char data;

unsigned long last_pulse_time_counter, present_time;


byte last_PIN_state;
int Pulse_width;
//Variables
float Period = 0;
float Frequency_micro = 0;
float Frequency = 0;
int Pulse_amount = 0;
int pulse_is_measured = 0;

void setup() {

PCICR |= (1 << PCIE0);


PCMSK0 |= (1 << PCINT0);

pinMode(led,OUTPUT);

Serial.begin(250000);

void loop() {

if(pulse_is_measured)
{
pulse_is_measured = 0;
Period = Pulse_width*2;
Frequency_micro = 1/Period;
Frequency = Frequency_micro*1000000;

if(Frequency >=1000 && Frequency <=5000 )


{
Serial.print("Freq: ");
Serial.print(Frequency);
Serial.println(" ");
if(Pulse_amount >= 5)
{

digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
data = '1';
Serial.print(data);

Pulse_amount=0;
}
Pulse_amount = Pulse_amount+1;

}//end of frequency range detect

else
{
Pulse_amount=0;
}
}//end of if pulse is measured

}//end of loop

//This is the pulse width interruption routine


//----------------------------------------------

ISR(PCINT0_vect){
present_time = micros();
///////////////////////////////////////Signal input
if(PINB & B00000001){
if(last_PIN_state == 0){
last_PIN_state = 1;
last_pulse_time_counter = present_time;
}
}
else if(last_PIN_state == 1){
last_PIN_state = 0;
Pulse_width = present_time - last_pulse_time_counter;
pulse_is_measured = 1;
}

}
Lampiran 4 Jadwal Pelaksanaan TA

No Jenis Kegiatan Bulan


1 2 3 4 5
1 Survey Harga Komponen v
2 Riset Rangkaian v v
Elektronik, Program, dan
Metode Kendali
3 Pembelian Komponen dan v v
Material Mekanik
4 Ujicoba Rangkaian dan v v
Program
5 Ujicoba Subsistem dan v v v
Sistem Secara Keseluruhan
6 Pengerjaan Mekanik v v v

7 Analisis dan Pemecahan v v v


Masalah
8 Pembuatan Laporan v v v v

Вам также может понравиться