element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Digilent, a National Instruments Company
  • Products
  • Manufacturers
  • Digilent, a National Instruments Company
  • More
  • Cancel
Digilent, a National Instruments Company
Blog Drive DC Motor with Digilent Pmod H-bridge with Feedback Inputs and Arduino Uno
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Digilent, a National Instruments Company to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: alexwonglik1
  • Date Created: 24 Sep 2020 5:32 AM Date Created
  • Views 6439 views
  • Likes 2 likes
  • Comments 0 comments
  • dc motor
  • microcontroller avr
  • avr
  • arduino uno
  • atmega
  • controller
  • arduino project
  • project
  • sensors
  • h-bridge
  • pwm
  • pmod btn
  • digilent project
  • digilent
  • push buttons
  • pmod hb5
  • pwm dc motor driver
  • motor
  • arduino
  • pmod
Related
Recommended

Drive DC Motor with Digilent Pmod H-bridge with Feedback Inputs and Arduino Uno

alexwonglik1
alexwonglik1
24 Sep 2020

image

 

This projects showcase how to use Digilent  Pmod HB5Pmod HB5 H-bridge driver and Arduino Uno to drive the DC motor. The Pmod HB5 offers a 2A H-bridge circuit to drive small- to medium-sized DC motors. Two sensor feedback pins are incorporated into the motor connection header and are specifically designed to work with the Digilent motor/gearbox, which incorporates quadrature encoder feedback. An Arduino Uno can be used to control the motor direction and speed. Digilent Pmod BTN pushbutton let users input the speed and direction.

 

First of all, you need to connect the Pmod HB5 and Pmod BTN to Arduino Uno. To drive the DC motor, you need to connect a 9V battery to Pmod HB5.

 

Wiring instructions:

 

Pmod HB5 <----------> Arduino Uno <----------> Pmod BTN

  VCC               to                5V                 to       VCC

  GND              to                GND              to       GND

  DIR                to                  2                  to       -

  EN                 to                  3                  to       -

  -                     to                  4                  to       BTN0

  -                     to                  5                  to       BTN1

  -                     to                  6                  to       BTN2

 

image

Then, you can enter the below Arduino code in the Arduino IDE and upload the sketch.

 

/************************************************************************


  Test of the Pmods HB5 and BTN


*************************************************************************
  Project description:  
  The pushbutton BTN0 changes the direction of the motor
  The pushbutton BTN1 increases the motor speed.
  The pushbutton BTN2 decreases the speed of the motor.
  The motor speed is displayed on the serial monitor.
***********************************************************************/


//defining connections
#define DIR   2   
#define EN    3
#define BTN_0 4
#define BTN_1 5
#define BTN_2 6 


void setup() {
  Serial.begin(9600); // Initialization of the serial monitor
  pinMode(DIR, OUTPUT); // Configure DIR to an output pin
  digitalWrite(DIR, LOW); // Set DIR Low 
  pinMode(EN, OUTPUT); // Configure EN to an output pin
  digitalWrite(EN, LOW); // Set EN Low
  pinMode(BTN_0, INPUT); // Configure BTN_0 to input pin
  pinMode(BTN_1, INPUT); // Configure BTN_1 to input pin
  pinMode(BTN_2, INPUT); // Configure BTN_2 to input pin
}


unsigned int spd = 0; //define motor speed as unsigned integer and set initial motor speed to 0
bool dir = LOW;       //define dir (motor direction) as a Boolean variable and set initial direction to low 


void loop() {
  //read buttons
  bool b0 = digitalRead(BTN_0); // Reading BTN_0
  bool b1 = digitalRead(BTN_1); // Reading BTN_1
  bool b2 = digitalRead(BTN_2); // Reading BTN_2


  //increment motor speed by 5 if button 1 is pressed and spd is less than the maximum duty cycle (255)
  if (spd < 255 && b1) {
    spd += 5;
  }


  //decrement motor speed if button 2 is pressed and spd is greater than 0 
  if (spd > 0 && b2) {
    spd -= 5;
  }


  //change direction if button 0 is pressed
  if (b0) {
    dir = !dir;
  }


  //control motor
  digitalWrite(DIR, dir);  //set direction
  analogWrite(EN, spd);  //Use PWM to control the motor speed


  //display data
  Serial.print("Motor speed: ");
  Serial.print(map(spd, 0, 255, 0, 100));  //convert pwm to percentage
  Serial.println("%");
  Serial.print("Direction: ");
  if (dir) {
    Serial.println("counter-clockwise");
  }
  else {
    Serial.println("clockwise");
  }


  delay(100);
}

 

The direction and the speed of the motor are displayed in the serial monitor.

image

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube