Translate

MONITOR BERAT DAN TINGGI BADAN, SUHU TUBUH, TENSIMETER IOT BLYNK

MONITOR BERAT DAN TINGGI BADAN, SUHU TUBUH, TENSIMETER IOT BLYNK


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat dengan beberapa parameter yaitu berat dan tinggi badan, suhu tubuh dan tensimeter digital. kemudian hasilnya dikirim ke Blynk 2.0. untuk lebih jelasnya berikut adalah kodingnya.


a. Komponen


b. Program Arduino IDE

#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
#include "HX711.h"
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
   
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define trigPin 2
#define echoPin 3
// HX711.DOUT    - pin #4
// HX711.PD_SCK    - pin #5
HX711 scale(4, 5);  
long duration, distance;
int x1 = 0;
int y1 = 150;
int x2 = 500;
int y2 = 150;
int dataadc;
unsigned long start;
float suhubenda;
float suhuruangan;
float tera = 0;
int berat;
float fix;
float kg;
float weight; 
float calibration_factor = 211000; // for me this vlaue works just perfect 211000  
int motor = 7;
int solenoid = 6;
int tombol = 8;
int tombolx;
int hitung;
float vol;
float mmhg;
float mmhgx;
float sistole;
float diastole;
int sistolex;
int diastolex;
int mark = 0;
float IMT;
int gol;
  
void setup() {
  mlx.begin();  
  Serial.begin(9600);
   lcd.begin();
   lcd.clear();
   lcd.noCursor();
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(motor,OUTPUT);
  pinMode(solenoid,OUTPUT);
  pinMode(tombol,INPUT_PULLUP);
  
  scale.set_scale(2280.f);       // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();                  // reset the scale to 0
   lcd.setCursor (0,0);
   lcd.print ("LOADING... ");
   delay(5000);
   lcd.clear();
}

void loop() {
 
  suhubenda = mlx.readObjectTempC();
  
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = 200 - ((duration/2) / 29.1);
  
  berat = scale.get_units(10) * -1;
  fix = (berat - 0.4233)/0.1586;
  
  lcd.setCursor(0,0);
  lcd.print(suhubenda,1);
  lcd.print("/");
  lcd.print(sistolex);
  lcd.print("/");
  lcd.print(diastolex);
  lcd.print("   ");
      
  lcd.setCursor(0,1);
  lcd.print(berat);
  lcd.print("/"); 
  lcd.print(distance);
  lcd.print("/"); 
  lcd.print(IMT);
  lcd.print("/"); 
  lcd.print(gol);
  lcd.print("   "); 
   tombolx = digitalRead(tombol); 
 if(tombolx == LOW){
  mark = 0;
  lcd.clear();
  delay(1000);
  digitalWrite(motor,HIGH);
  digitalWrite(solenoid,HIGH);
  mulai();
  }
IMT = berat / pow(distance,2);
Serial.print("*");
Serial.print(suhubenda * 100);
Serial.print(",");
Serial.print(berat * 100);
Serial.print(",");
Serial.print(distance);
Serial.print(",");
Serial.print(IMT * 100);
Serial.print(",");
Serial.print(sistole);
Serial.print(",");
Serial.print(diastole);
Serial.println("#"); 
  scale.power_down();                  
  delay(200);
  scale.power_up();    
  delay(200); 
}

void mulai(){
  
 dataadc = analogRead(A0);
 mmhg = (dataadc - 46.222) / 3.2;
if((mmhg >= mmhgx + 10)&&(mmhg > 100)&&(mark == 0)){
//digitalWrite(motor,LOW); 
Serial.println("SISTOLE"); 
sistole = mmhg;
mark = 2; 
digitalWrite(motor,LOW);
}
if((mmhg >= mmhgx + 5)&&(mmhg > 50)&&(mmhg < 90)&&(mark == 2)){
//digitalWrite(motor,LOW); 
Serial.println("DIASTOLE"); 
diastole = mmhg;
mark = 3;
}
 lcd.setCursor(0,1);
 lcd.print("S= ");
 lcd.print(mmhg);
 lcd.print("     ");
if(mmhg >= 150)
{
 digitalWrite(motor,LOW);   
}
mmhgx = mmhg;
Serial.println(mmhg);
if((mark == 3)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = diastole;
digitalWrite(solenoid,LOW);
return;  
}
if((mark == 2)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = random(60,90);
digitalWrite(solenoid,LOW);
return;  
}
if(IMT < 18.5){
gol = 1;  
}
if((IMT >= 18.5)&&(IMT < 25.9)){
gol = 2;  
}
if((IMT >= 25.9)&&(IMT < 27)){
gol = 3;  
}
if(IMT > 27){
gol = 4;  
}
delay(1);   
mulai();  
}


