Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang berfungsi untuk mengukur berat dan tinggi badan dengan menggunakan Arduino dan juga hasilnya bisa di print menggunakan printer thermal. alat ini sangat cocok sekali jika digunakan untuk sehari-hari atau di klinik yang mmbutuhkan data tinggi dan berat badan. untuk lebih jelasnya berikut adalah daftar komponen dan programnya.
a. Arduino Uno
b. Modul Amplifier Hx711
c. Sensor Jarak HC-SRF04
d. Loadcell 300kg
e. Lcd Oled
f. Printer Thermal
g. Program Arduino IDE
#include <Wire.h>
#include "HX711.h"
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);
#include <SoftwareSerial.h>
SoftwareSerial Thermal(2, 3);
// HX711.DOUT - pin #4
// HX711.PD_SCK - pin #5
#define trigPin 6
#define echoPin 7
HX711 scale(4, 5);
long duration, distance;
float tera = 0;
int berat;
float fix;
int x;
char tmp_string1[8];
char tmp_string2[8];
int zero=0;
int heatTime = 80;
int heatInterval = 255;
char printDensity = 15;
char printBreakTime = 15;
void draw(void) {
itoa(distance, tmp_string1, 8);
itoa(berat, tmp_string2, 8);
u8g.setFont(u8g_font_unifont);
u8g.drawStr(5, 25, "S= ");
u8g.drawStr(30, 25, tmp_string1);
u8g.drawStr(5, 40, "W= ");
u8g.drawStr(30, 40, tmp_string2);
}
void initPrinter()
{
//Modify the print speed and heat
Thermal.write(27);
Thermal.write(55);
Thermal.write(7); //Default 64 dots = 8*('7'+1)
Thermal.write(heatTime); //Default 80 or 800us
Thermal.write(heatInterval); //Default 2 or 20us
//Modify the print density and timeout
Thermal.write(18);
Thermal.write(35);
int printSetting = (printDensity<<4) | printBreakTime;
Thermal.write(printSetting); //Combination of printDensity and printBreakTime
}
int btprint = A0;
int btprintx;
void setup() {
Wire.begin();
Serial.begin(9600);
Thermal.begin(9600); // to write to our new printer
initPrinter();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(btprint, INPUT_PULLUP);
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
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
u8g.setColorIndex(255); // white
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
u8g.setColorIndex(3); // max intensity
}
else if ( u8g.getMode() == U8G_MODE_BW ) {
u8g.setColorIndex(1); // pixel on
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
u8g.setHiColorByRGB(255,255,255);
}
}
void loop() {
btprintx = digitalRead(btprint);
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
Serial.println(distance);
berat = scale.get_units(10) * -1;
fix = ((berat + 1.523) / 0.223) - tera ;
if (fix < 0 ) {
fix = 0;
}
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
scale.power_down();
delay(1000);
scale.power_up();
if (btprintx == 0) {
Serial.println("print ready");
Serial.println("printing....");
delay(1000);
//print
Thermal.write(27);
Thermal.write(45);
Thermal.write(1);
Thermal.print("Tinggi= ");
Thermal.print(distance);
Thermal.println(" cm");
Thermal.print("Berat= ");
Thermal.print(berat);
Thermal.println(" kg");
Thermal.write(10);
Thermal.write(10);
}
}
#include "HX711.h"
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);
#include <SoftwareSerial.h>
SoftwareSerial Thermal(2, 3);
// HX711.DOUT - pin #4
// HX711.PD_SCK - pin #5
#define trigPin 6
#define echoPin 7
HX711 scale(4, 5);
long duration, distance;
float tera = 0;
int berat;
float fix;
int x;
char tmp_string1[8];
char tmp_string2[8];
int zero=0;
int heatTime = 80;
int heatInterval = 255;
char printDensity = 15;
char printBreakTime = 15;
void draw(void) {
itoa(distance, tmp_string1, 8);
itoa(berat, tmp_string2, 8);
u8g.setFont(u8g_font_unifont);
u8g.drawStr(5, 25, "S= ");
u8g.drawStr(30, 25, tmp_string1);
u8g.drawStr(5, 40, "W= ");
u8g.drawStr(30, 40, tmp_string2);
}
void initPrinter()
{
//Modify the print speed and heat
Thermal.write(27);
Thermal.write(55);
Thermal.write(7); //Default 64 dots = 8*('7'+1)
Thermal.write(heatTime); //Default 80 or 800us
Thermal.write(heatInterval); //Default 2 or 20us
//Modify the print density and timeout
Thermal.write(18);
Thermal.write(35);
int printSetting = (printDensity<<4) | printBreakTime;
Thermal.write(printSetting); //Combination of printDensity and printBreakTime
}
int btprint = A0;
int btprintx;
void setup() {
Wire.begin();
Serial.begin(9600);
Thermal.begin(9600); // to write to our new printer
initPrinter();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(btprint, INPUT_PULLUP);
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
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
u8g.setColorIndex(255); // white
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
u8g.setColorIndex(3); // max intensity
}
else if ( u8g.getMode() == U8G_MODE_BW ) {
u8g.setColorIndex(1); // pixel on
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
u8g.setHiColorByRGB(255,255,255);
}
}
void loop() {
btprintx = digitalRead(btprint);
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
Serial.println(distance);
berat = scale.get_units(10) * -1;
fix = ((berat + 1.523) / 0.223) - tera ;
if (fix < 0 ) {
fix = 0;
}
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
scale.power_down();
delay(1000);
scale.power_up();
if (btprintx == 0) {
Serial.println("print ready");
Serial.println("printing....");
delay(1000);
Thermal.write(27);
Thermal.write(45);
Thermal.write(1);
Thermal.print("Tinggi= ");
Thermal.print(distance);
Thermal.println(" cm");
Thermal.print("Berat= ");
Thermal.print(berat);
Thermal.println(" kg");
Thermal.write(10);
Thermal.write(10);
}
}
h. VIDEO HASILNYA
No comments:
Post a Comment