Translate

DETEKSI TELUR BAGUS / JELEK ARDUINO SENSOR LDR & AMPLI HX711 - LOADCELL

DETEKSI TELUR BAGUS / JELEK ARDUINO SENSOR LDR & AMPLI HX711 - LOADCELL
 

       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mendeteksi telur bagus atau jelek dengan menggunakan sensor LDR dan loadcell. jadi jika cahaya bisa tembus ke telur maka telur dikatakan bagus namun jika tidak maka telur dikatakan buruk. untuk lebih jelasnya berikut adalah koding dan komponennya.
 
 
a. 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;
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 #3
// HX711.PD_SCK    - pin #2

HX711 scale(3, 2);       

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 < 850)){
 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 > 850)){
 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 < 850)){
 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. VIDEO HASILNYA


Alat Pendeteksi Golongan Darah ESP32 dan Hasil Bisa diprint serta Interface LCD Nextion

Alat Pendeteksi Golongan Darah ESP32 dan Hasil Bisa diprint serta Interface LCD Nextion


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mendeteksi golongan darah. alat ini sangat bagus karena hasil pengukuran bisa di print melalui printer thermal. dan juga interface atau LCD menggunakan LCD Nextion sehingga memiliki interface yang bagus. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema Alat




b. Program Arduino ESP32

#include <WiFi.h>
#include <WiFiClient.h>
#define RXD2 16 
#define TXD2 17

int dataadc1;
int dataadc2;
int dataadc3;
int zero=0;
int heatTime = 80;
int heatInterval = 255;
char printDensity = 15;
char printBreakTime = 15;
char my_str1[] = "A+";
char my_str2[] = "A-";
char my_str3[] = "B+";
char my_str4[] = "B-";
char my_str5[] = "AB+";
char my_str6[] = "AB-";
char my_str7[] = "O+";
char my_str8[] = "O-";
int datahasil;
int urutan;
int mark;
int tanda = 0;

void setup() {
  Serial2.begin(9600);
  Serial.begin(9600); // to write to our new printer
  initPrinter();
}

void initPrinter()
{
 //Modify the print speed and heat
 Serial.write(27);
 Serial.write(55);
 Serial.write(7); //Default 64 dots = 8*('7'+1)
 Serial.write(heatTime); //Default 80 or 800us
 Serial.write(heatInterval); //Default 2 or 20us
 //Modify the print density and timeout
 Serial.write(18);
 Serial.write(35);
 int printSetting = (printDensity<<4) | printBreakTime;
 Serial.write(printSetting); //Combination of printDensity and printBreakTime
}

void loop() {

  dataadc1 = analogRead(34);
  dataadc2 = analogRead(35);
  dataadc3 = analogRead(32);
  
  if((dataadc1 > 1000)&&(dataadc2 < 1000)&&(dataadc3 > 1000)){
  lcdCMD("hasil.txt=\"A+\"");  
  mark = 1;
  }

  if((dataadc1 > 1000)&&(dataadc2 < 1000)&&(dataadc3 < 1000)){
  lcdCMD("hasil.txt=\"A-\"");  
  mark = 2;
  }

  if((dataadc1 < 1000)&&(dataadc2 > 1000)&&(dataadc3 > 1000)){
  lcdCMD("hasil.txt=\"B+\"");  
  mark = 3;
  }

  if((dataadc1 < 1000)&&(dataadc2 > 1000)&&(dataadc3 < 1000)){
  lcdCMD("hasil.txt=\"B-\"");  
  mark = 4;
  }

  if((dataadc1 > 1000)&&(dataadc2 > 1000)&&(dataadc3 > 1000)){
  lcdCMD("hasil.txt=\"AB+\""); 
  mark = 5;
  }

  if((dataadc1 > 1000)&&(dataadc2 > 1000)&&(dataadc3 < 1000)){
  lcdCMD("hasil.txt=\"AB-\"");  
  mark = 6;
  }

  if((dataadc1 < 1000)&&(dataadc2 < 1000)&&(dataadc3 > 1000)){
  lcdCMD("hasil.txt=\"O+\"");  
  mark = 7;
  }

  if((dataadc1 < 1000)&&(dataadc2 < 1000)&&(dataadc3 < 1000)){
  lcdCMD("hasil.txt=\"O-\"");  
  mark = 8;
  }

  lcdCMD("sensor1.val=" + String(dataadc1));
  lcdCMD("sensor2.val=" + String(dataadc2));
  lcdCMD("sensor3.val=" + String(dataadc3));
  lcdCMD("noid.val=" + String(urutan));
   
    datahasil = Serial2.read();
    if(datahasil == 'A'){
    urutan++;
    }  
    if(datahasil == 'B'){
    urutan--;
    } 
    if((datahasil == 'C')&&(tanda == 0)){
    tanda = 1;  
    printing();
    } 
}

void lcdCMD(String cmd) {
  Serial2.print(cmd);
  Serial2.write(0xff);
  Serial2.write(0xff);
  Serial2.write(0xff);
  tanda = 0;
}

void printing(){
   delay(1000);

  //print
  Serial.write(27);
  Serial.write(45);
  Serial.write(1);
  Serial.print("ID= ");
  Serial.println(urutan);

if(mark == 1){
  Serial.print("GOL= ");
  Serial.println(my_str1);
  mark = 0;
  }

if(mark == 2){
  Serial.print("GOL= ");
  Serial.println(my_str2);
  mark = 0;
  }

if(mark == 3){
  Serial.print("GOL= ");
  Serial.println(my_str3);
  }

if(mark == 4){
  Serial.print("GOL= ");
  Serial.println(my_str4);
  mark = 0;
  }

if(mark == 5){
  Serial.print("GOL= ");
  Serial.println(my_str5);
  mark = 0;
  }  

if(mark == 6){
  Serial.print("GOL= ");
  Serial.println(my_str6);
  mark = 0;
  }      

if(mark == 7){
  Serial.print("GOL= ");
  Serial.println(my_str7);
  mark = 0;
  }      

if(mark == 8){
  Serial.print("GOL= ");
  Serial.println(my_str8);
  mark = 0;
  }                  
  
  Serial.write(10);
  Serial.write(10);  
}



c. Interface LCD NEXTION







d. VIDEO HASILNYA




Monitor Tegangan 220Vac dan Jarak ESP32 IOT Blynk 2.0 Sensor PZEM-004t dan HC-SRF04

Monitor Tegangan 220Vac dan Jarak ESP32 IOT Blynk 2.0 Sensor PZEM-004t dan HC-SRF04


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tegangan 220 Vac dan juga monitoring jarak dengan maksimal jarak yaitu 2 meter. alat ini menggunakan ESP32 + IOT dengan server Blynk 2.0 sehingga bisa dimonitor secara jarak jauh. untuk lebih jelasnya berikut adalah koding dan komponennya.


a. Komponen




b. Program ESP32

#define BLYNK_TEMPLATE_ID "TMPL6wOC--abc"
#define BLYNK_TEMPLATE_NAME "monitor daya"
#define BLYNK_AUTH_TOKEN "VOK0cWiFN5ycHj3SV_snEDXTfTfxxxxx"
#define BLYNK_PRINT Serial  

#include <Wire.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
#include <PZEM004Tv30.h>
#define RXD2 16 
#define TXD2 17

LiquidCrystal_I2C lcd(0x27, 16, 2); 
PZEM004Tv30 pzem_r(&Serial2);

const int trigPin = 5;
const int echoPin = 18;

//define sound speed in cm/uS
#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701

long duration;
float distanceCm;
float distanceInch;

float vr;
float ir;
float freq;
float pf_r;
float energy;
float power;

BlynkTimer timer;

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

void sendSensor()
{
 Blynk.virtualWrite(V0, vr);
 Blynk.virtualWrite(V1, distanceCm);
 delay(1000);
}
 
void setup() {
  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, sendSensor);
}
 