c. Program ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6u7QIXXXX
#define BLYNK_TEMPLATE_NAME "Pasien Monitor"
#define BLYNK_AUTH_TOKEN "MNElwijJcAWS6S1po8rO5RdpJEdXxXxX"
#define BLYNK_PRINT Serial   
#include <SPI.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int temp;
int x = 5;
int y;
int value1;
int value2;
int value3;
int value4;
int value5;
int value6;
float suhu;
float berat;
int distance;
float IMT;
int sistole;
int diastole;
float datain1;
float datain2;
float datain3;
float datain4;
float datain5;
float datain6;
String dataIn;
String dt[10];
int i;
boolean parsing=false;
BlynkTimer timer;
char ssid[] = "hotspothpku";
char pass[] = "123456789";
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
 Blynk.virtualWrite(V0, suhu);
 Blynk.virtualWrite(V1, berat);
 Blynk.virtualWrite(V2, distance);
 Blynk.virtualWrite(V3, IMT);
 Blynk.virtualWrite(V4, sistole);
 Blynk.virtualWrite(V5, diastole);
 delay(1000);
}
void setup()
{
 
  dataIn="";
  Serial.begin(9600);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, sendSensor);
}
void loop()
{
while(Serial.available()>0) {
//  dataIn="";
    char inChar = (char)Serial.read();
    dataIn += inChar;
    if (inChar == '\n') {
    parsing = true;
  }
}
if(parsing){
  parsingData();
   
  Blynk.run();
  timer.run();
}
}
void parsingData(){
int j=0;
//kirim data yang telah diterima sebelumnya
//Serial.print("data masuk : ");
//Serial.print(dataIn);
//Serial.print("\n");
//inisialisasi variabel, (reset isi variabel)
dt[j]="";
//proses parsing data
for(i=1;i<dataIn.length();i++){
//pengecekan tiap karakter dengan karakter (#) dan (,)
if ((dataIn[i] == '#') || (dataIn[i] == ','))
{
//increment variabel j, digunakan untuk merubah index array penampung
j++;
dt[j]="";       //inisialisasi variabel array dt[j]
}
else
{
//proses tampung data saat pengecekan karakter selesai.
dt[j] = dt[j] + dataIn[i];
}
}
datain1 = dt[0].toInt();
datain2 = dt[1].toInt();
datain3 = dt[2].toInt();
datain4 = dt[3].toInt();
datain5 = dt[4].toInt();
datain6 = dt[5].toInt();
//kirim data hasil parsing
Serial.print("data 1 : ");
Serial.print(datain1);
Serial.print("\n");
Serial.print("data 2 : ");
Serial.print(datain2);
Serial.print("\n");
Serial.print("data 3 : ");
Serial.print(datain3);
Serial.print("\n");
Serial.print("data 4 : ");
Serial.print(datain4);
Serial.print("\n");
suhu = datain1 / 100.0;
berat = datain2 / 100.0;
distance = datain3 / 1;
IMT = datain4 / 100.0;
sistole = datain5 / 1;
diastole = datain6 / 1;
}


d. VIDEO HASILNYA


TIMER LOMBA LARI DRAG RACE 1 LINE

TIMER LOMBA LARI DRAG RACE 1 LINE


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dipakai untuk timer lomba lari yang mana alat ini memiliki beberapa komponen yaitu DMD P10 Panel dan Arduino. untuk sensor menggunakan sensor proximity. untuk lebih jelasnya berikut adalah kodingnya.


a. Komponen


b. Program Arduino IDE

