Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15404

Scale doesn't calibrate correctly

$
0
0

First of all excuse my english, but I have an Arduino Uno and I'm trying to make a scale, It already works besides the fact that it doesn't make a good calibration. It's connected to a loadcell and I already have the weightfactor (1kg=813900.0, and 2kg=153711.0)

could you guys help me find what I'm missing? I put the code below.

thank you for your help in advance!

#include "HX711.h"
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

const int DOUT_PIN = 2; // DAT-pin van de HX711 aangesloten op digitale pin 2
const int SCK_PIN = 3; // CLK-pin van de HX711 aangesloten op digitale pin 3

HX711 scale;
LiquidCrystal_I2C lcd(0x27, 20, 4);

const float scaleFactor1kg = 813900.0; // Vervang dit met je eigen weegschaalfactor voor 1kg
const float scaleFactor2kg = 153711.0;      // Vul de weegschaalfactor voor 2kg in wanneer beschikbaar
const float offset = 0.0;               // Offset, pas aan indien nodig

void setup() {
  Serial.begin(9600);
  scale.begin(DOUT_PIN, SCK_PIN);

  // Initialiseer het lcd-scherm
  lcd.init();
  // Zet de achtergrondverlichting aan
  lcd.backlight();

  lcd.setCursor(0, 0);
  lcd.print("Weegschaal");

  delay(2000);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Voeg gewicht toe");
}

void loop() {
  if (scale.is_ready()) {
    long rawValue = scale.get_value(); // Lees de ruwe sensorwaarde

    // Voer de lineaire vergelijking uit
    float weight = (rawValue / scaleFactor1kg) - offset;

    lcd.setCursor(0, 1);
    lcd.print("Gewicht: ");
    lcd.print(weight, 3); // Toon het gewicht met twee decimalen
    lcd.print(" kg      ");

    // Optioneel: Serial monitor voor het weergeven van het gewicht in de seriële monitor
    Serial.print("Ruwe waarde: ");
    Serial.print(rawValue);
    Serial.print(", Gewicht: ");
    Serial.print(weight, 3); // Toon het gewicht met twee decimalen
    Serial.println(" kg");
  } else {
    lcd.setCursor(0, 1);
    lcd.print("Fout bij het lezen");
  }

  delay(500); // Wacht 0,5 seconden voordat de volgende meting wordt uitgevoerd
}

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 15404

Trending Articles