Things used in this project

Hardware components:
Pmod hb5  98780.1456866507.500.659
Digilent Pmod HB5
×1
Pmod btn  25707.1456865908.1280.1280
Digilent Pmod BTN
×1
A000066 iso both
Arduino UNO & Genuino UNO
×1
DC motor (generic)
×1
Software apps and online services:
Ide web
Arduino IDE

Schematics

Pmod HB5 and Arduino Uno Fritzing file
Fritzing file displaying the connection of the Pmod HB5 to the Arduino Uno.
pmodhb5arduinouno_A8DKPhdjQf.fzz
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 CodeArduino
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

01aa44817a11ceb1a3050ebac4b68bbc
Martha Migliacio
1 project • 0 followers
Contact
Thanks to Lextronics.

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login