Translate

Arduino Visual Basic 6.0 (VB 6) Control dan Monitor Suhu DHT22 Interface + Database Ms. Access

Arduino Visual Basic 6.0 (VB 6) Control dan Monitor Suhu DHT22 Interface + Database Ms. Access
 

          Pada kesempatan kali ini saya akan menjelaskan mengenai bagimana cara membuat sebuah alat yang dapat memonitor suhu udara dan kendali 2 buah LED yang mana tiap LED tersebut mewakili motor DC dan Heater. untuk lebih jelasnya berikut adalah koding dan komponennya.
 
 
a. Komponen ver 1


b. Program Arduino ver 1

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

int msg[1];
int datain;
int motor1 = 6;
int heater1 = 7;
int suhu;

#define DHTPIN 8     
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  dht.begin();
  pinMode(motor1,OUTPUT);
  pinMode(heater1,OUTPUT);
  digitalWrite(motor1,LOW);
  digitalWrite(heater1,LOW);
}

void loop() {

int t = dht.readTemperature();

if (Serial.available() > 0)
{

datain = Serial.parseInt();
lcd.setCursor(0,0);
lcd.print(datain);

if(datain > 10){
suhu = datain;
}

//Serial.println(datain);
if(datain == 1){
  digitalWrite(motor1,LOW);
  }

if(datain == 2){
  digitalWrite(motor1,HIGH);
  }

if(datain == 3){
  digitalWrite(heater1,LOW);
  }

if(datain == 4){
  digitalWrite(heater1,HIGH);
}
}

if(t > suhu){
  digitalWrite(motor1,HIGH);
  digitalWrite(heater1,HIGH);
}

  Serial.println(t);
  delay(1000);
}


c. Program Arduino ver 2

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

int msg[1];
int datain;
int motor1 = 4;
int motor2 = 5;
int heater1 = 6;
int heater2 = 7;
int suhu;
int speed1 = 10;
int speed2 = 9;

#define DHTPIN 8     
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  dht.begin();
  pinMode(motor1,OUTPUT);
  pinMode(motor2,OUTPUT);
  pinMode(heater1,OUTPUT);
  pinMode(heater2,OUTPUT);
  pinMode(speed1,OUTPUT);
  pinMode(speed2,OUTPUT);
  digitalWrite(motor1,LOW);
  digitalWrite(motor2,LOW);
  digitalWrite(heater1,LOW);
  digitalWrite(heater2,LOW);
}

void loop() {

int t = dht.readTemperature();

if (Serial.available() > 0)
{

datain = Serial.parseInt();
lcd.setCursor(0,0);
lcd.print(datain);

if(datain > 10){
suhu = datain;
}

//Serial.println(datain);
if(datain == 1){
   analogWrite(speed1,200);
   digitalWrite(motor1,HIGH);
   digitalWrite(motor2,LOW);
  }

if(datain == 2){
   digitalWrite(motor1,LOW);
   digitalWrite(motor2,LOW);
  }

if(datain == 3){
   analogWrite(speed2,200);
   digitalWrite(heater1,HIGH);
   digitalWrite(heater2,LOW);
  }

if(datain == 4){
   digitalWrite(heater1,LOW);
   digitalWrite(heater2,LOW);
}
}

if(t > suhu){
   digitalWrite(heater1,LOW);
   digitalWrite(heater2,LOW);
   digitalWrite(motor1,LOW);
   digitalWrite(motor2,LOW);
}

  Serial.println(t);
  delay(1000);
}


d. Interface Visual Basic 6

1. Module1.bas

Public Conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public SQl As String
Public i As Byte

Public Sub dbConnect()
Set Conn = New ADODB.Connection
Conn.ConnectionString = strConn
Conn.Open
End Sub

Public Function strConn() As String
Set Conn = New ADODB.Connection
Set Rs = New ADODB.Recordset
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\ADMIN B106\Desktop\interface\Database1.mdb;Persist Security Info=False"
End Function


2. TA.frm

Option Explicit
Dim arrdata()
Dim TotalBaca As Integer
Dim BMI As Single
Dim Keterangan As String
Const MAKSBACA = 10

Dim Conn1 As ADODB.Connection
Dim Cmd1 As ADODB.Command
Dim Param1 As ADODB.Parameter
Dim Rs1 As ADODB.Recordset

