This is my first post and I am a beginner in this field , so it will be immensely helpful if someone can tell how to achieve this task. My task is to create a smart attendance system.
I have two separate program running on different Arduino UNO.
The first is 16x2 display , hx711 and is calibrated to measure the weight of the placed on the load cell.
<
#include <HX711_ADC.h> // need to install
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // need to install
HX711_ADC LoadCell(6, 7); // parameters: dt pin 6, sck pin 7;
LiquidCrystal_I2C lcd(0x27, 16,2); // 0x27 is the i2c address might different;you can check with Scanner
void setup()
{
LoadCell.begin(); // start connection to HX711
LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor(1000.0); // calibration factor for load cell => dependent on your individual setup
lcd.init();
lcd.backlight();
}
void loop() {
LoadCell.update(); // retrieves data from the load cell
float i = LoadCell.getData(); // get output value
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Weight[g]:"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to second row
lcd.print(i); // print out the retrieved value to the second row
} />
The other uno is supposed to show true or false every 5 min whether the weight is placed on load cell or not. At the end of 60 min it will display the maximum amount of true or false obtained. If max amount are true then the student is present and if its false then student is absent.
<
#include "HX711.h"
#define DOUT 3
#define CLK 2
HX711 scale;
unsigned long previousMillis = 0;
const long interval = 5 * 60 * 1000; // 5 minutes in milliseconds
unsigned long startTime = 0;
int trueCount = 0;
int falseCount = 0;
bool report = false;
void setup() {
Serial.begin(9600);
scale.begin(DOUT, CLK);
}
bool is_weight_present() {
// Read the weight from the load cell
float weight = scale.get_units();
// Adjust this threshold according to your setup
if (weight > 0.1) {
return true;
} else {
return false;
}
}
void loop() {
unsigned long currentMillis = millis();
// Measure weight every 5 minutes
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
bool weight_present = is_weight_present();
if (weight_present) {
trueCount++;
} else {
falseCount++;
}
}
// After 60 minutes, display the maximum count of true or false
if (currentMillis - startTime >= 60 * 60 * 1000 && !report) {
report = true;
Serial.print("Maximum true count obtained in 60 minutes: ");
Serial.println(trueCount);
Serial.print("Maximum false count obtained in 60 minutes: ");
Serial.println(falseCount);
}
delay(100); // Adjust delay according to your needs
} />
Also I had a doubt that can't these two functions be both run on a single arduino.
4 posts - 4 participants