void loop() {
  
  vr = pzem_r.voltage();
  ir = pzem_r.current();

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  
  // Calculate the distance
  distanceCm = duration * SOUND_SPEED/2;  

  lcd.setCursor(0,0);
  lcd.print("V: ");
  lcd.print(vr,1);
  lcd.print("   ");
      
  lcd.setCursor(0,1);
  lcd.print("S: "); 
  lcd.print(distanceCm);
  lcd.print(" cm   ");
  
  Blynk.run();
  timer.run();  
  delay(200);
}
 


c. VIDEO HASILNYA



Membuat Alat Frekuensi & Duty Cycle Generator dan Timer Arduino

Membuat Alat Frekuensi & Duty Cycle Generator dan Timer Arduino


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat menghasilkan frekuensi dan duty cycle yang dapat diatur melalui tombol dan juga timer yang bisa disetting maksimal di 30 menit. untuk frekuensi yaitu berada di range 0 - 100 Hz dan duty cycle 0 - 100 persen. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema




b. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <PWM.h>
#include <EEPROM.h>
#define DS3231_I2C_ADDRESS 0x68

LiquidCrystal_I2C lcd(0x27,16,2);

int relay1 = A0;
int relay2 = A1;
int relay3 = A2;
int buzzer = 8;
int btset = 3;
int btok = 4;
int btup = 5;
int btdown = 6;
int btsetx;
int btokx;
int btupx;
int btdownx;
int32_t frekuensi,frekuensi2;
int dutycycle,dutycycle2;
int waktu;
bool success;
float duty,duty2;

