Fairly new, need help creating simple code -_-

Hello, I'm fairly new to coding and I need help with creating an simple piece of code that should be easy. I'm creating a on/off switch that after a delay will turn on a dc motor. If anyone can help I am open to suggestions.

I have suggested to the Moderator to move this to the Programming section - which seems the appropriate place to ask a programming question.

If you just want someone to write a program for you please ask in the Gigs and Collaborations section of the Forum and be prepared to pay.

If you want to learn to program yourself the examples that come with the Arduino IDE are a good place to start. There are also many online tutorials. Also see the Useful Links Thread.

If you have some code that does not work as you want then please post it and tell us in detail what it actually does and what you want it to do that is different. It will make it much easier to focus on the parts you need help with rather than wasting time on things that you can do.

Also have a look at the demo Several Things at a Timewhich illustrates the use of millis() to manage timing.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

...R

Start by writing a program that turns the motor on as soon as the switch is turned on and stops the motor when the switch is turned off. How much current does the motor take ? I ask because there is a limit as to how much current an Arduino pin can sfely supply

Welcome to the group.

“I'm creating a on/off switch that after a delay will turn on a dc motor”

Please reword this so it more accurately reflects exactly what you want.

Why is it that so many people who have no idea how to program anything keep turning up and telling us that the program they can't write is really simple and must be easy?

Folks, if was that easy you would be able to do it! And the first step is to produce an accurate detailed description of what the program is intended to do. In this case it would definitely include things like what sort of switch, how long a delay and what type and size of motor.

Steve

Steve

:wink:

AdamBaum:
Hello, I'm fairly new to coding and I need help with creating an simple piece of code that should be easy. I'm creating a on/off switch that after a delay will turn on a dc motor. If anyone can help I am open to suggestions.

Well, you could start by stating with more precision what you are trying to do. For instance,

const byte pin = D4;
void setup()  {
  pinMode(D4, OUTPUT);
  digitalWrite(D4, LOW);
  delay(1000);
  digitalWrite(D4, HIGH);
}
void loop() {}

This sketch, when the arduino is powered up, waits 1 second and drives pin4 HIGH. That's it. That's all it does. Raise pin 4 high after one second when the arduino is turned on.

Did you want more? Did you want to turn your thingamajig on and off as well, without power-cycling the arduino? Well - you should have said.

What should happen when the switch is turned on?
What should happen when the switch is turned off?
What should happen when someone flicks the switch on and off, just to dick around?
When the switch is on, should the output stay on? Should it go off after a period of time? Should - heck, I dunno - should it leave the output on for a time equal to half the time that the switch had been sitting in the off position?

Half the battle is describing what you want the sketch to do. You may very will find that if you do that, youll be able to write the sketch yourself.