Monitoring Berat dan Tinggi Badan Hasilnya bisa diprint
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur berat dan tinggi badan secara langsung dengan Arduino dan sensor jarak HC-SRF04 dengan sensor berat menggunakan loadcell. untuk lebih jelasnya berikut adalah koding dan skemanya.
1. Skema
2. 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 #6
// HX711.PD_SCK - pin #7
#define trigPin 4
#define echoPin 5
HX711 scale(6, 7);
int btprint = 12;
int btprintx;
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
}
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() {
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.print("S: ");
Serial.print(distance);
Serial.print(" w: ");
Serial.println(berat);
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();
btprintx = digitalRead(btprint);
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);
}
}
3. VIDEO HASILNYA
No comments:
Post a Comment