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