I've setup a DC and Servo motor that fires when motion detected from PIR sensor. Works fine after uploading the sketch. However, If I turn things off, it doesn't work when I turn things back on. I have to re-upload the sketch to get them working again.
Sounds like a power issue. When uploading you have 2A of USB power available. When you disconnect and restart you're working off different power.
A hand drawn schematic and some good clear pics of your wiring would be a real help.
Please, before you post ANY code, use < ctrl T > to format & indent your code in the IDE before pasting it here. Also be sure to use the </> (code formatting) button before you paste here.
Thanks for your response. Apologies in advance for misusing terminology. Anyway, here are a few pictures as well as my code. Good luck making sense of this:
This scheme is using a diode on the DC motor and running through a transistor.
I'm using a 9v battery on the DC motor and powering the Arduino from the computer.
The PIR sensor is on Pin 9,
the Servo is on Pin 7 and
the DC motor on Pin 2
You can't power a motor directly from Arduino. Also the 9V batteries don't have the current. Use a real power supply and things will improve. You got a schematic? (Hand drawn is ok) I don't understand the diode on the motor.
Thanks a lot for taking the time to comment. I was following someone's work via youtube. Here is a drawing. I don't know how to do schematics. Sounds like I need to learn how. A general consensus is saying that a 9V battery is unacceptable. What is a the preferred method?
Formal schematics are a PITA. Draw it out rough on paper, take a pic and post it. Just show all the parts.
Use a USB power supply or "wall wart" that can supply sufficient current indefinitely.