Tag Archives: Tutorial

Arduino driving a motor with Pololu MC33887 / Seed Studio L298 Motor Driver

Introduction


There are different approaches to driving a motor when it comes to driving  a motor with Arduino. If a simple relay is used to drive a motor it can only turn the motor on and off. In case a single transistor like TIP120 (BJT) or IRF510 (MOSFE ) is used, it is possible to control the speed of the rotation. There exist smarter DC motor drivers (so called H-bridge) that can control the direction of rotation and even brake.

Seed Studio L298 Motor Driver

H-bridge_2_pot

Use this sketch and schematics above, compile and upload it to your Arduino. By changing the position of the potentiometer you should be able to change the rotation speed and direction of the motor.
Motor driver manual can be found here.

MC33887 Motor Driver

An example of such a driver is Plolu’s MC33887 Motor Driver which is affordable and versatile. This driver can control a single DC motor with maximum consumption of 2.5A and peaks of 5A. Motor voltage can range from 5-28V which makes it an excellent general purpose motor driver.

Table below describes the marking of the pins on the back side of the MC33887 driver board from Pololu:

Interfacing MC33887 Motor Driver with Arduino

In order to drive a motor with Arduino you will need the components below:

  • A DC motor (5-12V)
  • A Breadboard
  • A Pololu MC338870 driver board
  • An Arduino with a USB cable
  • Some wires
  • A DC Jack connector
  • An adapter matching the voltage of your motor (less than 5-12V)
  • 10-50KΩ Potentiometer

Make the circuit shows below:

Your circuit should look like this:

Use this sketch, compile and upload it to your Arduino. By changing the position of the potentiometer you should be able to change the rotation speed and direction of the motor.

More info:

The circuit suggested above is the simplest form of using an MC338870 to drive a motor. By using D1 and D2, Disable1 and Disable2, one can leave the motor pins in tri-state. FS, Fault Signal, pin can be used to determine malfunction of the driver. FB, Feed Back, can aslo be read with the analog inputs to determine the amount of current being consumed by the motors.

Advertisements

RFID(RDM630) and Arduino

RFID is in use all around us. If you have ever chipped your pet with an ID tag or take a look to the plastic tag in your key ring you use to enter your building, you have used RIFD. “Radio-frequency identification (RFID) is the use of an object (typically referred to as an RFID tag) applied to or incorporated into a product, animal, or person for the purpose of identification and tracking using radio waves.” Read more.

You can read RFID tags Using a RFID reader and an Arduino board. Below you can find the schematic for Connecting a RDM630serial RFID reader to an Arduino board.

RDM630 and Arduino

Pinout for RDM630

Here is the sample code that reads RFID tags from RDM630 serial RFID reader and prints them on the serial  port. You can see the results by clicking “Serial Monitor” in Arduino program. The LED blinks when the reader reads a tag.

Arduino and Processing, Potentiometer

This is an updated version of the Potentiometer post from here.

To build the electronic circuit you need the following parts:

  • a 10kΩ potentiometer(You can use any potentiometer < 100kΩ ),
  • a 1kΩ resistor,
  • and a couple of wires.

A potentiometer is a variable resistor. Between the two outer pins you will always measure the (maximum) value of the resistor, while the variable resistance is measure between the middle and an outer pin. That’s where we connect a wire to measure the voltage. The pull-down resistor avoids a short circuit when the variable resistance is set to zero. The circuit on your breadboard should look something like this:

Working circuit on breadboard

If everything is set up right, you can connect the board to USB port of your computer. The power LED should light up the next step is to export the program, which reads the state of the switch to the board. Open the ap_ReadAnalog.pde file in Arduino set the right serial port (from the menu Tools->Serial Port), compile the program, and then click on the Upload icon () to send the program to the board.To check if everything works fine so far, turn the potentiometer to both extremes: the LED should light up/turn off when the potentiometer reaches (approximately) its middle position. If that works fine, you can then download and unzip pa_Potentiometer.zip and open the file pa_Potentiometer.pde in Processing. Then you will have to set the right serial port as described before.

