I am a new user of arduino. I need some suggestion or assist to complete my program. I am using arduino mega 2560, stepper motor and analog sensor.
Goal: Run the stepper motor for a particular distance in mm range and then it will stop for a while. Within this stopped time the sensor will take analog data. Then again do the same task in a loop.
#include <Stepper.h>
#define STEPS 100
Stepper stepper(STEPS, 8, 9, 10, 11);
////////////////
// Analog input pins
int sensor1 = 0;
int sensor2 = 1;
int sensor3 = 2;
int sensor4 = 3;
int sensor5 = 4;
int sensor6 = 5;
int value1 = 0;
int value2 = 0;
int value3 = 0;
int value4 = 0;
int value5 = 0;
int value6 = 0;
////////////////
long duration;
float distance;
////////////////
void setup() {
stepper.setSpeed(30); // set the speed of the motor to 30 RPMs
Serial.begin(19200);
}
////////////////
void readSensor() {
value1 = analogRead(sensor1); // read the value from the sensor
value2 = analogRead(sensor2); // read the value from the sensor
value3 = analogRead(sensor3); // read the value from the sensor
value4 = analogRead(sensor4); // read the value from the sensor
value5 = analogRead(sensor5);
value6 = analogRead(sensor6);
//Display sensor digital value
Serial.print(value1); Serial.print(";"); Serial.print(value2); Serial.print(";"); Serial.print(value3); Serial.print(";"); Serial.print(value4); Serial.print(";"); Serial.print(value5); Serial.print(";"); Serial.println(value6);
}
////////////////
void motor() {
for(int i = 0; i < 30; i++)
{
stepper.step(STEPS);
}
}
///////////////
void loop () {
// I am not sure how to execute motor and sensor command in loop
}