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


 

Robot Pendeteksi Warna Arduino

Robot Pendeteksi Warna Arduino


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana membuat sebuah robot beroda yang dapat mendeteksi beberapa warna sekaligus. alat yang dideteksi yaitu kuning, merah, hijau, hitam, biru. alat ini menggunakan sensor Tcs3200 dan Arduino Uno. untuk lebih jelasnya berikut adalah koding dan komponennya. 



a. Komponen




b. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define S0 12
#define S1 11
#define S2 8
#define S3 7
#define sensorOut 9
int frequency = 0;

int fmerah;
int fgreen;
int fblue;
int btkuning = 2;
int bthitam = 3;
int bthijau = 4;
int btbiru = 5;
int btmerah = 6;
int btkuningx;
int bthitamx;
int bthijaux;
int btbirux;
int btmerahx;
int btonmotor = 13;
int btonmotorx;

int motorkiri1 = A3;
int motorkiri2 = A2;
int motorkanan1 = A0;
int motorkanan2 = A1;

int fmerahatasku,fmerahatashi,fmerahatashij,fmerahatasbi,fmerahatasme;
int fmerahbawahku,fmerahbawahhi,fmerahbawahhij,fmerahbawahbi,fmerahbawahme;
int fgreenatasku,fgreenatashi,fgreenatashij,fgreenatasbi,fgreenatasme;
int fgreenbawahku,fgreenbawahhi,fgreenbawahhij,fgreenbawahbi,fgreenbawahme;
int fblueatasku,fblueatashi,fblueatashij,fblueatasbi,fblueatasme;
int fbluebawahku,fbluebawahhi,fbluebawahhij,fbluebawahbi,fbluebawahme;

void setup()
{
 lcd.begin();
 lcd.clear();
 lcd.noCursor();

  pinMode(btkuning,INPUT_PULLUP);
  pinMode(bthitam,INPUT_PULLUP);
  pinMode(bthijau,INPUT_PULLUP);
  pinMode(btbiru,INPUT_PULLUP);
  pinMode(btmerah,INPUT_PULLUP);
  pinMode(btonmotor,INPUT_PULLUP);
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(sensorOut, INPUT);
  digitalWrite(S0,HIGH);
  digitalWrite(S1,LOW);

  pinMode(motorkiri1, OUTPUT);
  pinMode(motorkiri2, OUTPUT);
  pinMode(motorkanan1, OUTPUT);
  pinMode(motorkanan2, OUTPUT);
 
}

