ESP8266IOT Projects

DIY IoT Weighing Scale using HX711 Load Cell, Nodemcu ESP8266, & Arduino

IoT Weighing Scale Project Description:

 

IoT Weighing Scale– In this project, you will learn how to make an IoT Weighing Scale using Hx711 24 bit analog to digital converter, a 5Kg Load Cell or Strain Gauge, Nodemcu ESP8266 WIFI Module, Arduino, and a cell phone application designed in Blynk.  Later in this tutorial, I will explain why I am using Arduino with the Nodemcu ESP8266 Wifi Module. With this DIY low-cost IoT Weighing Scale, you can measure and monitor weights from anywhere around the world. For demonstration purposes, I am using some known weights 50 grams, 100 grams, 200 grams, and 1 Kg.

This is my 3rd tutorial on the HX711 and load cell which explains how to use the Wifi technology to make an IoT based Weighing Scale. While in my previous two tutorials, I explained the basics, like for example what is HX711, Soldering, Interfacing, and the Load Cell or Strain Gauge calibration. I highly recommend you should read my previous two tutorials and then you can resume from here because this tutorial is entirely based on my previous two tutorials. I will modify the previous program and I will also explain how to establish the Serial communication between the Arduino and Nodemcu ESP8266 Wifi module and then how to display the weight information on the 16×2 LCD widget.

Previous tutorials:

Without any further delay, let’s get started!!!

Amazon Links:

HX711 Load cell / Strain Gauge:

Nodemcu ESP8266 WiFi Module:

LM7805 Voltage Regulator:

470uf capacitor:

DC Female Power Jack:

Female Headers:

Male Headers:

12v Adaptor:

Arduino Uno

Arduino Nano

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!


Making of the Weighing Scale Machine:

IoT Weighing Scale

I salvaged this thing from an old scale. I am going to replace this old load cell with the new one which you can see in the picture below. In this project, I am using a 5kg load cell or strain gauge.

IoT Weighing Scale

While fixing the load cell make sure the arrowhead is in the downward direction. As you can see the load cell is fixed and the arrowhead points in the downward direction.

IoT Weighing Scale

Finally, I fixed a steel plate. Which is explained in the video given at the end of this article.

IoT Weighing Scale

IoT Weighing Scale

These are some known weights, which I will be using during the demonstration. 50 grams, 100 grams, 200 grams, and 1Kg. Now let’s have a look at the complete connection diagram of the IoT weighing Scale.


IoT Weighing Scale Circuit Diagram:

IoT Weighing Scale

The DC female power jack positive leg is connected with the input leg of the LM7805 voltage regulator. The ground leg of the DC female power jack is connected with the middle leg of the 7805 voltage regulator. The output leg of the voltage regulator is connected with the Vin pin of the Nodemcu ESP8266 Wifi module and the ground of the 5 volts regulated power supply is connected with the Gnd pin of the Nodemcu module. This 5 volts regulated power supply is used to power up the Nodemcu module. A 330-ohm resistor is connected in series with the 2.5 volts LED. This is a current limiting resistor. The purpose of this LED is to let you know that the power supply is turned ON. Two 470uf capacitors are connected at the input and output sides of the LM7805 voltage regulator.

The Tx and Rx pins of the Nodemcu module are connected with the Arduino’s pin number 7 and pin number 8. Make sure you connect the ground of the Nodemcu module with the ground of the Arduino.

A Load cell or Strain gauge has 4 wires, the red wire of the load cell is connected with the E+, Black wire is connected with the E-, the White wire is connected with the A-, and green wire of the load cell or strain gauge is connected with the A+ of the HX711 board.

The HX711 is a 24 bit analog to digital converter “ADC”. Which has an amplifier, that gives a maximum gain of 128 as per the Datasheet. The Gnd of the HX711 is connected with the Arduino’s ground, the DT pin of the HX711 is connected with the Arduino’s pin number 3, the SCK pin is connected with the Arduino’s pin number 2, and the VCC pin of the HX711 breakout board is connected with the Arduino’s 5 volts.

IoT Weighing Scale

This is the PCB board designed for the Nodemcu Module, the PCB board designing and soldering is already explained in my previous tutorial. Watch the video tutorial.

The final Nodemcu ESP8266 power supply board can be seen in the picture below.

IoT Weighing Scale

 

About the PCBWay:

iot weighing scale
sponsor

The PCB board used in this project is sponsored by the PCBway Company, which is one of the most experienced PCB and PCB assembly manufacturer. They create high-quality PCBs at reasonable prices. The Gerber files of the PCB board used in this project can be downloaded from the PCBway

Download Gerber Files:

High quality & Only 24 Hours Build time:

Interfacing HX711 & Nodemcu with Arduino:

IoT Weighing Scale

All the components are interfaced as per the connections diagram already explained. The 4 wires coming from the load cell or strain gauge are connected with the HX711 board which is also connected with the Arduino. The Arduino is also connected with the Nodemcu ESP8266 Wifi Module. The Arduino communicates serially with the Nodemcu Module.

You can make this IoT based Weighing Scale using only the Nodemcu Module, but the reason I have added the Arduino board is if in case you want to add an LCD or a keypad, etc. To reduce the size you can also use Arduino Nano. Now let’s make the Blynk application.



Note: this old version of the Blynk app is no more functional. For the blynk mobile App setup and Blynk.cloud dashboard setup ready my article on the New Blynk V2.0. In this article I have explained how to migrate your projects from Blynk 1.0 to the new Blynk V2.0. You can also watch the video.

IoT Weighing Scale Blynk Application:

