Hello, my name is Nathan West and I have been working on coding for an engineering project for my high school this year. However, I have one code that works, which has a sensor that activates a red light, shuts off a green light, and it has a working servo motor. My only struggle at this point is when integrating my stepper motor code that works on it own. Bellow I have two files, I am trying to take the Stepper motor code, named Stepper_Motor.ino, and add it to the code, named Full_Arduino_T.E.D._inc.ino. I was hoping someone would be able to help, because whenever I tried to incorporate the stepper motor code, I would get a bunch of errors that I never had trouble with when doing the same thing with the other codes.
Thank You for your time!
Sincerely,
Nathan West
Stepper_Motor.ino (1.88 KB)
Full_Arduino_T.E.D._Inc.ino (2.94 KB)
Any good reason for not simply posting your code?
You will save everyone a lot of time if you read the how to use this forum sticky. We don't like to have to download code that could be posted (in code tags). If you have errors post the complete error message(s) in code tags.
Post the code that you are having trouble with.
And please don't waste your obviously valuable time looking for this topic's twin; I deleted it.
And while you are at it, please go back and edit your first post to correct the "Subject" line.
This is one reason you are getting less than friendly replies.
Hi,
Welcome to the forum.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks..Tom...
engineerriverwood:
Hello, my name is Nathan West and I have been working on coding for an engineering project for my high school this year. However, I have one code that works, which has a sensor that activates a red light, shuts off a green light, and it has a working servo motor. My only struggle at this point is when integrating my stepper motor code that works on it own. Bellow I have two files, I am trying to take the Stepper motor code, named Stepper_Motor.ino, and add it to the code, named Full_Arduino_T.E.D._inc.ino. I was hoping someone would be able to help, because whenever I tried to incorporate the stepper motor code, I would get a bunch of errors that I never had trouble with when doing the same thing with the other codes.
Thank You for your time!
Hi Nathan -- welcome to the forum!
When you tried combining the sketches, what errors did you see? If you can list out the first few error messages you see in the window, and attach a copy of your modified code (ie. the combination), that would be really helpful. That way we could determine what things you might have tried and what changes might be necessary. It is good that you attached the two original (working) examples, as that helps provide a baseline reference for what you're attempting to do.
For example, do you see: error: redefinition of 'void setup()'
? Errors like that would indicate that you haven't merged the two setup()
and two loop()
functions properly.
Assuming you are trying to merge "Stepper_Motor" into "Full_Arduino", it should be very easy to copy the 4 lines of the "Stepper_Motor" setup() function to the start of the "Full_Arduino" setup(). But, merging the "Stepper_Motor" loop() function into the "Full_Arduino" loop() takes much more care because both of your loop() functions perform actions that consume time (ie. call delay()
). So you'll need to find a way to alternate/combine the operations.
To start with, I would comment out your servo code and try to just get the PIR detection working at the same time as the stepper motor.
Other notes:
- "Full_Arduino" has a typo on
delay(" sec");
that should be triggering a warning. It is best to check that error messages are enabled during compile to catch these. See the IDE Settings, ensure it isn't set to None.
- Your "Full_Arduino" PIR detection is only going to happen once every 12 seconds due to the wait statements at the end of your loop. I'm not sure what you're intending to do with your servos, but you'll probably want to only perform the
myservo.write()
when a certain total time has elapsed, for example.
- One of the challenges you will face (and need to solve) is how you can run all of these time-driven operations "at the same time". You may want to think about alternating between these tasks and checking to see if it is "time" to do the next step of a task. One way to approach this is to draw up the sequence of operations you're trying to accomplish on graph paper, with time along the X axis. On the Y axis you can plan out the various operations and when they need to occur.