void loop(){

btonmotorx = digitalRead(btonmotor);
btkuningx = digitalRead(btkuning);
bthitamx = digitalRead(bthitam);
bthijaux = digitalRead(bthijau);
btbirux = digitalRead(btbiru);
btmerahx = digitalRead(btmerah);

  digitalWrite(S2,LOW);
  digitalWrite(S3,LOW);
  frequency = pulseIn(sensorOut, LOW);
  fmerah = frequency;

  lcd.setCursor(0,0);
  lcd.print(fmerah);
  lcd.print(" ");
  delay(100);

  digitalWrite(S2,HIGH);
  digitalWrite(S3,HIGH);
  frequency = pulseIn(sensorOut, LOW);
  fgreen = frequency;

  lcd.print(fgreen);
  lcd.print(" ");
  delay(100);

  digitalWrite(S2,LOW);
  digitalWrite(S3,HIGH);
  frequency = pulseIn(sensorOut, LOW);
  fblue = frequency;

  lcd.print(fblue);
  lcd.print("  ");
  delay(800);

if(btkuningx == 0){
  delay(200);
  fmerahatasku = fmerah + 5;
  fmerahbawahku = fmerah - 5;
  fgreenatasku = fgreen + 5;
  fgreenbawahku = fgreen - 5;
  fblueatasku = fblue + 5;
  fbluebawahku = fblue - 5;    
}

if(bthitamx == 0){
  delay(200);
  fmerahatashi = fmerah + 5;
  fmerahbawahhi = fmerah - 5;
  fgreenatashi = fgreen + 5;
  fgreenbawahhi = fgreen - 5;
  fblueatashi = fblue + 5;
  fbluebawahhi = fblue - 5;    
}

if(bthijaux == 0){
  delay(200);
  fmerahatashij = fmerah + 5;
  fmerahbawahhij = fmerah - 5;
  fgreenatashij = fgreen + 5;
  fgreenbawahhij = fgreen - 5;
  fblueatashij = fblue + 5;
  fbluebawahhij = fblue - 5;    
}

if(btbirux == 0){
  delay(200);
  fmerahatasbi = fmerah + 5;
  fmerahbawahbi = fmerah - 5;
  fgreenatasbi = fgreen + 5;
  fgreenbawahbi = fgreen - 5;
  fblueatasbi = fblue + 5;
  fbluebawahbi = fblue - 5;    
}

if(btmerahx == 0){
  delay(200);
  fmerahatasme = fmerah + 5;
  fmerahbawahme = fmerah - 5;
  fgreenatasme = fgreen + 5;
  fgreenbawahme = fgreen - 5;
  fblueatasme = fblue + 5;
  fbluebawahme = fblue - 5;    
}

if(btonmotorx == 0){
  delay(200);
  digitalWrite(motorkiri1,HIGH);
  digitalWrite(motorkiri2,LOW);
  digitalWrite(motorkanan1,HIGH);
  digitalWrite(motorkanan2,LOW);
}

if(btonmotorx == 1){
  delay(200);
  digitalWrite(motorkiri1,LOW);
  digitalWrite(motorkiri2,LOW);
  digitalWrite(motorkanan1,LOW);
  digitalWrite(motorkanan2,LOW);
}

if((fmerah < fmerahatasku)&&(fmerah > fmerahbawahku)&&(fgreen < fgreenatasku)&&(fgreen > fgreenbawahku)&&(fblue < fblueatasku)&&(fblue > fbluebawahku)){
  lcd.setCursor(0,1);
  lcd.print("KUNING        ");    
}

if((fmerah < fmerahatashi)&&(fmerah > fmerahbawahhi)&&(fgreen < fgreenatashi)&&(fgreen > fgreenbawahhi)&&(fblue < fblueatashi)&&(fblue > fbluebawahhi)){
  lcd.setCursor(0,1);
  lcd.print("HITAM        ");    
}

if((fmerah < fmerahatashij)&&(fmerah > fmerahbawahhij)&&(fgreen < fgreenatashij)&&(fgreen > fgreenbawahhij)&&(fblue < fblueatashij)&&(fblue > fbluebawahhij)){
  lcd.setCursor(0,1);
  lcd.print("HIJAU       ");    
}

if((fmerah < fmerahatasbi)&&(fmerah > fmerahbawahbi)&&(fgreen < fgreenatasbi)&&(fgreen > fgreenbawahbi)&&(fblue < fblueatasbi)&&(fblue > fbluebawahbi)){
  lcd.setCursor(0,1);
  lcd.print("BIRU       ");    
}

if((fmerah < fmerahatasme)&&(fmerah > fmerahbawahme)&&(fgreen < fgreenatasme)&&(fgreen > fgreenbawahme)&&(fblue < fblueatasme)&&(fblue > fbluebawahme)){
  lcd.setCursor(0,1);
  lcd.print("MERAH      ");    
}
}



c. VIDEO HASILNYA



Monitor Arus dan Tegangan 3 Fasa IOT BLYNK GRAFIK REALTIME

Monitor Arus dan Tegangan 3 Fasa IOT BLYNK GRAFIK REALTIME


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk monitor arus dan tegangan 3 fasa dengan menggunakan IOT Blynk sehingga bisa dilakukan monitor secara jarak jauh menggunakan web atau handphone. untuk lebih jelasnya berikut adalah koding dan komponennya.



a. Komponen




b. Program Arduino Mega

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <PZEM004Tv30.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27,16,2); 
PZEM004Tv30 pzem1(A12, A13);
PZEM004Tv30 pzem2(A8, A9);
PZEM004Tv30 pzem3(A10, A11);
int voltage1, voltage2, voltage3;
float arusR, arusS, arusT;

void setup() {
  lcd.begin();   
  lcd.noCursor();
  lcd.clear();
  Serial.begin(9600);    
}

