Monitor Timbangan Bayi Digital IOT BLYNK ESP32 / NODEMCU ESP8266
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah timbangan digital dengan menggunakan ESP32 atau Nodemcu ESP8266 dengan fitur yaitu bisa mengukur berat dan tinggi bayi lalu mengirimkan nilainya ke aplikasi BLYNK dengan IOT untuk lebih jelasnya berikut adalah koding dan komponennya.
a. Komponen
b. Program ESP32
#define BLYNK_TEMPLATE_ID "TMPL6ou3EQ9xx"
#define BLYNK_TEMPLATE_NAME "monitor timbangan bayi"
#define BLYNK_AUTH_TOKEN "vcclo04QhO5qyH0qzUQLVt3Wm7WL5xxx"
#define BLYNK_PRINT Serial
#include <Wire.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include "HX711.h"
// HX711.DOUT - pin #23
// HX711.PD_SCK - pin #19
#define trigPin 25
#define echoPin 26
#define trigPin2 12
#define echoPin2 13
HX711 scale(23, 19);
BlynkTimer timer;
char ssid[] = "hotspothpku";
char pass[] = "123456789";
long duration, distance;
long duration2, distance2;
float tera = 0;
int berat;
float fix;
int x;
int jarak;
int sp = 30;
float kg;
float weight;
float calibration_factor = 211000; // for me this vlaue works just perfect 211000
int tinggi;
float BMI;
int statusnya;
void sendSensor()
{
Blynk.virtualWrite(V0, weight);
Blynk.virtualWrite(V1, tinggi);
Blynk.virtualWrite(V2, statusnya);
delay(1000);
}
void setup() {
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, sendSensor);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
lcd.setCursor (0,0);
lcd.print ("LOADING... ");
delay(5000);
lcd.clear();
// Set up serial monitor
Serial.println("HX711 calibration sketch");
Serial.println("Remove all weight from scale");
Serial.println("After readings begin, place known weight on scale");
Serial.println("Press + or a to increase calibration factor");
Serial.println("Press - or z to decrease calibration factor");
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
Serial.println(zero_factor);
}
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;
digitalWrite(trigPin2, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
distance2 = (duration2/2) / 29.1;
tinggi = 55 - distance - distance2;
BMI = weight / (tinggi * tinggi);
measureweight();
lcd.setCursor(0,0);
lcd.print("W/H:");
lcd.print(weight);
lcd.print("/");
lcd.print(tinggi);
lcd.print(" ");
lcd.setCursor(11,1);
lcd.print(BMI);
if(BMI < 17){
statusnya = 1;
lcd.setCursor(0,1);
lcd.print(" KURUS ");
}
if((BMI > 17)&&(BMI < 23)){
statusnya = 2;
lcd.setCursor(0,1);
lcd.print(" NORMAL ");
}
if((BMI > 23)&&(BMI < 30)){
statusnya = 3;
lcd.setCursor(0,1);
lcd.print(" GEMUK ");
}
if(BMI > 30){
statusnya = 4;
lcd.setCursor(0,1);
lcd.print(" OBES ");
}
Blynk.run();
timer.run();
}
void measureweight(){
scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print("Reading: ");
weight = scale.get_units(5);
if(weight<0)
{
weight=0.00;
}
//Serial.print(scale.get_units(), 2);
// Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
Serial.print("Kilogram:");
Serial.print( weight);
Serial.print(" Kg");
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
// Delay before repeating measurement
delay(100);
}
c. Program NODEMCU ESP8266
#define BLYNK_TEMPLATE_ID "TMPL6KNlz0xxx"
#define BLYNK_TEMPLATE_NAME "timbangan bayi"
#define BLYNK_AUTH_TOKEN "hdIky8QH-niNXKXhgB0xznG9PklZ4xxx"
#define BLYNK_PRINT Serial
#include <Wire.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include "HX711.h"
// HX711.DOUT - pin #D4 gpio 14
// HX711.PD_SCK - pin #D3 gpion 12
#define trigPin D7
#define echoPin D8
//#define trigPin2 16
//#define echoPin2 2
HX711 scale(14, 12);
BlynkTimer timer;
char ssid[] = "hotspothpku";
char pass[] = "123456789";
long duration, distance;
long duration2, distance2;
float tera = 0;
int berat;
float fix;
int x;
int jarak;
int sp = 30;
float kg;
float weight;
float calibration_factor = 211000; // for me this vlaue works just perfect 211000
int tinggi;
float BMI;
int statusnya;
void sendSensor()
{
Blynk.virtualWrite(V0, weight);
Blynk.virtualWrite(V1, tinggi);
Blynk.virtualWrite(V2, statusnya);
delay(1000);
}
void setup() {
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, sendSensor);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
//pinMode(trigPin2, OUTPUT);
//pinMode(echoPin2, INPUT);
lcd.setCursor (0,0);
lcd.print ("LOADING... ");
delay(5000);
lcd.clear();
// Set up serial monitor
Serial.println("HX711 calibration sketch");
Serial.println("Remove all weight from scale");
Serial.println("After readings begin, place known weight on scale");
Serial.println("Press + or a to increase calibration factor");
Serial.println("Press - or z to decrease calibration factor");
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
Serial.println(zero_factor);
}
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;
/*
digitalWrite(trigPin2, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
distance2 = (duration2/2) / 29.1;
*/
tinggi = 55 - distance;
BMI = weight / (tinggi * tinggi);
measureweight();
lcd.setCursor(0,0);
lcd.print("W/H:");
lcd.print(weight);
lcd.print("/");
lcd.print(tinggi);
lcd.print(" ");
/*
lcd.setCursor(0,1);
lcd.print("T:");
lcd.print(distance);
lcd.print(" / ");
lcd.print(distance2);
lcd.print(" ");
*/
lcd.setCursor(11,1);
lcd.print(BMI);
if(BMI < 17){
statusnya = 1;
lcd.setCursor(0,1);
lcd.print(" KURUS ");
}
if((BMI > 17)&&(BMI < 23)){
statusnya = 2;
lcd.setCursor(0,1);
lcd.print(" NORMAL ");
}
if((BMI > 23)&&(BMI < 30)){
statusnya = 3;
lcd.setCursor(0,1);
lcd.print(" GEMUK ");
}
if(BMI > 30){
statusnya = 4;
lcd.setCursor(0,1);
lcd.print(" OBES ");
}
Blynk.run();
timer.run();
}
void measureweight(){
scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print("Reading: ");
weight = scale.get_units(5);
if(weight<0)
{
weight=0.00;
}
//Serial.print(scale.get_units(), 2);
// Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
Serial.print("Kilogram:");
Serial.print( weight);
Serial.print(" Kg");
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
// Delay before repeating measurement
delay(100);
}
d. VIDEO HASILNYA
No comments:
Post a Comment