#include <Wire.h>
#include <SPI.h>        //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>        //Library DMD yang menyediakan fungsi penampilan teks, gambar dsb
#include <TimerOne.h>   //Library peripheral Timer1 untuk menjalankan prosedur pindai panel DMD
#include <Time.h>     //Library waktu yang menyediakan tipe data, struktur, dan obyek waktu
#include "Arial_black_16.h"
#include "Arial_Black_16_ISO_8859_1.h"
#include "Arial14.h"
#include "DejaVuSans9.h"
#include "Droid_Sans_12.h"
#include "Droid_Sans_16.h"
#include "DejaVuSansItalic9.h"
#include "Mono5x7.h"
#include "SystemFont5x7.h"

#define DISPLAY_COLUMN_COUNT  2
#define DISPLAY_ROW_COUNT     1

#define PIXELS_PER_COLUMN  32
#define PIXELS_PER_ROW    16

DMD dmd(DISPLAY_COLUMN_COUNT, DISPLAY_ROW_COUNT);
unsigned char show = 0;

char lineBuff[20];
int tombol = 12;
int tombolx;
int lineA;
int lineB;
int lineC;
int mulai;
int seconds;
int cs;
int secondsa;
int csa;
int secondsb;
int csb;
int secondsc;
int csc;

long start_time = 0;
int lapa,lapb,lapc;
int finisha = 0;

void ScanDMD()
{
  dmd.scanDisplayBySPI();
}

void setup(void)
{  
pinMode(2,INPUT);
pinMode(tombol,INPUT_PULLUP);

  dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)
  Serial.begin(9600);
   //initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
  Timer1.initialize( 1000 );           //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
  Timer1.attachInterrupt( ScanDMD );   //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
  //clear/init the DMD pixels held in RAM
  dmd.clearScreen( true );
}

void loop(void)
{

//============================================
lineA = digitalRead(2);

if(lineA == 0){
secondsa = seconds;
csa = cs;
finisha = 1;
dmd.clearScreen( true );
hasil();
}

//=============================================
tombolx = digitalRead(tombol);

if((tombolx == 0)&&(mulai == 0)){
  delay(200);
  mulai = 1;
  start_time = millis();  
}  

if(mulai == 1){
seconds = (millis() - start_time) / 1000;
cs = ((millis() - start_time) / 10) % 100;;
}

//===========================================================================  
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  
//===========================================================================

delay(1);
}

void hasil(){

sprintf(lineBuff, "%d:%d  ", secondsa, csa);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

hasil();
}


c. VIDEO HASILNYA


Monitor Tegangan Arus Daya KWH Meter Sensor PZEM-004t IOT BLYNK 2.0 ESP8266 NODEMCU

Monitor Tegangan Arus Daya KWH Meter Sensor PZEM-004t IOT BLYNK 2.0 ESP8266 NODEMCU


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur tegangan arus daya dari VAC 220v. alat ini menggunakan IoT Blynk untuk memonitornya dan juga untuk mengendalikan relaynya. untuk lebih jelasnya berikut adalah kodingnya.


a. Komponen


2. Program Arduino IDE

#define BLYNK_TEMPLATE_ID "TMPL651DVXXXX"
#define BLYNK_TEMPLATE_NAME "monitor daya"
#define BLYNK_AUTH_TOKEN "3_d7wLIQkxjAFuAe9_jY_IXSDrMXxXxx"
#define BLYNK_PRINT Serial    
#include <Wire.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
#include <PZEM004Tv30.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); 
 
PZEM004Tv30 pzem(D7,D8);  
float voltage;
float current;
float power;
int relay = D6;
int pinValue;
BlynkTimer timer;
char ssid[] = "hotspothpku";
char pass[] = "123456789";
BLYNK_WRITE(V3)
{
  pinValue = param.asInt();   
  if(pinValue == 1){
    digitalWrite(relay, LOW);
  }
  
  if(pinValue == 0) {
    digitalWrite(relay, HIGH);
  }
  
 Serial.print("button value is: "); 
 Serial.println(pinValue);
  
}
void sendSensor()
{
 Blynk.virtualWrite(V0, voltage);
 Blynk.virtualWrite(V1, current);
 Blynk.virtualWrite(V2, power);
 delay(1000);
}

