#include <Stepper.h>
#include "HX711.h"
// Define variables
int buttonPin = 2; // Digital pin where the button is connected.
int ledPin = 13; // Digital pin where the LED is connected.
int potPin = A0; // Analog pin where the potentiometer is connected.
int motorSteps = 200; // Change this to fit the number of steps per revolution for your motor
int motorSpeed = 60; // Speed of the stepper motor
bool buttonState = false;
Stepper myStepper(motorSteps, 8, 9, 10, 11); // Stepper motor configuration
HX711 scale;
void setup() {
pinMode(ledPin, OUTPUT); // LED pin as an output.
pinMode(buttonPin, INPUT); // Button pin as an input.
myStepper.setSpeed(motorSpeed); // Set the speed of the stepper motor
scale.begin(A1, A0); // Initialize the scale
Serial.begin(115200);
}
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// Check if the button is pressed
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn LED on.
} else {
digitalWrite(ledPin, LOW); // Turn LED off.
}
// Read potentiometer value
int potValue = analogRead(potPin);
Serial.print("Potentiometer Value: ");
Serial.println(potValue);
// Read load cell value
Serial.print("Load Cell Value: ");
Serial.println(scale.get_units(), 1);
// Move stepper motor based on potentiometer value
int motorStepsToMove = map(potValue, 0, 1023, 0, motorSteps);
myStepper.step(motorStepsToMove);
// Delay for stability
delay(100);
}