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