void setup() {
  Serial.begin(9600);  
  lcd.begin();   
  lcd.noCursor();
  lcd.clear();
  pinMode(relay,OUTPUT);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, sendSensor);
}
 
void loop() {
 
voltage = pzem.voltage();
current = pzem.current();
power = pzem.power();
   
lcd.setCursor(0, 0);
lcd.print("V:");
lcd.print(voltage,1);
lcd.print(" P:");
lcd.print(power,1);
lcd.print("   ");
lcd.setCursor(0, 1);
lcd.print("I:");
lcd.print(current,1);
lcd.print("  ");
if(current > 5){
  digitalWrite(relay, LOW);
}

Blynk.run();
timer.run();
delay(200);
}


3. VIDEO HASILNYA



Monitor Tekanan Udara via BLYNK (IOT)

Monitor Tekanan Udara via BLYNK (IOT)

          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tekanan udara dalam satuan MPa. jika ingin merubah ke satuan lain bisa diubah sesuai rumusnya. untuk lebih jelasnya berikut adalah komponen dan kodingnya.

 

a. Komponen



b. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
float pressure_pascal;
float pressure_bar;
int dataadc;
int x;
float v;
float kpa;
float mpa;
void setup() {
 Serial.begin(9600); 
 lcd.begin();
 lcd.clear();
 lcd.noCursor();
}
void loop() {
 
  x = analogRead(A0);
  v = x*(5.0/1023.0);
  pressure_pascal = (3.0*(v-0.47))*1000000.0;
  pressure_bar = pressure_pascal/10e5;
  mpa = pressure_bar / 10.0;
 
  lcd.setCursor(0, 0);
  lcd.print("MPA= ");
  lcd.print(mpa);
  lcd.print("   ");
Serial.println(mpa * 1000);
 
delay(200);  
}


c. Program ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6fx_xxxxx"
#define BLYNK_TEMPLATE_NAME "Monitor Pressure"
#define BLYNK_AUTH_TOKEN "Vk4temfJ0R3jIhakzOxuTeCC2aIxxxxx"
#define BLYNK_PRINT Serial    
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int temp;
int x = 5;
int y;
int value1;
int value2;
int tekanan = 0;
float fix;
float datain1;
String dataIn;
String dt[10];
int i;
boolean parsing=false;
int pinValue;
int pinValue2;
int pinValue3;
BlynkTimer timer;
char ssid[] = "hotspothpku";
char pass[] = "123456789";
void sendSensor()
{
 Blynk.virtualWrite(V0, fix);
 delay(1000);
}

void setup()
{
  dataIn=""; 
  // Debug console
 Serial.begin(9600);
 Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
 timer.setInterval(1000L, sendSensor);
}
void loop()
{
  tekanan = Serial.parseInt();;
  fix = tekanan / 1000.0;
  
  Blynk.run();
  timer.run();
}


d VIDEO HASILNYA

Kendali Arah dan Kemiringan Sudut Motor Stepper Driver TB6600 Arduino

Kendali Arah dan Kemiringan Sudut Motor Stepper Driver TB6600 Arduino

           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan arah dan sudut kemiringan motor stepper dengan driver TB6600 dan Arduino Mega sebagai kontrolernya. sensor arah yang dipakai yaitu HMC5883L dan sudut kemiringan MPU6050. untuk lebih jelasnya berikut adalah koding dan komponennya.

 

a. Komponen
 

 

b. Program Arduino IDE

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
#include <SPI.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
#include <HMC5883L.h>
#include <TinyGPS.h>

#define dirPin 4
#define stepPin 5
#define stepsPerRevolution 800 // sesuaikan dengan settingan SW1-SW3 pada modul motor driver
#define dirPin2 2
#define stepPin2 3
#define stepsPerRevolution2 800 // sesuaikan dengan settingan SW1-SW3 pada modul motor driver

HMC5883L compass;

SoftwareSerial mySerial(10, 11);
TinyGPS gps;

LiquidCrystal_I2C lcd(0x27, 16, 2);

void gpsdump(TinyGPS &gps);
void printFloat(double f, int digits = 2);

int sudut;
float sudutku;
int nilaisudut = 0;
int nilaimiring = 0;
int nilaisudutfix;
int mark = 0;
int tanda;
int manual;
int motor;

