I'm working on a project to read pressure sensor data and use the applied levels to rotate the stepper motor. Each force on the sensor would rotate the motor a certain degree.
*For now the main goal is for the Arduino to read a stream of pressure readings over time, and rotate accordingly (i.e if the reading is 400 going to 100, rotate clockwise).
*Currently using the stepper motor library for the Arduino - the code successfully reads one value from the pressure sensor to make a rotation.
*I have tried variations of this where I placed the integer fsrReading in the loop() but it failed to even make one rotation. Likewise, I tried adjusting the baud rate / Serial.begin(). In this attempt, I ran a for loop to see if I could pretty much manually but it ran one clockwise rotation and then one counterclockwise rotation before it cut out.
#include <AccelStepper.h>
int fsrPin = 0;
int fsrReading;
int setReading;
#define FULLSTEP 4
AccelStepper myStepper(FULLSTEP, 8, 10, 9, 11);
void setup(void) {
Serial.begin(5000);
myStepper.setSpeed(1000.0);
}
int readSensor() {
setReading = analogRead(fsrPin);
return setReading;
}
void loop() {
for(int i=0; i < 3; i++)
{
if (readSensor() > 100 && readSensor() < 200) {
myStepper.moveTo(2038);
Serial.println(setReading);
}else if(readSensor() > 300) {
myStepper.moveTo(-2038);
Serial.println(setReading);
}
myStepper.run();
}**
Any help or advice to change this to continuously read multiple levels would be greatly appreciated. Thank you.