int addr1 = 0;
int addr2 = 1;
int addr3 = 2;
int addr4 = 3;
int addr5 = 4;
int val1;
int val2;
int val3;
int simpan1;
int simpan2;
int simpan3;
int simpan4;
int simpan5;

int outpin1 = 9;
int outpin2 = 10;   

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}

void setup() {
Serial.begin(9600);
lcd.begin();  
lcd.clear();
lcd.noCursor();
InitTimersSafe();
success = SetPinFrequencySafe(outpin1, frekuensi);
success = SetPinFrequencySafe(outpin2, frekuensi);
pinMode(relay1,OUTPUT);
pinMode(relay2,OUTPUT);
pinMode(relay3,OUTPUT);
pinMode(outpin1,OUTPUT);
pinMode(outpin2,OUTPUT);
pinMode(buzzer,OUTPUT);
digitalWrite(relay1,LOW); //OFF
digitalWrite(relay2,LOW); //OFF
digitalWrite(relay3,LOW); //OFF
digitalWrite(buzzer,LOW); //OFF
pinMode(btset,INPUT_PULLUP);
pinMode(btok,INPUT_PULLUP);
pinMode(btup,INPUT_PULLUP);
pinMode(btdown,INPUT_PULLUP);
  
Wire.begin();
// DS3231 seconds, minutes, hours, day, date, month, year
setDS3231time(0,0,0,6,5,10,18);

frekuensi = EEPROM.read(addr1);
dutycycle = EEPROM.read(addr2);
waktu = EEPROM.read(addr3);
frekuensi2 = EEPROM.read(addr4);
dutycycle2 = EEPROM.read(addr5);

digitalWrite(buzzer,HIGH); //ON
delay(3000);
digitalWrite(buzzer,LOW); //OFF
}

void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}

void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

void loop() {

btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
  
lcd.setCursor(0,0);
lcd.print("EMS GENERATOR");
lcd.setCursor(0,1);
lcd.print("SETTING ");

if(btsetx == 0){
lcd.clear();
delay(200);
setfreq1();
setduty1();
setfreq2();
setduty2();
settimer();
setDS3231time(0,0,0,6,5,10,18); 
mulai();  
}

}

