Martha MigliacioAlex Wong
Published © GPL3+

Using the Pmod HB5 with Arduino Uno

Application notes for Pmod HB5 and Arduino Uno. In this app, pushbuttons will be used to control a motor.

EasyProtip1 hour357
Using the Pmod HB5 with Arduino Uno

Things used in this project

Hardware components

Pmod HB5
Digilent Pmod HB5
×1
Pmod BTN
Digilent Pmod BTN
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Digilent DC Motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Pmod HB5 and Arduino Uno Fritzing file

Fritzing file displaying the connection of the Pmod HB5 to the Arduino Uno.

Pmod HB5 and Arduino Uno Fritzing Image

Fritzing image displaying the connection between the Pmod HB5 and Arduino Uno.
Pmodhb5arduinouno bb n4vjyoopjp

Code

Pmod HB5 and Arduino Uno Code

Arduino
Using this code will control a motor and show the state of the motor in the serial monitor.
/************************************************************************
*
* Test of Pmod HB5
*
*************************************************************************
* Description: Pmod_HB5
* The pushbutton BTN0 controls the motor stop.
* The pushbutton BTN1 controls the increase of the motor speed.
* The pushbutton BTN2 controls the reduction of the speed of the motor.
* The motor speed is displayed on the serial monitor.
*
* Material
* 1. Arduino Uno
* 2. Pmod HB5 
* 3. Pmod BTN 
*
************************************************************************/
// Affectation of pins
#define DIRECTION 2
#define VALIDATION 3
#define BTN_0 4
#define BTN_1 5
#define BTN_2 6

boolean etat_1;
boolean etat_2;
boolean etat_3;
int vitesse=0;
int aff_vitesse;

void setup()
{
 Serial.begin(9600); // Initialization of the serial monitor
 pinMode(DIRECTION,OUTPUT); // Pin configuration
 pinMode(VALIDATION,OUTPUT);
 pinMode(BTN_0,INPUT);
 pinMode(BTN_1,INPUT);
 pinMode(BTN_2,INPUT);
}

void loop()
{
 etat_1=digitalRead(BTN_0); // Reading of switch BTN_0
 etat_2=digitalRead(BTN_1); // Reading of switch BTN_1
 etat_3=digitalRead(BTN_2); // Reading of switch BTN_2
 if (etat_1==HIGH) // stop the motor
  {
   vitesse=0;
  }
  if (etat_2==HIGH) // Speed increase
  {
   vitesse=vitesse+10;
   if(vitesse>255) // The duty cycle is 100%
  {
   vitesse=255;
  }
 }
 if (etat_3==HIGH) // Decrease the speed
 {
  vitesse=vitesse-10;
  if(vitesse<0) // The duty cycle is 0 %
 {
  vitesse=0;
 }
}

digitalWrite(DIRECTION,HIGH); // To turn the motor in the other direction, set LOW to HIGH
analogWrite(VALIDATION,vitesse);
aff_vitesse=map(vitesse,0,255,0,100); // Scaling for display(0 à 100 %)
Serial.print("La vitesse du moteur est egale a ");
Serial.print(aff_vitesse);
Serial.println(" %.");
delay(100);
}

Credits

Martha Migliacio

Martha Migliacio

5 projects • 2 followers
Contact
Alex Wong

Alex Wong

5 projects • 6 followers
I work in Digilent and like creating projects
Contact
Thanks to Lextronics.

Comments

Add projectSign up / Login