void loop() {
  
voltage1 = pzem1.voltage();
voltage2 = pzem2.voltage();
voltage3 = pzem3.voltage();
arusR = pzem1.current();
arusS = pzem2.current();
arusT = pzem3.current();

lcd.setCursor(0, 0);
lcd.print(voltage1);
lcd.print("/");
lcd.print(voltage2);
lcd.print("/");
lcd.print(voltage3);
lcd.print(" ");

lcd.setCursor(0, 1);
lcd.print(arusR);
lcd.print("/");
lcd.print(arusS);
lcd.print("/");
lcd.print(arusT);
lcd.print(" ");

Serial.print("*");
Serial.print(arusR * 100.0);
Serial.print(",");
Serial.print(arusS * 100.0);
Serial.print(",");
Serial.print(arusT * 100.0);
Serial.println("#");  

delay(200);
}



c. Program NodeMCU ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6lXvbTxXX"
#define BLYNK_TEMPLATE_NAME "MONITOR ARUS"
#define BLYNK_AUTH_TOKEN "6WRDw9uHuqd0543E7fG2wccvWWxxxxxx"

#define BLYNK_PRINT Serial    

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

int temp;
int x = 5;
int y;

int value1;
int value2;

float tegangan1 = 0;
float tegangan2 = 0;
float tegangan3 = 0;
float arusR = 0;
float arusS = 0;
float arusT = 0;

float datain1;
float datain2;
float datain3;
float datain4;
float datain5;
float datain6;

String dataIn;
String dt[10];
int i;
boolean parsing=false;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "4G MIFI-6499";
char pass[] = "1234567891";

BlynkTimer timer;


void sendSensor()
{

 Blynk.virtualWrite(V5, arusR);
 Blynk.virtualWrite(V6, arusS);
 Blynk.virtualWrite(V7, arusT);
 delay(1000);

}

void setup()
{
  
  dataIn=""; 
  // Debug console
  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();

/*
//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");
Serial.print("data 5 : ");
Serial.print(datain5);
Serial.print("\n");
Serial.print("data 6 : ");
Serial.print(datain6);
Serial.print("\n");
*/

 arusR = datain1 / 100.0;
 arusS = datain2 / 100.0;
 arusT = datain3 / 100.0;

}



d, VIDEO HASILNYA



ROBOT LENGAN ARDUINO

ROBOT LENGAN ARDUINO  
 

          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah robot lengan untuk edukasi atau belajar program dengan menggunakan Arduino. jadi robot ini menggunakan 4 buah servo sehingga robot ini bisa melakukan gerakan kanan kiri, atas bawah, maju mundur, dan japit lepas. untuk lebih jelasnya berikut adalah program dan komponennya.



a. Robot Lengan



 
 
b. Program Arduino IDE

#include<Wire.h>
#include<Servo.h>

Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo5;

int a;
int b;
int c;
int d;
int e;

void setup(){
myservo1.attach(11); //kanan kiri
myservo2.attach(9); //maju mundur
myservo3.attach(10); //turun naik
myservo5.attach(6); //japit lepas

 myservo1.write(70);
 myservo2.write(130);
 myservo3.write(150);
 myservo5.write(150);
 delay(3000);
}

void loop(){
 
kanan();  
turun();
maju();
japit();
mundur();
naik();

kiri();  
turun();
maju();
lepas();
mundur();
naik();

}

void kanan(){
  for(a=70;a<=150;a++){
  myservo1.write(a);
  delay(50);
  }
  return;
}

void kiri(){
  for(a=150;a>=70;a--){
  myservo1.write(a);
  delay(50);
  }
  return;
}

void mundur(){
  for(b=130;b>=100;b--){
  myservo2.write(b);
  delay(50);
  }
  return;
}

void maju(){
  for(b=100;b<=130;b++){
  myservo2.write(b);
  delay(50);
  }
  return;
}

void naik(){
  for(c=150;c>=90;c--){
  myservo3.write(c);
  delay(50);
  }
  return;
}

void turun(){
  for(c=90;c<=150;c++){
  myservo3.write(c);
  delay(50);
  }
  return;
}

void japit(){
  for(e=100;e>=30;e--){
  myservo5.write(e);
  delay(50);
  }
  return;
}

void lepas(){
  for(e=30;e<=100;e++){
  myservo5.write(e);
  delay(50);
  }
  return;
}
 
 
 
c. VIDEO HASILNYA



Monitor Suhu Sensor PT100 ESP32 IOT BLYNK

