I need to make both mortors move in opposite directions but i keep getting errors help?!?!?
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution for your motor
const int photoresistorPin = A0; // select the input pin for the photoresistor
const int temperatureSensorPin = A1; // select the input pin for the temperature sensor
const int motorPin1 = 8;
const int motorPin2 = 9;
const int motorPin3 = 10;
const int motorPin4 = 11;
const int motorPin5 = 4;
const int motorPin6 = 5;
const int motorPin7 = 6;
const int motorPin8 = 7;
// Threshold values for sunlight detection
const int sunlightThreshold = 750; // value for full sunlight
const int heatThreshold = 500; // value for sun heat
int open = 0; // this creates a marker to keep track of whether the shade is open or closed.
myStepper(stepsPerRevolution, motorPin1, motorPin2, motorPin3 ,motorPin4);
myStepper1(stepsPerRevolution, motorPin5, motorPin6, motorPin7 ,motorPin8);
void setup() {
// put your setup code here, to run once:
myStepper.setSpeed(60); // set the speed of the motor (RPM)
myStepper1.setSpeed(60); // set the speed of the motor (RPM)
pinMode(photoresistorPin, INPUT);
pinMode(temperatureSensorPin, INPUT);
Serial.begin(9600);
}
void loop() {
int photoresistorValue = analogRead(photoresistorPin);
int temperatureValue = analogRead(temperatureSensorPin);
// Check if full sunlight
Serial.print("Photoresistor: ");
Serial.println(photoresistorValue);
Serial.print("Temperature: ");
Serial.println(temperatureValue);
if (photoresistorValue >= sunlightThreshold && temperatureValue <= heatThreshold && open == 0) {
// only do this if shade is currently closed
for (int i = 0; i < (stepsPerRevolution * 5); i++) {
myStepper.step(-1); // turn motor to open shade
myStepper1.step(1); // turn motor in opposite direction to open shade
}
open = 1; // mark that shade is open
delay(1000);
}
else if (photoresistorValue < sunlightThreshold && open == 1) {
// only do this if shade is currently open
for (int i = 0; i < (stepsPerRevolution * 5); i++) {
myStepper.step(1); // turn motor to close shade
myStepper1.step(-1); // turn motor in opposite direction to close shade
}
open = 0; // mark that shade is closed
delay(1000);
}`Use code tags to format code for the forum`
````Use code tags to format code for the forum`
Welcome to the forum.
So copy and paste the errors you get.
You might want to look at this How to get the best out of this forum before you proceed any further.
We only know what you tell us, and without knowing what you have, we don't stand a chance.
Also in embedded programming code is only half the story, we need to see a schematic to know how this is put together. It looks like from the code that you drive the coils direct from the Arduino. If so they can't supply enough current to drive a stepping motor.
You have also not included any libraries in the code you posted. Therefor myStepper is not defined.
when i compile your code, i see that myStepper
and myStepper1
are not defined, there definitions are missing a type.
there's no #include for a stepper motor library to know the type for the library being used such as AccelStepper.
most experienced developers start small and test each new feature of the code rather than write a lot of code and then start test/debugging.
i suggest you start with one of the examples, Multistepper
Hi, @dandry
Welcome to the forum.
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
What model Arduino are you using?
Can you please post links to data/specs of the motors and the drivers?
Thanks.. Tom..
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.