char customKey;
const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {A0,A1,A2,A3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A4,A5,A6,A7}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;


void setup()
{
   Wire.begin();
   Wire.beginTransmission(MPU_addr);
   Wire.write(0x6B);  // PWR_MGMT_1 register
   Wire.write(0);     // set to zero (wakes up the MPU-6050)
   Wire.endTransmission(true);

   delay(10);
   lcd.begin();
   lcd.clear();
   lcd.noCursor();

  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin2, OUTPUT);
  pinMode(dirPin2, OUTPUT);
 
  // Oploen serial communications and wait for port to open:
  Serial.begin(9600);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  delay(1000);
  Serial.println();
  Serial.print("Sizeof(gpsobject) = ");
  Serial.println(sizeof(TinyGPS));
  Serial.println();

  // Initialize Initialize HMC5883L
  Serial.println("Initialize HMC5883L");
  while (!compass.begin())
  {
    Serial.println("Could not find a valid HMC5883L sensor, check wiring!");
    delay(500);
  }
 
  // Set measurement range
  compass.setRange(HMC5883L_RANGE_1_3GA);
  // Set measurement mode
  compass.setMeasurementMode(HMC5883L_CONTINOUS);
  // Set data rate
  compass.setDataRate(HMC5883L_DATARATE_30HZ);
  // Set number of samples averaged
  compass.setSamples(HMC5883L_SAMPLES_8);
  // Set calibration offset. See HMC5883L_calibration.ino
  compass.setOffset(0, 0);

}


void loop() // run over and over
{

  customKey = customKeypad.getKey();

    if(customKey >= '0' && customKey <= '9')
  {
      manual = manual * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print(manual);
  }
 
  lcd.setCursor(0,0);
  lcd.print("PILIH MENU ");   

  if((customKey == '*')&&(manual == 1)){
    for (int i = 0; i < 30; i++) {
      digitalWrite(dirPin, LOW); // putar CCW jarum jam
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
      digitalWrite(stepPin, LOW);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
    }
   }
   
  if((customKey == '#')&&(manual == 1)){
    for (int i = 0; i < 30; i++) {
      digitalWrite(dirPin, HIGH); // putar CCW jarum jam
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
      digitalWrite(stepPin, LOW);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
    }
   }

  if((customKey == '*')&&(manual == 2)){
    for (int i = 0; i < 30; i++) {
      digitalWrite(dirPin2, LOW); // putar CCW jarum jam
      digitalWrite(stepPin2, HIGH);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
      digitalWrite(stepPin2, LOW);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
    }
   }
   
  if((customKey == '#')&&(manual == 2)){
    for (int i = 0; i < 30; i++) {
      digitalWrite(dirPin2, HIGH); // putar CCW jarum jam
      digitalWrite(stepPin2, HIGH);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
      digitalWrite(stepPin2, LOW);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
    }
   }
                  
  if(customKey == 'A'){
    lcd.clear();    
    delay(1000);
    tampilgps();
    }

  if(customKey == 'B'){
    lcd.clear();    
    delay(1000);
    carititiknol();
    kompas();
    }

  if(customKey == 'C'){
    lcd.clear();    
    delay(1000);
    nilaimiring = 0;
    accel();
    }  

  if(customKey == 'D'){
    lcd.clear();    
    delay(1000);
    manual= 0;
    motor = 0;
    }      
 
}


void accel(){
 
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)   
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  Serial.print(AcX); Serial.println('a');
  Serial.print(AcY); Serial.println('b');

  sudutku = (AcX + 15013)/163.6;
   
  lcd.setCursor(0,0);
  lcd.print("SUDUT: ");
  lcd.print(sudutku);
  lcd.print("     ");
        
  customKey = customKeypad.getKey();
                  
  if(customKey == 'D'){
    lcd.clear();    
    delay(1000);
    return;
    }
    
  if(customKey >= '0' && customKey <= '9')
  {
      nilaimiring = nilaimiring * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print("X: ");
      lcd.print(nilaimiring);
      lcd.print("     ");
  }

    if(customKey == '*'){
    lcd.clear();    
    delay(200);
    tanda = 1;
    }