Now, you can run your Processing program. A new window will open and you should see something like this:

Output of the program

As you turn the potentiometer the vertical bar should move as it indicates the value read from the serial port.

Arduino and Processing,Piezo Element

This is an updated version of the Piezo Element post from here.

To build the electronic circuit you need the following parts:

  • a piezo element,
  • a 1MΩ resistor,
  • and a couple of wires.

The schematic for the circuit looks like this:

Working circuit on breadboard

If everything is set up right, you can connect the board to the USB port of your computer.  The power LED should light up and the next step is to export the programm which reads the state of the switch to the board. Open the ap_ReadPiezoKnock.pde file in Arduino, set the right serial port and baudrate, compile the programm, and then press the reset button on your board and click on the export icon to send the program to the board.

To check if everything works fine so far, see if the control LED lights up when the switch is on ON-position. Now, you can download and unzip pa_PiezoKnock.zip and open the file pa_PiezoKnock.pde in Processing. Then you will have to set the right serial port as described before.

Now, you can run your Processing programm. A new window will open and you should see something like this:

Output of the program

Arduino and Processing, LDR

This is an updated version of the LDR post from here.

To build the electronic circuit you need the following parts:

  • a LDR light sensor,
  • a 1kΩ resistor,
  • and a couple of wires.

A LDR light sensor is a variable resistor. Notice, that in this case we use a pull-up resistor (which means that it is located before the sensor). Still, we measure the voltage ‘between’ this resistor and the light sensor. The circuit on your breadboard should look something like this:

Working circuit on breadboard

If everything is set up right, you can connect the board to USB port of your computer. The power LED should light up the next step is to export the program, which reads the state of the switch to the board. Open the ap_ReadAnalog.pde file in Arduino set the right serial port (from the menu Tools->Serial Port) and baudrate (in the code), compile the program, and then click on the Upload icon () to send the program to the board.To check if everything works fine so far, see if the control LED goes off when you cover the sensor with you hand. If it’s turned off you might have to expose it to more light to pass the threshold value and cause the LED to light up. Now, you can download and unzip pa_LDR.zip and open the file pa_LDR.pde in Processing.Then you will have to set the right serial port as described before.

Run your Processing program. A new window will open and you should see something like this:

Program Output

The maximum size of the pulsating circle depends from the quantity of light that hits the sensor. More light will increase the size of the circle, less light will make it smaller.

Arduino and Processing, Switch

This is an updated version of the Switch post from here.

To build the electronic circuit you need the following parts:

  • a switch,
  • a 1kΩ resistor,
  • and a couple of wires.

The schematic for the circuit looks like this:

Switches have three pins. In one position the switch closes the connection between the middle pin an outer pin while the opposite position establishes a connection between the middle pin and the other outer pin. Therefore, we connect 5V to one of the outer pins and the 1kΩ resistor to the middle pin and ground. We will measure ‘between’ the middle pin and the resistor and therefore have a wire leading from there to pin 7 of the Arduino board. The circuit on your breadboard should look something like this:

Working circuit on breadboard

If everything is set up right, you can connect the board to the USB  port of your computer. The power LED should light up and the next step is to export the program which reads the state of the switch to the board. Open the ap_ReadDigital.pde file in Arduino set the right serial port (from the menu Tools->Serial Port), compile the program, and then click on the Upload icon () to send the program to the board. To check if everything works fine so far, see if the control LED lights up when the switch is in ON-position. If that’s the case, you can then download and unzip pa_Switch.zip and open the file pa_Switch.pde in Processing.

List of serial ports in MS Windows and Mac OS X

Now, you can run your Processing program. A new window will open and you should see something like this:

Output of the program

From the middle a red (or blue) bar will start growing to the right (or left), depending on the position of the switch. If you change the position of the switch, the other bar will start growing and when both bars are of equal size they will both turn green. Play around a little bit and you will see that rhythmic switching will maintain the bar green, isn’t that great?