This may be a dumb question, but I basically know nothing about coding arduino.
Basically, my project is that I need to make a weight sensor that activates a motor once a certain weight (lets say 400grams) and above has been reached. I already know how to code the motor bit, but I require assistance coding the weight as all tutorials I have found do not include the weight being a variable. I am using an hx711 and a 1kg load cell on an arduino uno. Thank you
you may seen calibration function or it own sketch. built it in and call when some pin is activated, this calibration value you can hold in memory until power down or store in EEPROM and recall after start if no calibration pin activated.
#include <Arduino.h>
#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;
HX711 scale;
void setup() {
Serial.begin(57600);
Serial.println("HX711 Demo");
Serial.println("Initializing the scale");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
Serial.println("Before setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided
// by the SCALE parameter (not set yet)
scale.set_scale(-459.542);
//scale.set_scale(-471.497); // this value is obtained by calibrating the scale with known weights; see the README for details
scale.tare(); // reset the scale to 0
Serial.println("After setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided
// by the SCALE parameter set with set_scale
Serial.println("Readings:");
}
void loop() {
Serial.print("one reading:\t");
Serial.print(scale.get_units(), 1);
Serial.print("\t| average:\t");
Serial.println(scale.get_units(10), 5);
delay(5000);
}
please describe what you want the program to do.
For example:
When the sensor get_value returns 50 the motor on pin 4 should switch on.
When the sensor get_value returns 60 the motor on pin 4 should switch off.
The sensor should be readed each 5 seconds.
The result of sensor get_value should be printed to serial monitor.
Yes, I do want my weight to be persistent between power cycles so I don't need to recalibrate it after a power cycle. Is there an EEPROM built into the arduino or would I need to get it separately?