Private Sub CBHEATER_Click()
MSComm2.Output = "2" + Chr(13)  'mengirimkan b ke serial
Shape2.FillColor = vbBlack
End Sub

Private Sub cbinsert_Click()
Dim SQl As String
    
   MSComm2.Output = tbtemp.Text + Chr(13)
   
   Call dbConnect
    
    SQl = "INSERT INTO Table1 VALUES('" & tbtagno.Text & "','" & tbdescription.Text & "','" & tbarea.Text & "','" & tbtemp.Text & "','" & tbspeed.Text & "','" & tbtimer.Text & "')"
    
    Dim Rs As Recordset
    Set Rs = New ADODB.Recordset
    Rs.Open SQl, Conn, adOpenDynamic
    'tbtagno.Text = ""
    'tbdescription.Text = ""
    'tbarea.Text = ""
    'tbtemp.Text = ""
    'tbspeed.Text = ""
    'tbtimer.Text = ""
    
    
End Sub

Private Sub CBOFF_Click()
MSComm2.Output = "4" + Chr(13)  'mengirimkan d ke serial
Shape2.FillColor = vbBlack
End Sub

Private Sub CBSTART_Click()
MSComm2.Output = "1" + Chr(13)  'mengirimkan a ke serial
Shape2.FillColor = vbGreen
End Sub

Private Sub CBSTOP_Click()
MSComm2.Output = "3" + Chr(13)  'mengirimkan c ke serial
Shape1.FillColor = vbGreen
End Sub

Private Sub cmdConnect_Click()
Dim port As Integer
On Error GoTo errcode

If MSComm2.PortOpen = False Then
    MSComm2.CommPort = Combo1.ListIndex + 1
    MSComm2.RThreshold = 1
    MSComm2.InputLen = 0
    MSComm2.Settings = Combo2.List(Combo2.ListIndex) & ",N,8,1"
    MSComm2.PortOpen = True
cmdConnect.Enabled = False
cmdDisconnect.Enabled = True
Timerbaca.Enabled = True
End If
 
Exit Sub

errcode:
    MsgBox "Port Salah !", vbOKOnly, "Peringatan"
    Combo1.SetFocus

End Sub

Private Sub cmdDisconnect_Click()
If MSComm1.PortOpen = True Then
    MSComm1.PortOpen = False
End If
cmdConnect.Enabled = True
cmdDisconnect.Enabled = False

End Sub

Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Form_Load()
Dim i As Byte
For i = 1 To 16
Combo1.AddItem (i)
Next i
With Combo2
        .AddItem "2400"
        .AddItem "4800"
        .AddItem "9600"
        .AddItem "19200"
        .AddItem "38400"
        .AddItem "56600"
        
End With
Timer2.Enabled = False
cmdConnect.Enabled = True
cmdDisconnect.Enabled = False
End Sub

Private Sub Timer1_Timer()
Adodc1.Refresh
End Sub

Private Sub Timer2_Timer()
MSComm2_OnComm
End Sub

Private Sub Timerbaca_Timer()
Dim strInput As String
Dim strPotong As String
Dim singleInput As Single
Dim u As Integer
Dim suhu As Integer
Dim batassuhu As Integer

    strInput = MSComm2.Input
        strPotong = strInput
        Text1.Text = Text1.Text + strPotong + vbCrLf
        singleInput = Val(strPotong)
        Text2.Text = singleInput
        If TotalBaca >= MAKSBACA Then
            Timerbaca.Enabled = False
            If MSComm2.PortOpen = True Then MSComm2.PortOpen = False
            Call cmdDisconnect_Click
        End If
        
        suhu = CInt(Text2.Text)
        batassuhu = CInt(tbtemp.Text)
        
        If suhu >= batassuhu Then
        Shape1.FillColor = vbRed
        Shape2.FillColor = vbRed
        End If
               
End Sub


e. VIDEO HASILNYA


Weather Station (Wind Speed Anemometer + Arah Mata Angin + Suhu Udara) Arduino

Weather Station (Wind Speed Anemometer + Arah Mata Angin + Suhu Udara) Arduino 

           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa mengukur kecepatan angin, arah mata angin dan suhu udara. alat ini menggunakan Arduino Sensor DHT22 dan sensor wind speed + arah mata angin. tampilan outputnya ditampilkan ke LCD 16x2 yang berada di box panel. untuk lebih jelasnya berikut adalah koding dan komponenya.
 
 
