Académique Documents
Professionnel Documents
Culture Documents
Introduction:
In this tutorial we will learn how to communicate with the host-machine using serialport.
1. Arduino UNO R3
2. Proto-board
3. Digital Oscilloscope
4. Digital Multimeter
5. Jumpers (connecting wires)
6. Resistor ( 470) or ( 220)
7. DC Motor
8. L293D IC
9. push button
10. 5 Volts D.C power supply
1
pin 09 as positive terminal of motor2
You can connect the circuit as shown in the Figure 1a,1b. We will use 2 x output pins from the Arduino
to control the motion of the DC motors. A switch on or off button is used to control the direction of
the motors.
// Wiring/Arduino code:
// Read data from the serial and turn ON or OFF a light depending on the value
void setup()
{
pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
pinMode(enablePin1, OUTPUT); // pin for enable motor
pinMode(enablePin2, OUTPUT); // pin for enable motor
pinMode(motor1P1, OUTPUT); // pin for enable motor
pinMode(motor1P2, OUTPUT); // pin for enable motor
pinMode(motor2P1, OUTPUT); // pin for enable motor
2
pinMode(motor2P2, OUTPUT); // pin for enable motor
pinMode(switchP, INPUT); // switch the motor reverse
// no need to for define pwm or analog input
Serial.begin(9600); // Start serial communication at 9600 bps
void loop() {
if(digitalRead(switchP) == HIGH){
digitalWrite(motor1P1, HIGH);
digitalWrite(motor1P2, LOW);
digitalWrite(motor2P1, LOW);
digitalWrite(motor2P2, HIGH);
}
else{
digitalWrite(motor1P1, LOW);
digitalWrite(motor1P2, HIGH);
digitalWrite(motor2P1, HIGH);
digitalWrite(motor2P2, LOW);
else {
digitalWrite(ledPin, LOW); // Otherwise turn it OFF
digitalWrite(enablePin1, LOW); // turn the Motor off
digitalWrite(enablePin2, LOW); // turn the Motor off
}
delay(10); // Wait 10 milliseconds for next reading
}
Conclusion and results: Press cntrl-R to compile the code. If there is no errors, then press cntrl-U to
upload the compiled program on your C Flash memory. As told earlier, once the program is uploaded
successfully, the board will automatically get a reset and after a few second will start running your code.
Press the push button to check if the motors move in the opposite directions when the signal at pin-2 is
high.
3
References
http://arduino.cc.
http://arduino.cc/en/Main/ArduinoBoardUno.
http://arduino.cc/en/Guide/Introduction.
www.atmel.com/Images/doc8161.pdf.
http://arduino.cc/en/Tutorial/Button
http://arduino.cc/en/Tutorial/Blink
http://arduino.cc/en/uploads/Main/arduino_Uno_Rev3-02-TH.zip.
http://arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf.
http://arduino.cc/en/Main/ArduinoBoardUno.
http://www.aishack.in/2010/07/the-three-motors-youll-ever-use-in-robotics/
http://arduino.cc/en/Tutorial/SoftwareSerialExample