Monitor Suhu Sensor PT100 ESP32 IOT BLYNK


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur suhu suatu ruangan dengan menggunakan sensor PT100 yang dilengkapi amplifier untuk pengkondisi sinyal. alat ini juga dilengkapi fitur IOT Blynk sehingga dapat memonitor device secara jarak jauh.



a. Komponen




b. Program Arduino IDE

#define BLYNK_TEMPLATE_ID "TMPL6BDtMpxxx"
#define BLYNK_TEMPLATE_NAME "SUHU"
#define BLYNK_AUTH_TOKEN "qanCOAe3V1JrtNQ4Vel5GatTWVr2Oxxx"

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

BlynkTimer timer;
int dataadc1;
int dataadc2;
float faktor_kalibrasi = 7.0;
float voltage1;
float voltage2;
float suhu1;
float suhu2;
float mbg;
float gfast = 80;
float a;
float gref;
float tref = 0.45;
float DT, ttragus,tanti,HA,G;
 
char ssid[] = "hotspothpku";
char pass[] = "123456789";

void senddata() {
    Blynk.virtualWrite(V0, ttragus);
    Blynk.virtualWrite(V1, tanti);
    Blynk.virtualWrite(V2, G);
}

void setup() {
  Serial.begin(9600);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, senddata);
}

void loop() {

  dataadc1 = analogRead(34);
  dataadc2 = analogRead(35);

  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5000mV):
  voltage1 = (dataadc1 * (3.3 / 4095.0)) * 1000.0; 
  //dihitung dg arus 1 mA dan 100 ohm pada suhu 0 deg celc maka didapatkan V pada suhu 0 deg celc = 100 mV
  suhu1 = ((voltage1-100)/0.385)-faktor_kalibrasi; // 100 mV at 0 deg celc dan 0.385 mV per 1 deg celc

  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5000mV):
  voltage2 = (dataadc2 * (3.3 / 4095.0)) * 1000.0; 
  //dihitung dg arus 1 mA dan 100 ohm pada suhu 0 deg celc maka didapatkan V pada suhu 0 deg celc = 100 mV
  suhu2 = ((voltage2-100)/0.385)-faktor_kalibrasi; // 100 mV at 0 deg celc dan 0.385 mV per 1 deg celc

  ttragus = suhu1 / 100.0;
  tanti = suhu2 / 100.0;

  mbg = (33.3 * 5)-86;
  a = mbg * gfast;
  gref = sqrt(a);
  DT = ttragus - tanti;
  HA = ((tref-DT)/0.024);
  G = gref + HA;
  
  Blynk.run();
  timer.run();
}




c. VIDEO HASILNYA



Monitor Timbangan Bayi Digital IOT BLYNK ESP32 / NODEMCU ESP8266

Monitor Timbangan Bayi Digital IOT BLYNK ESP32 / NODEMCU ESP8266


      Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah timbangan digital dengan menggunakan ESP32 atau Nodemcu ESP8266 dengan fitur yaitu bisa mengukur berat dan tinggi bayi lalu mengirimkan nilainya ke aplikasi BLYNK dengan IOT untuk lebih jelasnya berikut adalah koding dan komponennya.


 
a. Komponen




b. Program ESP32 

#define BLYNK_TEMPLATE_ID "TMPL6ou3EQ9xx"
#define BLYNK_TEMPLATE_NAME "monitor timbangan bayi"
#define BLYNK_AUTH_TOKEN "vcclo04QhO5qyH0qzUQLVt3Wm7WL5xxx"

#define BLYNK_PRINT Serial    
#include <Wire.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include "HX711.h"

// HX711.DOUT    - pin #23
// HX711.PD_SCK    - pin #19

#define trigPin 25
#define echoPin 26
#define trigPin2 12
#define echoPin2 13

HX711 scale(23, 19);  
     
BlynkTimer timer;

char ssid[] = "hotspothpku";
char pass[] = "123456789";

long duration, distance;
long duration2, distance2;
float tera = 0;
int berat;
float fix;
int x;
int jarak;
int sp = 30;
float kg;
float weight; 
float calibration_factor = 211000; // for me this vlaue works just perfect 211000  
int tinggi;
float BMI;
int statusnya;

void sendSensor()
{
 Blynk.virtualWrite(V0, weight);
 Blynk.virtualWrite(V1, tinggi);
 Blynk.virtualWrite(V2, statusnya);
 delay(1000);
}

