Smart Elevator simulation with arduino uno and Proteus
Smart Elevator simulation with arduino uno and Proteus
// By HomeMade Electronics
// Subscribe to my channel https://www.youtube.com/channel/UC8isJR_71x1wIfw6jB106pg
// for more tutorial videos
// like, share and leave a comment if you need help
#include "HX711.h" // Get this library by clicking on Sketch > Include Library > Library Manager in the Arduino IDE and install it from there
#include <LiquidCrystal.h>
// Define calibration factor obtained using the SparkFun_HX711_Calibration sketch
#define calibration_factor 18029.57
// Define pin numbers
#define IN1 4
#define IN2 5
#define DOUT 3
#define CLK 2
#define Bstart 6
#define Bstop 7
#define Bstopage 1
float weight; // Variable to store weight measurement
HX711 scale;
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
// Function to move motor forward
void forward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
}
// Function to move motor backward
void backward() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
}
// Function to stop motor movement
void stopage() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
}
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
// Initialize LCD
lcd.begin(16, 2);
// Initialize button pins
pinMode(Bstart, INPUT);
pinMode(Bstop, INPUT);
pinMode(Bstopage, INPUT);
// Initialize load cell
scale.begin(DOUT, CLK);
scale.set_scale(calibration_factor); // Set the scale calibration factor
scale.tare(); // Reset the scale to 0 assuming no weight on it at startup
}
void loop() {
// Get weight measurement and display on LCD
weight = scale.get_units() / 2; // Dividing by 2 to convert from grams to kilograms
lcd.setCursor(0, 0);
lcd.print("WEIGHT MEASURED");
lcd.setCursor(6, 1);
lcd.print(weight, 1);
lcd.print(" Kg");
// Check weight and control motor accordingly
if (weight > 60) {
stopage(); // If weight exceeds 60 Kg, stop the motor
} else {
if (digitalRead(Bstart) == LOW) {
forward(); // If start button is pressed, move motor forward
}
}
reverse(); // Check for reverse movement condition
m_stopage(); // Check for stoppage condition
}
// Function to handle reverse movement of the motor
void reverse() {
if (digitalRead(Bstop) == LOW) { // If stop button is pressed
if (weight > 60)
stopage(); // Stop motor if weight exceeds 60 Kg
else
backward(); // Otherwise, move motor backward
}
}
// Function to handle manual stoppage of the motor
void m_stopage() {
if (digitalRead(Bstopage) == LOW) // If stopage button is pressed
stopage(); // Stop the motor
}
Comments
Post a Comment