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
No comments:
Post a Comment