a. Komponen

 

b. Program Arduino IDE

#include <Wire.h>  // i2C Conection Library
#include "DHT.h"
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define DHTTYPE DHT22
#define DHTPIN 8
DHT dht(DHTPIN, DHTTYPE);

// anemometer parameters
volatile byte rpmcount; // count signals
volatile unsigned long last_micros;
unsigned long timeold;
unsigned long timemeasure = 2.00; // seconds
int timetoSleep = 1;               // minutes
unsigned long sleepTime = 15;      // minutes
unsigned long timeNow;
int countThing = 0;
int GPIO_pulse = 2; // Arduino = D2
float rpm, rps;     // frequencies
float radius = 0.1; // meters - measure of the lenght of each the anemometer wing
float velocity_kmh; // km/h
float velocity_ms;  //m/s
float omega = 0;    // rad/s
float calibration_value = 2.0;
float t;

SoftwareSerial dataserial(7, 6); // D7,D6
String data, arah_angin, s_angin;
int a, b;

void setup() {

  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  dht.begin();
  dataserial.begin(9600);
 
  pinMode(GPIO_pulse, INPUT_PULLUP);
  digitalWrite(GPIO_pulse, LOW);

  detachInterrupt(digitalPinToInterrupt(GPIO_pulse));                         // force to initiate Interrupt on zero
  attachInterrupt(digitalPinToInterrupt(GPIO_pulse), rpm_anemometer, RISING); //Initialize the intterrupt pin
  rpmcount = 0;
  rpm = 0;
  timeold = 0;
  timeNow = 0;
 
}

void loop()
{
  t = dht.readTemperature();
   
  //Measure RPM
  if ((millis() - timeold) >= timemeasure * 1000)
  {
    //countThing++;
    detachInterrupt(digitalPinToInterrupt(GPIO_pulse)); // Disable interrupt when calculating
    rps = float(rpmcount) / float(timemeasure);         // rotations per second
    rpm = 60 * rps;                                     // rotations per minute
    omega = 2 * PI * rps;                               // rad/s
    velocity_ms = omega * radius * calibration_value;   // m/s
    velocity_kmh = velocity_ms * 3.6;                   // km/h
        
    timeold = millis();
    rpmcount = 0;
    attachInterrupt(digitalPinToInterrupt(GPIO_pulse), rpm_anemometer, RISING); // enable interrupt
  }

  lcd.setCursor(0, 0);
  lcd.print("S/T:");
  lcd.print(velocity_ms,1);
  lcd.print("/");
  lcd.print(t,1);
  lcd.print("   ");

Serial.print("*");
Serial.print(velocity_ms*100);
Serial.print(",");
Serial.print(t*100);
Serial.print(",");
Serial.print(s_angin);
Serial.println("#");

bacaarahangin();
}

void rpm_anemometer()
{
  if (long(micros() - last_micros) >= 5000)
  { // time to debounce measures
    rpmcount++;
    last_micros = micros();
  }
}

void bacaarahangin(){

 if (dataserial.available()) // Jika ada data yang diterima dari sensor
  {
    data = dataserial.readString(); // data yang diterima dari sensor berawalan tanda * dan diakhiri tanda #, contoh *1#
    a = data.indexOf("*"); // a adalah index tanda *
    b = data.indexOf("#"); // b adalah index tanda #
    s_angin = data.substring(a + 1, b); // membuang tanda * dan # sehingga di dapat nilai dari arah angin
    if (s_angin.equals("1")) { // jika nilai dari sensor 1 maka arah angin utara
      arah_angin = "utara     ";
    }
    if (s_angin.equals("2")) {
      arah_angin = "timur laut";
    }
    if (s_angin.equals("3")) {
      arah_angin = "timur     ";
    }
    if (s_angin.equals("4")) {
      arah_angin = "tenggara  ";
    }
    if (s_angin.equals("5")) {
      arah_angin = "selatan   ";
    }
    if (s_angin.equals("6")) {
      arah_angin = "barat daya";
    }
    if (s_angin.equals("7")) {
      arah_angin = "barat     ";
    }
    if (s_angin.equals("8")) {
      arah_angin = "barat laut";
    }
    lcd.setCursor(0, 1); // menampilkan pada lcd kolom 0, baris 0
    lcd.print(arah_angin);
  }
}