For the step by step Blynk application explanation watch video available at the end of this article or you can follow the following steps.

  • First of all, open the blynk application.
  • Click on the new project.
  • Enter the project name as “iot weighing scale” or any other name which you like.
  • Click on the choose device and select Nodemcu.
  • In the connection, type select Wifi and then click on the create button. An authentication token will be sent on your email id. Copy the authentication token and paste it in the programming as explained in the video.
  • Click on the screen and search for the LCD widget and add it.
  • Click on the LCD, select the input type as the advanced.
  • Click on the Pin and select virtual pin V2.

That’s it the application is ready.

IoT Weighing Scale Programming:

In this project two programs are used, one program is written for the Arduino, while the other program is written for the Nodemcu ESP8266 Wifi Module. All the libraries used in this project can be downloaded by clicking on the link given below.

Download Libraries:


IoT Weighing Scale Arduino Programming:

#include <SoftwareSerial.h>
#include "HX711.h"
#include <stdlib.h>
SoftwareSerial nodemcu(7, 8); // nodemcu module connected here
#define DOUT  3
#define CLK  2
HX711 scale(DOUT, CLK);

int rbutton = 6; // this button will be used to reset the scale to 0. 
String myString; 
String cmessage; // complete message
char buff[10];
float weight; 
float calibration_factor = 419640; // for me this vlaue works just perfect 419640 
void setup() {
  Serial.begin(9600);
  nodemcu.begin(9600);
  pinMode(rbutton, INPUT_PULLUP); 
  scale.set_scale();
  scale.tare(); //Reset the scale to 0
  long zero_factor = scale.read_average(); //Get a baseline reading

}
void loop() {
  scale.set_scale(calibration_factor); //Adjust to this calibration factor

  weight = scale.get_units(5); //5
myString = dtostrf(weight, 3, 2, buff);
cmessage = cmessage + "Weight" + ":" + myString + "Kg"+","; 
 nodemcu.println(cmessage);
Serial.println(cmessage); 
cmessage = "";

  Serial.println();

  if ( digitalRead(rbutton) == LOW)
  {
     scale.set_scale();
  scale.tare(); //Reset the scale to 0
  }

  
}
Arduino program explanation:

This is basically the same program I used in my previous two tutorials, this time I made a few changes. I added the SoftwareSerial and stdlib libraries, created a Serial Port for the Nodemcu module, defined some variables while the calibration factor value remains the same.

In the void setup function, I activated the serial communication, while the other instructions remain the same.

In the void loop function, I added the dtostrf() function to convert the Float value into the String value. Then I created a complete message and finally using the println function the complete message is sent to the Nodemcu module and also to the serial monitor for the debugging purposes. Now let’s have a look at the Nodemcu programming.


IoT Weighing Scale Nodemcu ESP8266 Programming:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>

WidgetLCD lcd(V2);

char auth[] = "jQkA7IneoZOlBxyPKUjQ0n71d7pwHVCh";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ZONG MBB-E8231-6E63";
char pass[] = "electroniclinic";

SimpleTimer timer;

String myString; // complete message from arduino, which consistors of snesors data
char rdata; // received charactors
String weight;

int firstVal;  
// This function sends Arduino's up time every second to Virtual Pin (1).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() / 1000);
  
}



void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);

    timer.setInterval(1000L,sensorvalue1); 

}

void loop()
{

  
  
   if (Serial.available() == 0 ) 
   {
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
   }
   
  if (Serial.available() > 0 ) 
  {
    rdata = Serial.read(); 
    myString = myString+ rdata; 
   // Serial.print(rdata);
    if( rdata == '\n')
    {
Serial.println(myString);
// new code
weight = getValue(myString, ',', 0);

  myString = "";
// end new code
    }
  }

}

void sensorvalue1()
{

      lcd.clear();
    lcd.print(0,0,weight);
    lcd.print(0,1,"ElectroniClinic");

}


String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}


Nodemcu ESP8266 program explanation:

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

#include <SoftwareSerial.h>

#include <SimpleTimer.h>

These are the same libraries I have been using in all of my Nodemcu based projects.

WidgetLCD lcd(V2);

Data to the LCD widget is sent through the virtual pin V2.

char auth[] = “jQkA7IneoZOlBxyPKUjQ0n71d7pwHVCh”;

This is the authentication token, which was sent via email, I simply copied and paste it over here.

char ssid[] = “ZONG MBB-E8231-6E63”;

char pass[] = “electroniclinic”;

These are the wifi credentials, the router name which is the ssid and the password.

SimpleTimer timer;

String myString; // complete message from arduino, which consistors of snesors data

char rdata; // received charactors

String weight;

int firstVal;

I defined some variables.

void myTimerEvent()

{

  // You can send any value at any time.

  // Please don’t send more that 10 values per second.

  Blynk.virtualWrite(V1, millis() / 1000);

}

The mytimerevent function is already explained in my previous iot based projects. The void setup function remains the same.

If the Nodemcu module has not received any data from the Arduino, then simply keep executing the blynk.run() and timer.run() functions.

If the Nodemcu module has received data from the Arduino then read the serial port, add the received character with the myString variable.

if( rdata == ‘\n’)

This condition makes sure that the entire message is received. Then using the getvalue function the string is split. And then finally, the weight information is sent to the blynk application.

Getvalue is a user-defined function that is used to split the string message using any character as the delimiter, in my case I have used a comma as the delimiter. So, that’s all about the programming.

For the practical demonstration watch video given below. Don’t forget to Subscribe to my website and YouTube channel “electronic clinic”. Support my website and YouTube channel by sharing and liking the video. If you have any questions let me know in a comment.



Watch Video Tutorial:

 

 

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button