void setup() {

  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, sendSensor);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  
   lcd.setCursor (0,0);
   lcd.print ("LOADING... ");
   delay(5000);
   lcd.clear();
   
  // Set up serial monitor
  Serial.println("HX711 calibration sketch");
  Serial.println("Remove all weight from scale");
  Serial.println("After readings begin, place known weight on scale");
  Serial.println("Press + or a to increase calibration factor");
  Serial.println("Press - or z to decrease calibration factor");
  scale.set_scale();
  scale.tare(); //Reset the scale to 0
  long zero_factor = scale.read_average(); //Get a baseline reading
  Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  Serial.println(zero_factor);

}

void loop() 
{

  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 = (duration/2) / 29.1;

  digitalWrite(trigPin2, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;
  
  tinggi = 55 - distance - distance2; 
  BMI = weight / (tinggi * tinggi);
  
  measureweight();
  
   lcd.setCursor(0,0);
   lcd.print("W/H:");
   lcd.print(weight);
   lcd.print("/");
   lcd.print(tinggi);
   lcd.print("   ");

   lcd.setCursor(11,1);
   lcd.print(BMI); 
   
 if(BMI < 17){
   statusnya = 1;
   lcd.setCursor(0,1);
   lcd.print(" KURUS    ");  
  }

 if((BMI > 17)&&(BMI < 23)){
   statusnya = 2;
   lcd.setCursor(0,1);
   lcd.print(" NORMAL  ");  
  }  

 if((BMI > 23)&&(BMI < 30)){
  statusnya = 3;
   lcd.setCursor(0,1);
   lcd.print(" GEMUK   ");  
  }  

 if(BMI > 30){
   statusnya = 4;
   lcd.setCursor(0,1);
   lcd.print(" OBES   ");  
  }   
   
  Blynk.run();
  timer.run();
   
}


void measureweight(){
 scale.set_scale(calibration_factor); //Adjust to this calibration factor
  Serial.print("Reading: ");
  weight = scale.get_units(5); 
    if(weight<0)
  {
    weight=0.00;
    }
  //Serial.print(scale.get_units(), 2);
 // Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
  Serial.print("Kilogram:");
  Serial.print( weight); 
  Serial.print(" Kg");
  Serial.print(" calibration_factor: ");
  Serial.print(calibration_factor);
  Serial.println();
  // Delay before repeating measurement
  delay(100);
}




c. Program NODEMCU ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6KNlz0xxx"
#define BLYNK_TEMPLATE_NAME "timbangan bayi"
#define BLYNK_AUTH_TOKEN "hdIky8QH-niNXKXhgB0xznG9PklZ4xxx"

#define BLYNK_PRINT Serial    

#include <Wire.h>                           
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include "HX711.h"

// HX711.DOUT    - pin #D4 gpio 14
// HX711.PD_SCK    - pin #D3 gpion 12

#define trigPin D7
#define echoPin D8
//#define trigPin2 16
//#define echoPin2 2

HX711 scale(14, 12);  

  
BlynkTimer timer;

char ssid[] = "hotspothpku";
char pass[] = "123456789";

long duration, distance;
long duration2, distance2;
float tera = 0;
int berat;
float fix;
int x;
int jarak;
int sp = 30;
float kg;
float weight; 
float calibration_factor = 211000; // for me this vlaue works just perfect 211000  
int tinggi;
float BMI;
int statusnya;

void sendSensor()
{
 Blynk.virtualWrite(V0, weight);
 Blynk.virtualWrite(V1, tinggi);
 Blynk.virtualWrite(V2, statusnya);
 delay(1000);
}


void setup() {

  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, sendSensor);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  //pinMode(trigPin2, OUTPUT);
  //pinMode(echoPin2, INPUT);
  
   lcd.setCursor (0,0);
   lcd.print ("LOADING... ");
   delay(5000);
   lcd.clear();
  
  // Set up serial monitor
  Serial.println("HX711 calibration sketch");
  Serial.println("Remove all weight from scale");
  Serial.println("After readings begin, place known weight on scale");
  Serial.println("Press + or a to increase calibration factor");
  Serial.println("Press - or z to decrease calibration factor");
  scale.set_scale();
  scale.tare(); //Reset the scale to 0
  long zero_factor = scale.read_average(); //Get a baseline reading
  Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  Serial.println(zero_factor);

}


