i need help with simple coding

I need help programming my arduino uno so that i am able to turn a motor on for a certain amount of time (3 sec) after which it must turn off automatically.It must also turn the motor in alternate directions every time. This must all be done through a smartphone. ps. I'm a first time arduino user. i think this link will help http://www.instructables.com/id/Bluetooth-Based-Home-Automation-1/?ALLSTEPS

If you want help with a program you have written or a downloaded program that you are trying to use post the program and tell us what actually happens and what you want it to do.

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

...R

I need help programming my arduino uno so that i am able to turn a motor on for a certain amount of time (3 sec) after which it must turn off automatically.It must also turn the motor in alternate directions every time. This must all be done through a smartphone. can someone please write this code for me. ps. I'm a first time arduino user. if you can modify the code from this webite it would be better as i wouldnt have to change the hardware http://www.instructables.com/id/Bluetooth-Based-Home-Automation-1/?ALLSTEPS

How much?

Pete

Threads merged.

What happens when you use your smartphone to poik the sketch during that three seconds while the motor is turning? I can think of three things you might want to do:

1 - ignore it 2 - immediately reverse direction 2a - for three seconds 2b - for the same amount of time that the motor had already been moving in the current direction 3 - queue up the signal and reverse direction when the current move is done

As to how to program it - I would tend to use cooperating classes as always.

class SignalAcceptor {
public:
  virtual void acceptSignal() = 0;
};

class MotorControl : public SignalAcceptor {
public:
  MotorControl(onPin, directionPin);
  void setup(){} // setup pins, initialize
  void loop(){} // keep track of time, work the motor
  void acceptSignal() {} // if we are idle, start the motor move sequence
};

class CommandReader {
public:
  CommandReader(SoftwareSerial &stream, SignalAcceptor &target);
  void setup(){} // initialise buffers, etc
  void loop(){} // if there is input available, read and interpret it
};

MotorControl has the job of running the motor back and forth and keeping track of time and direction. Occasionally, its 'acceptSignal' method may be called by something and it has to decide what to do about that.

CommandReader has the job of reading an input stream as bytes come in and working out from those incoming bytes when to send a 'acceptSignal' to it's referenced signal acceptor. This might be as simple as 'whenever I see an asterisk'; or 'whenever I see any data at all, but only once per line'; or 'read a line and parse it into fields, then if the third field is a number greater than 10 and it's wednesday, signal the motor'.

To wire it up:

SoftwareSerial bluetoothModule(tx, rx);
MotorControl motor(onPin, reversePin);
CommandReader reader(bluetoothModule, motor);

void setup() {
  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);
  bluetoothModule.begin(9600);
  motor.setup(); // this object sets up the pins
  reader.setup(); // this object sets up the pins
}

void loop() {
  motor.loop();
  reader.loop();
}

The nice thing about doing it this way is that you can leave aside the reader and just hook up a button for testing the motor, and likewise leave aside the motor and just hook up an LED for testing the reader.

See the link in my sig for more on how I do these kinds of projects.