c. Program ESP8266

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

int temp;
int x = 5;
int y;

int value1;
int value2;
int value3;

float speednya;
float t;
int arah;

int datain1;
int datain2;
int datain3;

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

String apiKey = "7687JHGJHF6576GJ";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";

const char *ssid =  "hotspothpku";     // replace with your wifi ssid and wpa2 key
const char *pass =  "123456789";
const char* server = "api.thingspeak.com";

WiFiClient client;

void setup()
{
 
  dataIn="";
  Serial.begin(9600);
  delay(10);

  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

      while (WiFi.status() != WL_CONNECTED)
     {
            delay(500);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");

}

void loop()
{

while(Serial.available()>0) {
//   dataIn="";
    char inChar = (char)Serial.read();
    dataIn += inChar;
    if (inChar == '\n') {
    parsing = true;
  }
}

if(parsing){
    parsingData();
       
  if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
                      {
                           
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(speednya);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + speednya + "&field2=" + t + "&field3=" + arah + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
                                       
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
                                          
                             Serial.println(". Send to Thingspeak.");
                        }
                       
          client.stop();

          //Serial.println("Waiting...");

  delay(10000);
 
 }
}

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();

 speednya = datain1 / 100.0;
 t = datain2 / 100.0;
 arah = datain3 / 1;

 
}


d. VIDEO HASILNYA


KENDALI PANAS DINGIN PELTIER CONTROL PID

KENDALI PANAS DINGIN PELTIER CONTROL PID
 

         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan panas dan dingin suhu peltier dengan menggunakan PID control. jadi ada 2 buah peltier yang difungsikan untuk panas dan satunya untuk dingin. untuk lebih jelasnya berikut adalah komponen dan kodingnya.
 
 
a. Komponen
 

 
 
b. Program Arduino IDE
 
#include <Wire.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <DS3231.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define ONE_WIRE_BUS 7  

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DS3231  rtc(SDA, SCL);

float temppanas;
float tempdingin;

int inpanas1 = 5;
int inpanas2 = 4;
int indingin1 = 3;
int indingin2 = 2;
int pwmpanas = 10;
int pwmdingin = 9;

int btset = A0;
int btup = A1;
int btdown = A2;
int btok = A3;
int buzzer = 11;

int btsetx;
int btupx;
int btdownx;
int btokx;
Time  t;
float kp = 2.15;
float ki = 2.67;
float kd = 2.15;

float p,i,d,suhu,pid;
float error,errorx,sumerr;
float sp = 0;

void setup()
{

rtc.begin();
rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAmy
rtc.setTime(0, 0, 0);     // Set the time to 12:00:00 (24hr format)
rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014

  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();  
  pinMode(buzzer,OUTPUT);
  pinMode(btset,INPUT_PULLUP);
  pinMode(btup,INPUT_PULLUP);
  pinMode(btdown,INPUT_PULLUP);
  pinMode(btok,INPUT_PULLUP);
 
  pinMode(inpanas1,OUTPUT);
  pinMode(inpanas2,OUTPUT);
  pinMode(indingin1,OUTPUT);
  pinMode(indingin2,OUTPUT);
  pinMode(pwmpanas,OUTPUT);
  pinMode(pwmdingin,OUTPUT);

  settingsp();
}

void loop()
{
btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

 lcd.setCursor(0,0);
 lcd.print("TEKAN START ");

if(btsetx == 0){
 lcd.clear();
 delay(2000);  
 settingsp();
}

if(btokx == 0){
 lcd.clear();
 delay(2000);  
 rtc.setTime(0, 0, 0);
 proses();
}

}

void settingsp(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

 lcd.setCursor(0,0);
 lcd.print("SP= ");
 lcd.print(sp);
 lcd.print("  ");

 if(btupx == 0){
 delay(200);  
 sp++;
 }

 if(btdownx == 0){
 delay(200);  
 sp--;
 }  

 if(btokx == 0){
 delay(200);
 lcd.clear();  
 return;
 }  
 
settingsp();  
}


