Need help with easy coding

Also, I got the battery count wrong, they are 6 AA Batteries.

A common 9volt smoke alarm battery can barely power an Arduino.
Only a fresh Alkaline would be able to power an Arduino and a small unloaded motor for a while.

I didn't see any 9volt battery mentioned in that article, or any other power source.
Only at the end it's mentioned that a larger motor should have it's own power source.

USB power would have been the safest for this experiment, because this is not using the onboard 5volt regulator. USB has a 500mA limit before the onboard polyfuse trips (it will self-heal).

Vin (and DC jack) runs through the onboard 5volt regulator.
High input voltage and high load current could overheat the regulator.
Leo..

@GarrisonFord

If you want to get more into programming, I urge you to master all the examples included in your IDE installation.

Pay attention to the 'switch change' and 'blink without delay' examples.

I am sure you will enjoy the programming part of learning Arduino environment.

It can be difficult to slow down and learn things fully, but you will benefit from doing so.

.

GarrisonFord:
Also, I got the battery count wrong, they are 6 AA Batteries.

6AA (7.5volt or 9volt) is perfect for a 6volt motor and the L293 H-bridge.
Connect directly to Vmotor and motor/H-bridge ground.
So no motor current is running over the Arduino board and wiring.
That ~9volt can also be connected to Vin, but the DC jack is safer (reverse voltage protection).
Leo..

See this if you don't know why AA batteries are the ones you should be using ! !

9,648 AA batteries

Hi,
https://www.youtube.com/watch?v=8hwLHdBTQ7s

try 244 9V batteries.

Tom... :slight_smile:

chummer1010:
Direction is quite easy then. I actually made an Instructable about this, but I'll spare you the trouble.

int in1pin = 6; // pins to h-bridge

int in2pin = 7;

int leftButton = 8;
int rightButton = 9; // buttons

void setup() {

pinMode(in1pin, OUTPUT);
  pinMode(in2pin, OUTPUT); // outputs

pinMode(leftButton, INPUT_PULLUP);
  pinMode(rightButton, INPUT_PULLUP); // inputs w internal pullup resistors
 
}

void loop() {

int leftPinState = digitalRead(leftButton);
  int rightPinState = digitalRead(rightButton); // set value names for read data

if (leftPinState == LOW) { // if left button is pressed ...

digitalWrite(in1pin, HIGH); // make motor go one way
    digitalWrite(in2pin, LOW);
   
  }

else if (rightPinState == LOW) { // if right button is pressed ...

digitalWrite(in1pin, LOW);
    digitalWrite(in2pin, HIGH); // make motor go other way

}

else { // if neither button is pressed ...

digitalWrite(in1pin, LOW); // nothing happens
    digitalWrite(in2pin, LOW);
   
  }
 
}




That is a code controlling one DC motor with an H-Bridge that I found in my old sketchbook. While you press one button, the motor will turn one way. If you press the other button, it will turn the other way. Here is also a diagram of my setup. 

![Screen Shot 2016-06-16 at 9.45.27 PM.png|1004x667](upload://4NxHwrNaowUkPqfdzNqi7TCUi0n.png)

So the first method I tried is not giving much results, So I managed to get 2 buttons to try your wiring, Could you tell me how the 2nd motor would go connected? Thanks!

Read this page for information on wiring up an H bridge.

Here's a tip - to power things, connect your batteries to the +Vmotor pin, and connect your enable pins and the +V pin to Arduino's 5V pin. To ground your project, connect the battery pack to arduino's GND pin, and connect the h bridge to a GND pin as well.