void loop() 
{

  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 = (duration/2) / 29.1;

/*
  digitalWrite(trigPin2, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;
*/
  
  tinggi = 55 - distance; 
  BMI = weight / (tinggi * tinggi);
  
  measureweight();
  
   lcd.setCursor(0,0);
   lcd.print("W/H:");
   lcd.print(weight);
   lcd.print("/");   
   lcd.print(tinggi);
   lcd.print("   ");

/*
   lcd.setCursor(0,1);
   lcd.print("T:");
   lcd.print(distance);
   lcd.print(" / ");
   lcd.print(distance2);
   lcd.print("   ");
*/
   
   lcd.setCursor(11,1);
   lcd.print(BMI); 


 if(BMI < 17){
   statusnya = 1;
   lcd.setCursor(0,1);
   lcd.print(" KURUS    ");  
  }

 if((BMI > 17)&&(BMI < 23)){
   statusnya = 2;
   lcd.setCursor(0,1);
   lcd.print(" NORMAL  ");  
  }  

 if((BMI > 23)&&(BMI < 30)){
  statusnya = 3;
   lcd.setCursor(0,1);
   lcd.print(" GEMUK   ");  
  }  

 if(BMI > 30){
   statusnya = 4;
   lcd.setCursor(0,1);
   lcd.print(" OBES   ");  
  }   

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


void measureweight(){
 scale.set_scale(calibration_factor); //Adjust to this calibration factor
  Serial.print("Reading: ");
  weight = scale.get_units(5); 
    if(weight<0)
  {
    weight=0.00;
    }
  //Serial.print(scale.get_units(), 2);
 // Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
  Serial.print("Kilogram:");
  Serial.print( weight); 
  Serial.print(" Kg");
  Serial.print(" calibration_factor: ");
  Serial.print(calibration_factor);
  Serial.println();
  // Delay before repeating measurement
  delay(100);
}




d. VIDEO HASILNYA





Timer Lomba Tamiya 3 Jalur / Line

Timer Lomba Tamiya 3 Jalur / Line


      Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk timer lomba tamiya dengan spek yaitu 3 jalur mobil mini 4 wd dan juga alat ini menggunakan penampil dmd p10 dan sensor optocoupler. untuk lebih jelasnya berikut adalah komponen dan 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 WAKTU_TAMPIL_JAM      10    //detik
#define WAKTU_TAMPIL_KALENDAR 5     //detik

#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];
char lineBuff2[20];

int lineA;
int lineB;
int lineC;
int mulai;
int seconds;
int cs;
long start_time = 0;
int lapa,lapb,lapc;

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


void setup(void)
{
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
  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);
lineB = digitalRead(3);
lineC = digitalRead(4);

if((lineA == 0)&&(lineB == 1)&&(lineC == 1)&&(mulai == 1)){
lapa++;
delay(100);
}

if((lineA == 1)&&(lineB == 0)&&(lineC == 1)&&(mulai == 1)){
lapb++;
delay(100);
}

if((lineA == 1)&&(lineB == 1)&&(lineC == 0)&&(mulai == 1)){
lapc++;
delay(100);
}

if((lineA == 0)&&(lineB == 0)&&(lineC == 1)&&(mulai == 1)){
lapa++;
lapb++;
delay(100);
}

if((lineA == 0)&&(lineB == 1)&&(lineC == 0)&&(mulai == 1)){
lapa++;
lapc++;
delay(100);
}

if((lineA == 1)&&(lineB == 0)&&(lineC == 0)&&(mulai == 1)){
lapb++;
lapc++;
delay(100);
}

if((lineA == 0)&&(lineB == 0)&&(lineC == 0)&&(mulai == 1)){
lapa++;
lapb++;
lapc++;
delay(100);
}

//=============================================
if(lapa > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasila();  
}

if(lapb > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasilb();  
}

if(lapc > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasilc();  
}

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

if((lineA == 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( 37,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, "%d/%d/%d ", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
//===========================================================================

}


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

sprintf(lineBuff2, " A", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasila();  
}


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

sprintf(lineBuff2, " B", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasilb();  
}


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

sprintf(lineBuff2, " C", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasilc();  
}




c. VIDEO HASILNYA