void proses(){
 t = rtc.getTime();
 
  sensors.requestTemperatures();
  tempdingin = sensors.getTempCByIndex(0);
  temppanas = sensors.getTempCByIndex(1);
 
  error = sp - temppanas;
  p = error * kp;
  sumerr = error + errorx;
  i = ki * sumerr;
  d = kd * (error - errorx);
  pid = p + i + d;

  if(pid < 1){
  pid = 0;
  }
 
  if(pid > 255){
  pid = 255;
  }
 
 lcd.setCursor(0,0);
 lcd.print("T1/2= ");
 lcd.print(tempdingin,1);
 lcd.print("/");
 lcd.print(temppanas,1);
 lcd.print("  ");

 lcd.setCursor(0,1);
 lcd.print("PID= ");
 lcd.print(pid,1);
 lcd.print("  ");

 digitalWrite(inpanas1,HIGH);
 digitalWrite(inpanas2,LOW);
 digitalWrite(indingin1,HIGH);
 digitalWrite(indingin2,LOW);
 analogWrite(pwmpanas,pid);
 analogWrite(pwmdingin,255);

if(t.min == 5){
lcd.clear();
digitalWrite(buzzer,HIGH);
delay(2000);
digitalWrite(buzzer,LOW);
return;  
}
      
delay(200);
proses();  
}


 
c. VIDEO HASILNYA
 

 

Alat Sortir Telur Bagus / Jelek Arduino

Alat Sortir Telur Bagus / Jelek Arduino 


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mensortir telur bagus atau jelek dengan menggunakan arduino, untuk parameternya yaitu menggunakan 2 buat variabel yaitu intensitas cahaya dan berat telur. untuk lebih jelasNya berikut adalah koding dan komponennya.


a. Komponen




b. Program Arduino Uno

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

Servo myservo1;
Servo myservo2;
Servo myservo3;

//myservo1.write(80); tutup
//myservo1.write(150); buka
//myservo2.write(40); buka
//myservo2.write(80); tutup
//myservo1.write(80); lepas
//myservo1.write(180); dorong telur

// HX711.DOUT    - pin #12
// HX711.PD_SCK    - pin #11

HX711 scale(7, 6);       

long duration, distance;
float tera = 0;
int berat;
float fix;
int x;
int dataadc;
int nilai;