void setfreq1(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
   
lcd.setCursor(0,0);
lcd.print("SET 1 FREQ HZ");
lcd.setCursor(0,1);
lcd.print(frekuensi);  
lcd.print("   ");

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

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

if(btokx == 0){
  lcd.clear();
  delay(2000);
  EEPROM.write(addr1, frekuensi);
  return;
}

if(frekuensi > 100){
frekuensi = 0;  
}

if(frekuensi < 0){
frekuensi = 100;  
}

setfreq1();
}

void setfreq2(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
   
lcd.setCursor(0,0);
lcd.print("SET 2 FREQ HZ");
lcd.setCursor(0,1);
lcd.print(frekuensi2);  

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

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

if(btokx == 0){
  lcd.clear();
  delay(2000);
  EEPROM.write(addr4, frekuensi2);
  return;
}

if(frekuensi2 > 100){
frekuensi2 = 0;  
}

if(frekuensi2 < 0){
frekuensi2 = 100;  
}

setfreq2();
}

void setduty1(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
   
lcd.setCursor(0,0);
lcd.print("SET 1 DUTY %");
lcd.setCursor(0,1);
lcd.print(dutycycle);  
lcd.print("   ");

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

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

if(btokx == 0){
  lcd.clear();
  delay(2000);
  EEPROM.write(addr2, dutycycle);
  return;
}

if(dutycycle > 100){
dutycycle = 0;  
}

if(dutycycle < 0){
dutycycle = 100;  
}

setduty1();
}

void setduty2(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
   
lcd.setCursor(0,0);
lcd.print("SET 2 DUTY %");
lcd.setCursor(0,1);
lcd.print(dutycycle2);  
lcd.print("   ");

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

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

if(btokx == 0){
  lcd.clear();
  delay(2000);
  EEPROM.write(addr5, dutycycle2);
  return;
}

if(dutycycle2 > 100){
dutycycle2 = 0;  
}

if(dutycycle2 < 0){
dutycycle2 = 100;  
}

setduty2();
}

void settimer(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
   
lcd.setCursor(0,0);
lcd.print("SET WAKTU");
lcd.setCursor(0,1);
lcd.print(waktu);  
lcd.print(" MENIT ");

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

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

if(btokx == 0){
  lcd.clear();
  delay(2000);
  EEPROM.write(addr3, waktu);
  return;
}

if(waktu > 59){
waktu = 0;  
}

if(waktu < 0){
waktu = 59;  
}

settimer();
}

void mulai(){

  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);

  lcd.setCursor(0,0);
  // send it to the serial monitor
  lcd.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  lcd.print(":");
  if (minute<10)
  {
    lcd.print("0");
  }
  lcd.print(minute, DEC);
  lcd.print(":");
  if (second<10)
  {
    lcd.print("0");
  }
  lcd.print(second, DEC);
 
//duty = pwmon / 255;
duty = (dutycycle / 100.0) * 255.0;
duty2 = (dutycycle2 / 100.0) * 255.0;

digitalWrite(relay1,HIGH); //ON 
digitalWrite(relay2,HIGH); //ON 
digitalWrite(relay3,HIGH); //ON 

btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
   
lcd.setCursor(0,1); 
lcd.print("F/D:");
lcd.print(frekuensi); 
lcd.print("/");
lcd.print(dutycycle); 
lcd.print("/");
lcd.print(frekuensi2); 
lcd.print("/");
lcd.print(dutycycle2); 

  InitTimersSafe();
  success = SetPinFrequencySafe(outpin1, frekuensi);
  success = SetPinFrequencySafe(outpin2, frekuensi2);
 
 pwmWrite(outpin1, duty);
 pwmWrite(outpin2, duty2);
 delay(1000);

if(minute == waktu){
  digitalWrite(relay1,LOW); //OFF
  digitalWrite(relay2,LOW); //OFF 
  digitalWrite(relay3,LOW); //OFF  
  digitalWrite(buzzer,HIGH); //ON
  delay(3000);
  digitalWrite(buzzer,LOW); //OFF
  pwmWrite(outpin1, 0);
  pwmWrite(outpin2, 0);
  lcd.clear();
  delay(2000);
  return;
}
    
mulai();  
}



c. VIDEO HASILNYA