Весы на ардуино при помощи модуля HX711 и тензодатчика.
Состоят весы из двух частей, тензодатчика и модуля на микросхеме HX711. HX711 это 24 битный аналого-цифровой преобразователь специализированный для весов, к которому подключается тензодатчик.
Подключение к arduino:
Модуль можно подключать на два любых выхода arduino, в данном случаи подключено на два аналоговых входа, но работают они как цифровые.
Софт:
Библиотеку для работы с HX711 можно скачать тут.
Калибровка тензодатчика:
Процесс калибровки показан в видео:
https://youtu.be/Q7n_78icCnY
Код из видео для калибровки:
Код для калибровки
/*
Setup your scale and start the sketch WITHOUT a weight on the scale
Once readings are displayed place the weight on the scale
Press +/- or a/z to adjust the calibration_factor until the output readings match the known weight
Arduino pin 6 -> HX711 CLK
Arduino pin 5 -> HX711 DOUT
Arduino pin 5V -> HX711 VCC
Arduino pin GND -> HX711 GND
*/
#include "HX711.h"
HX711 scale(A1, A0); // DT, CLK
float calibration_factor = -3.7; // this calibration factor is adjusted according to my load cell
float units;
float ounces;
void setup() {
Serial.begin(9600);
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() {
scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print("Reading: ");
units = scale.get_units(), 10;
if (units < 0)
{
units = 0.00;
}
ounces = units * 0.035274;
Serial.print(ounces);
Serial.print(" grams");
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
if(Serial.available())
{
char temp = Serial.read();
if(temp == '+' || temp == 'a')
calibration_factor += 1;
else if(temp == '-' || temp == 'z')
calibration_factor -= 1;
}
}
Код для весов
#include "HX711.h"
HX711 scale(A1, A0);
float calibration_factor = -3.7; // калибровка!
float units;
float ounces;
void setup() {
Serial.begin(9600);
scale.set_scale();
scale.tare(); //Сбрасываем на 0
scale.set_scale(calibration_factor); //Применяем калибровку
}
void loop() {
Serial.print("Reading: ");
for(int i = 0;i < 10; i ++) units =+ scale.get_units(), 10; // усредняем показания считав 10 раз
units / 10; // делим на 10
ounces = units * 0.035274; // переводим унции в граммы
Serial.print(ounces); // отправляем в монитор порта
Serial.print(" grams");
Serial.println();
}
В коде изменена единица веса, значение в мониторе порта в граммах, а не в унциях.
Купить:
можно тут.