void setup() {
  
  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  myservo1.attach(9);
  myservo2.attach(10);
  myservo3.attach(11);
  myservo1.write(80);
  myservo2.write(80);
  myservo3.write(80);

  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() {

 dataadc = analogRead(A0);
 
 berat = scale.get_units(10) * 1;
 //fix = (berat - 0.4233)/0.1586;

 if(berat < 0){
  berat = berat * -1;
 }
 
 lcd.setCursor(0,0);
 lcd.print("Berat= ");
 lcd.print(berat);
 lcd.print("   ");
 lcd.setCursor(0,1);
 lcd.print("ADC= ");
 lcd.print(dataadc);
 lcd.print("   ");
      
 scale.power_down();                  
 delay(200);
 scale.power_up();


if((berat > 5)&&(dataadc > 0)){
 nilai = 1; 
 lcd.clear(); 
 lcd.setCursor(0,0);
 lcd.print("TELUR BAGUS  ");
 myservo1.write(80);
 myservo2.write(80);
 myservo3.write(80); 
 myservo3.write(180); 
 Serial.print(nilai);
 delay(3000);
 lcd.clear();
 myservo1.write(80);
 myservo3.write(80);
 }

if((berat > 5)&&(dataadc == 0)){
 nilai = 2; 
 lcd.clear(); 
 lcd.setCursor(0,0);
 lcd.print("TELUR JELEK  ");
 myservo1.write(150);
 myservo2.write(80);
 myservo3.write(80);
 myservo3.write(180); 
 Serial.print(nilai);
 delay(3000);
 myservo1.write(80);
 myservo3.write(80);
 lcd.clear();
 }

if((berat > 0)&&(berat < 5)&&(dataadc > 0)){
 nilai = 3; 
 lcd.clear(); 
 lcd.setCursor(0,0);
 lcd.print(" TDK STANDAR  ");
 myservo1.write(80);
 myservo2.write(40);
 myservo3.write(80); 
 myservo3.write(180); 
 Serial.print(nilai);
 delay(3000);
 myservo2.write(80);
 myservo3.write(80);
 lcd.clear();
 }

}



c. Program Nodemcu ESP8266

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

char ssid[ ] = "hotspothku";
char pass[ ] = "123456789";//password wifi

#define BOTtoken "6247350997:AAHVV8cNgK7iYneSVNZEBQDB_-wZdtGdULs" //token bot telegram
#define idChat "1148868205" //idbot

WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
int uang;
int nilai;

void setup() {

  client.setInsecure();
  Serial.begin(9600);
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  delay(5000);
 
}

void loop() {
        
  nilai = Serial.parseInt();;

  if (nilai == 1) {
    bot.sendChatAction(idChat, "Sedang mengetik...");
    Serial.print("TELUR BAGUS ");
    Serial.println(nilai);
    delay(2000);
    String nilainya = " KUALITAS TELUR BAGUS ";
    nilainya += nilai;
    nilainya += " 'C\n";
    nilainya += "TERIMA KASIH\n";
    bot.sendMessage(idChat, nilainya, "");
    Serial.print("Mengirim data sensor ke telegram");
  }

  
  if (nilai == 2) {
    bot.sendChatAction(idChat, "Sedang mengetik...");
    Serial.print("TELUR JELEK ");
    Serial.println(nilai);
    delay(2000);
    String nilainya = " KUALITAS TELUR JELEK ";
    nilainya += nilai;
    nilainya += " 'C\n";
    nilainya += "TERIMA KASIH\n";
    bot.sendMessage(idChat, nilainya, "");
    Serial.print("Mengirim data sensor ke telegram");
  }

  if (nilai == 3) {
    bot.sendChatAction(idChat, "Sedang mengetik...");
    Serial.print("TELUR KURANG STANDART ");
    Serial.println(nilai);
    delay(2000);
    String nilainya = " KUALITAS TELUR TIDAK STANDART ";
    nilainya += nilai;
    nilainya += " 'C\n";
    nilainya += "TERIMA KASIH\n";
    bot.sendMessage(idChat, nilainya, "");
    Serial.print("Mengirim data sensor ke telegram");
  }

delay(100);
}



d. VIDEO HASILNYA




Blood Shaker DIY Arduino

Blood Shaker DIY Arduino


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk menggerakkan darah sat berada di kantung darah agar darah tidak menggumpal, alat ini menggunakan kendali motor servo dan mikrokontroller Arduino. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema dan Komponen




b. Program Arduino IDE

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

Servo myservo1;
Servo myservo2;

// HX711.DOUT    - pin #12
// HX711.PD_SCK    - pin #11

HX711 scale(12, 11);       

long duration, distance;
float tera = 0;
int berat;
float fix;
int x;
int ledm = 5;
int ledy = 6;
int ledg = 7;
int a,b;
int tombol1 = A0;
int tombol2 = A1;
int tombol3 = A2;
int tombol4 = A3;
int tombol1x;
int tombol2x;
int tombol3x;
int tombol4x;
int buzzer = 8;
int beratnya;
int tampil;
int solenoid = 2;

void setup() {

  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  myservo1.attach(9);
  myservo2.attach(10);
  myservo1.write(110);
  myservo2.write(110);
  pinMode(ledm,OUTPUT);
  pinMode(ledy,OUTPUT);
  pinMode(ledg,OUTPUT);
  pinMode(buzzer,OUTPUT);
  pinMode(solenoid,OUTPUT);
  digitalWrite(solenoid,LOW); //off
  
  pinMode(tombol1,INPUT_PULLUP);
  pinMode(tombol2,INPUT_PULLUP);
  pinMode(tombol3,INPUT_PULLUP);
  pinMode(tombol4,INPUT_PULLUP);
    
  digitalWrite(ledm,LOW);
  digitalWrite(ledy,LOW);
  digitalWrite(ledg,LOW);
  digitalWrite(buzzer,LOW);
  
  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() {

if(tampil == 1){
 berat = scale.get_units(10) * 1;
 //fix = (berat - 0.4233)/0.1586;

 if(berat < 0){
  berat = berat * -1;
 }
 
 lcd.setCursor (0,0);
 lcd.print ("Berat= ");
 lcd.print (berat);
 lcd.print (" ml  ");
      
 scale.power_down();                  
 delay(200);
 scale.power_up();
}

tombol1x = digitalRead(tombol1);
tombol2x = digitalRead(tombol2);
tombol3x = digitalRead(tombol3);
tombol4x = digitalRead(tombol4);

if(tampil == 0){
lcd.setCursor(0,0);
lcd.print("PILIH BERAT ML");
lcd.setCursor(0,1);
lcd.print("A250 B350 C450");
}

if(tombol4x == 0){
  delay(500);
  lcd.clear();
  tampil++;
  }

if(tampil > 1){
  tampil = 0;
}
  
if(tombol1x == 0){
  digitalWrite(ledm,HIGH);
  digitalWrite(ledy,LOW);
  digitalWrite(ledg,LOW);
  delay(200);
  lcd.clear();
  beratnya = 10;
  shake();
}

if(tombol2x == 0){
  digitalWrite(ledm,LOW);
  digitalWrite(ledy,HIGH);
  digitalWrite(ledg,LOW);
  delay(200);
  lcd.clear();
  beratnya = 350;
  shake();
}

if(tombol3x == 0){
  digitalWrite(ledm,LOW);
  digitalWrite(ledy,LOW);
  digitalWrite(ledg,HIGH);
  delay(200);
  lcd.clear();
  beratnya = 450;
  shake();
}

}

void shake(){ 
digitalWrite(solenoid,HIGH); //on
 
tombol4x = digitalRead(tombol4);

  for(a=90,b=130;a<=130,b>=90;a++,b--){
  myservo1.write(a);
  myservo2.write(b);
  if(a == 110){
  ukurberat();
  }
  delay(50);
  }
       
if(berat >= beratnya){
  myservo1.write(110);
  myservo2.write(110);
  lcd.clear();
  lcd.setCursor (0,0);
  lcd.print ("SELESAI ");
  lcd.print (beratnya);
  lcd.print (" ml  ");
  digitalWrite(buzzer,HIGH);
  delay(3000);
  digitalWrite(buzzer,LOW);
  lcd.clear();
  digitalWrite(ledm,LOW);
  digitalWrite(ledy,LOW);
  digitalWrite(ledg,LOW); 
  digitalWrite(solenoid,LOW); //off  
  return;  
}

if(tombol4x == 0){
lcd.clear();
delay(3000);
myservo1.write(110);
myservo2.write(110);
digitalWrite(ledm,LOW);
digitalWrite(ledy,LOW);
digitalWrite(ledg,LOW);
digitalWrite(solenoid,LOW); //off
return;  
}

  for(a=130,b=90;a>=90,b<=130;a--,b++){
  myservo1.write(a);
  myservo2.write(b);
  if(a == 110){
  ukurberat();
  }
  delay(50);
  }
       
if(berat >= beratnya){
  myservo1.write(110);
  myservo2.write(110);
  lcd.clear();
  lcd.setCursor (0,0);
  lcd.print ("SELESAI ");
  lcd.print (beratnya);
  lcd.print (" ml  ");
  digitalWrite(buzzer,HIGH);
  delay(3000);
  digitalWrite(buzzer,LOW);
  lcd.clear();
  digitalWrite(ledm,LOW);
  digitalWrite(ledy,LOW);
  digitalWrite(ledg,LOW);
  digitalWrite(solenoid,LOW); //off   
  return;  
}

if(tombol4x == 0){
lcd.clear();
delay(3000);
myservo1.write(110);
myservo2.write(110);
digitalWrite(ledm,LOW);
digitalWrite(ledy,LOW);
digitalWrite(ledg,LOW);
digitalWrite(solenoid,LOW); //off
return;  
}

shake();
}

void ukurberat(){
  
 berat = scale.get_units(10) * -1;
 //fix = (berat - 0.4233)/0.1586;

 if(berat < 0){
  berat = berat * -1;
 }
  
 lcd.setCursor (0,0);
 lcd.print ("Berat= ");
 lcd.print (berat);
 lcd.print (" ml  ");

 lcd.setCursor (0,1);
 lcd.print ("SP= ");
 lcd.print (beratnya);
 lcd.print (" ml  ");

 scale.power_down();                  
 delay(10);
 scale.power_up();

}



c. VIDEO HASILNYA