Hi,
Weighing Load Cell Sensor 3kgs not showing exact weight it is displaying some ramdom values on arduino ide's serial monitor....
Hardwares we are using:
1)Weighing Load Cell Sensor 3kgs
2)HX711(Analog to digital convertor)
3)Arduino Uno
4)ESP8266 WIFI Module
5)Connecting wires
Program which we are executing is as per below,
#include <WiFiEsp.h>
#include <WiFiEspClient.h>
#include <WiFiEspServer.h>
#include <WiFiEspUdp.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <MySQL_Encrypt_Sha1.h>
#include <MySQL_Packet.h>
WiFiEspClient client; //Use this for ESP8266
MySQL_Connection conn((Client *)&client);
#include "HX711.h" //You must have this library in your arduino library folder
#define DOUT 6
#define CLK 5
HX711 scale(DOUT, CLK);
// Emulate Serial1 on pins 2/3 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2, 3); // RX, TX
#endif
char ssid[] = "MAKARAND SYSTEMS"; // your network SSID (name)
char pass[] = "xyzabc"; // your network password
IPAddress server_addr(148,66,135,229); // IP of the MySQL server here go dadday
char user[] = "srinivas";
char password[] = "xyzabc$";
//Change this calibration factor as per your load cell once it is found you many need to vary it in thousands
float calibration_factor = 96650; //-106600 worked for my 40Kg max scale setup
//=============================================================================================
// SETUP
//=============================================================================================
void setup() {
Serial.begin(115200);
Serial.read();
while (!Serial); // wait for serial port to connect. Needed for Leonardo only
// initialize serial for ESP module
Serial.println("Starting....");
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
//Serial1.println("Connecting to WiFi");
// Begin WiFi section
int status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
while(true);
}
// print out info about the connection:
else {
Serial.println("Connected to network");
IPAddress ip = WiFi.localIP();
Serial.print("My IP address is: ");
Serial.println(ip);
}
Serial.println("Press T to tare");
scale.set_scale(-96650); //Calibration Factor obtained from first sketch
scale.tare(); //Reset the scale to 0
Serial.print("Weight: ");
Serial.print(scale.get_units(),3); //Up to 3 decimal points
Serial.println(" kg"); //Change this to kg and re-adjust the calibration factor if you follow lbs
Serial.println("Connecting...");
if(conn.connect(server_addr,3306,user,password)) {
delay(1000);
// if(Serial.available()>0)
// {
Serial.print("executing inside available");
//char temp = Serial.read();
//if(temp == 't' || temp == 'T'){
char weight[8];
Serial.println("Line 1");
dtostrf(scale.get_units(),5,3,weight);
Serial.println("Line 2");
//char INSERT_SQL1[40];
//char INSERT_SQL[80];
String INSERT_SQL1 = "INSERT INTO test.test VALUES(";
String strbracket =")";
String INSERT_SQL=INSERT_SQL1+weight+strbracket;
Serial.println("Line 3");
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
//extern void recvOneChar();
//extern void showNewData();
char copy[50];
Serial.println("Line 4");
INSERT_SQL.toCharArray(copy, 50);
cur_mem->execute(copy);
Serial.print("output:");
Serial.print(INSERT_SQL);
scale.tare();
}}
//}
//=============================================================================================
// LOOP
//=============================================================================================
void loop() {
}
//=============================================================================================
We are able to insert sensor data into our mysql database,but the data is inaccurate....
Please suggest us to get exact load sensor data.