if((tanda == 1)&&(nilaimiring < 90)){
      digitalWrite(dirPin2, LOW); // putar CCW jarum jam
      digitalWrite(stepPin2, HIGH);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
      digitalWrite(stepPin2, LOW);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
}

if((tanda == 1)&&(nilaimiring >= 90)){
      digitalWrite(dirPin2, HIGH); // putar CW jarum jam
      digitalWrite(stepPin2, HIGH);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
      digitalWrite(stepPin2, LOW);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
}     

if((tanda == 1)&&(sudutku >= nilaimiring - 5)&&(sudutku <= nilaimiring + 5)){
      digitalWrite(dirPin2, LOW);
      digitalWrite(stepPin2, LOW);
      lcd.clear();
      delay(1000);
      tanda = 0;
      return;
}
 
accel();  
}


void tampilgps(){

  customKey = customKeypad.getKey();
                  
  if(customKey == 'D'){
    lcd.clear();    
    delay(1000);
    return;
    }
      
  bool newdata = false;
  unsigned long start = millis();
  // Every 5 seconds we print an update
  while (millis() - start < 5000)
  {
    if (mySerial.available())
   
    {
      char c = mySerial.read();
      //Serial.print(c);  // uncomment to see raw GPS data
      if (gps.encode(c))
      {
        newdata = true;
        break;  // uncomment to print new data immediately!
      }
    }
  }
 
  if (newdata)
  {
    Serial.println("Acquired Data");
    Serial.println("-------------");
    gpsdump(gps);
    Serial.println("-------------");
    Serial.println();
  }  

tampilgps();  
}



void kompas(){
customKey = customKeypad.getKey();

  if(customKey >= '0' && customKey <= '9')
  {
      nilaisudut = nilaisudut * 10 + (customKey - '0');
      lcd.setCursor(0,1);
      lcd.print("S:");
      lcd.print(nilaisudut);
      lcd.print("     ");
  }

  if(customKey == 'D'){
    lcd.clear();    
    delay(1000);
    return;
    }
    
  if(customKey == '*')
  {
   nilaisudutfix = nilaisudut;
   nilaisudut = 0;
   lcd.clear();
   mark = 1;
   delay(200);
  }

if(nilaisudutfix > 350){
nilaisudutfix = 350;
}

if(mark == 1){
delay(1000);
carititiknol();
carititik();
}

lcd.setCursor(0,1);
lcd.print("S:");
lcd.setCursor(8,1);
lcd.print("M:");
lcd.print(nilaisudutfix);
lcd.print("   ");

//============================================================================  
  Vector norm = compass.readNormalize();

  // Calculate heading
  float heading = atan2(norm.YAxis, norm.XAxis);

  float declinationAngle = (4.0 + (26.0 / 60.0)) / (180 / M_PI);
  heading += declinationAngle;

  // Correct for heading < 0deg and heading > 360deg
  if (heading < 0)
  {
    heading += 2 * PI;
  }

  if (heading > 2 * PI)
  {
    heading -= 2 * PI;
  }

  // Convert to degrees
  float headingDegrees = heading * 180/M_PI;

  lcd.setCursor(0,0);
  lcd.print("Sudut= ");
  lcd.print(headingDegrees);
  lcd.print("    ");

if((nilaisudutfix > 0)&&(headingDegrees < nilaisudutfix - 10)){
      digitalWrite(dirPin, HIGH); // putar CW jarum jam
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
      digitalWrite(stepPin, LOW);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
}

if((nilaisudutfix > 0)&&(headingDegrees > nilaisudutfix + 10)){
      digitalWrite(dirPin, LOW); // putar CCW jarum jam
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
      digitalWrite(stepPin, LOW);
      delayMicroseconds(1000); // ganti delay untuk mempercepat motor
}

kompas();  
}


void gpsdump(TinyGPS &gps)
{
  long lat, lon;
  float flat, flon;
  unsigned long age, date, time, chars;
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned short sentences, failed;

  gps.get_position(&lat, &lon, &age);
  Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon);
  Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
 
  gps.f_get_position(&flat, &flon, &age);
  Serial.print("Lat/Long(float): "); printFloat(flat, 5); Serial.print(", "); printFloat(flon, 5);
    Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");

  lcd.setCursor(0,0);
  lcd.print("LAT:");
  lcd.print(flat, 5);
 
  lcd.setCursor(0,1);
  lcd.print("LONG:");
  lcd.print(flon, 5);
 
}

