The Start


Hi, What and Why

Plug it in

Rule number 1

Water Sensor

Sound Sensor

Joystick

Tri Colour LED

RTC (Real Time Clock) DS1302

RTC (Real Time Clock) DS3231

Matrix LED step 1

LCD

Stepper Motor

LCD revisited with PCF8574T

Humidity Sensor

Shift Register

RFID tags (RC-522)

7 Segment display

Ultrasonic distance sensor

5V regulator

analogRead and analogWrite

Wiring an Array of Switches

The next step


Other things I have bought

Infra red and Processing

Programming a separate arduino chip

Creating your own PCB

L293D for a DC motor

4 digit 7 segment display

Starting with motors

RF433 Wireless Comms

Sort a character array

More stuff


I2C devices (SDA,SCL)

I2C scanner

SPI devices (MOSI,MISO)

HMC5883L Compass

MMA7361 Accelerometer

Added projects


Message Display System

4WD robot car
4WD robot car II

4WD robot car COMPLETE

MP3 Player

L293D for a DC motor


A L293D motor controller chip and a DC motor. L293D and a DC motor

I got fed up with indecipherable pinout diagrams within datasheets, so have designed my own that I think gives more pertinent information.
There are 3 wires connected to the arduino, 2 wires connected to the motor, and 1 wire connected to a battery.

A L293D motor controller chip - pinout diagram.
Green - connected to arduino.
Blue - connect to motor
Pink - connect to a battery +ve, eg 12 volt.
L293D and a DC motor

To use this pinout:
The left hand side deals with the first motor, the right hand side deals with a second motor.
Yes, you can run it with only one motor connected.

Arduino Connections
M1 PWM - connect this to a PWM pin on the arduino. They're labelled on the Uno, pin 3 is an example. Output any integer between 0 and 255, where 0 will be off, 128 is half speed and 255 is max speed.

M1 direction 0/1 and M1 direction 1/0 - Connect these two to two digital arduino pins. Output one pin as HIGH and the other pin as LOW, and the motor will spin in one direction.
Reverse the outputs to LOW and HIGH, and the motor will spin in the other direction.


The code below does not use a separate power supply (ie a battery), it uses instead the 5v power from the arduino. Note that this would be risky without the L293D controlling it.
You should _never_ connect a motor directly to the arduino, because when you switch a motor off you get an electrical feedback. With a small motor, this will damage your arduino, and with a large motor, you can watch an interesting flame and sparks effect.

Wired up.
L293D Pin : Arduino Pin
1	:	3
2	:	5
3	(DC motor +5V) 
4	(GND)
5	(GND)
6	(DC motor GND)
7	:	4
8	(+5V)

9	:	6
10	:	8
11	(DC motor #2 +5V)
12	(GND)
13	(GND)
14	(DC motor #2 GND)
15	:	7
16	(+5V)
joystick

This is the code that I used.

/************************
Exercise the motor using
the L293 chip
************************/

#define ENABLE 3
#define DIRB 4
#define DIRA 5


int i;
 
void setup() {
  //---set pin direction
  pinMode(ENABLE,OUTPUT);
  pinMode(DIRA,OUTPUT);
  pinMode(DIRB,OUTPUT);

 
Serial.begin(9600);

}

void loop() {
  //---back and forth example

Serial.println("One way, then reverse");
  digitalWrite(ENABLE,HIGH); // enable on
  for (i=0;i<5;i++) {
    digitalWrite(DIRA,HIGH); //one way
    digitalWrite(DIRB,LOW);
    delay(500);
    digitalWrite(DIRA,LOW);  //reverse
    digitalWrite(DIRB,HIGH);
    delay(500);
  }
  digitalWrite(ENABLE,LOW); // disable
  delay(4000);

Serial.println("fast Slow example");
  //---fast/slow stop example
  digitalWrite(ENABLE,HIGH); //enable on
  digitalWrite(DIRA,HIGH); //one way
  digitalWrite(DIRB,LOW);
  delay(1000);
  digitalWrite(ENABLE,LOW); //slow stop
  delay(3000);
  digitalWrite(ENABLE,HIGH); //enable on
  digitalWrite(DIRA,HIGH); //one way
  digitalWrite(DIRB,LOW);
  delay(1000);
  digitalWrite(DIRA,LOW); //fast stop
  delay(3000);

//Serial.println("PWM full then slow");
  //---PWM example, full speed then slow
  digitalWrite(ENABLE,HIGH); //enable on
  digitalWrite(DIRA,HIGH); //one way
  digitalWrite(DIRB,LOW);
  delay(2000);
  analogWrite(ENABLE,128); //half speed
  delay(2000);
  digitalWrite(ENABLE,LOW); //all done
  delay(10000);
}
   

All the above is in the public domain. It's included here to show which PIN settings work with which code.