void printFloat(double number, int digits)
{
  // Handle negative numbers
  if (number < 0.0)
  {
     Serial.print('-');
     number = -number;
  }

  // Round correctly so that print(1.999, 2) prints as "2.00"
  double rounding = 0.5;
  for (uint8_t i=0; i<digits; ++i)
    rounding /= 10.0;
 
  number += rounding;

  // Extract the integer part of the number and print it
  unsigned long int_part = (unsigned long)number;
  double remainder = number - (double)int_part;
  Serial.print(int_part);

  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
    Serial.print(".");

  // Extract digits from the remainder one at a time
  while (digits-- > 0)
  {
    remainder *= 10.0;
    int toPrint = int(remainder);
    Serial.print(toPrint);
    remainder -= toPrint;
  }
}



void carititiknol(){
 
//============================================================================  
  Vector norm = compass.readNormalize();

  // Calculate heading
  float heading = atan2(norm.YAxis, norm.XAxis);

  float declinationAngle = (4.0 + (26.0 / 60.0)) / (180 / M_PI);
  heading += declinationAngle;

  // Correct for heading < 0deg and heading > 360deg
  if (heading < 0)
  {
    heading += 2 * PI;
  }

  if (heading > 2 * PI)
  {
    heading -= 2 * PI;
  }

  // Convert to degrees
  float headingDegrees = heading * 180/M_PI;

  lcd.setCursor(0,0);
  lcd.print("Sudut= ");
  lcd.print(headingDegrees);
  lcd.print("    ");

if((headingDegrees >= 150)&&(headingDegrees <= 360)){  
  digitalWrite(dirPin, HIGH); // putar CW jarum jam
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  digitalWrite(stepPin, LOW);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
}

if((headingDegrees >= 1)&&(headingDegrees < 150)){
  digitalWrite(dirPin, LOW); // putar CCW jarum jam
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  digitalWrite(stepPin, LOW);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
}

if((headingDegrees >= 0)&&(headingDegrees < 3)){
mark = 0;
lcd.clear();
delay(1000);  
return;  
}  
 
carititiknol();
}



void carititik(){
 
//============================================================================  
  Vector norm = compass.readNormalize();

  // Calculate heading
  float heading = atan2(norm.YAxis, norm.XAxis);

  float declinationAngle = (4.0 + (26.0 / 60.0)) / (180 / M_PI);
  heading += declinationAngle;

  // Correct for heading < 0deg and heading > 360deg
  if (heading < 0)
  {
    heading += 2 * PI;
  }

  if (heading > 2 * PI)
  {
    heading -= 2 * PI;
  }

  // Convert to degrees
  float headingDegrees = heading * 180/M_PI;

  lcd.setCursor(0,0);
  lcd.print("Sudut= ");
  lcd.print(headingDegrees);
  lcd.print("    ");

if((nilaisudutfix >= 0)&&(nilaisudutfix <= 175)){  
  digitalWrite(dirPin, LOW); // putar CW jarum jam
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(1000); // ganti delay untuk mempercepat motor
  digitalWrite(stepPin, LOW);
  delayMicroseconds(1000); // ganti delay untuk mempercepat motor
}

if((nilaisudutfix >= 175)&&(nilaisudutfix < 350)){
  digitalWrite(dirPin, HIGH); // putar CCW jarum jam
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(1000); // ganti delay untuk mempercepat motor
  digitalWrite(stepPin, LOW);
  delayMicroseconds(1000); // ganti delay untuk mempercepat motor
}

if((headingDegrees >= nilaisudutfix - 10)&&(headingDegrees < nilaisudutfix + 10)){
mark = 0;   
digitalWrite(dirPin, LOW); // putar CCW jarum jam
digitalWrite(stepPin, LOW);
lcd.clear();
delay(1000);  
return;  
}

lcd.setCursor(0,1);
lcd.print("Cari Titik: ");
lcd.print(nilaisudutfix);
lcd.print("   ");  
 
carititik();
}


c. VIDEO HASILNYA