Martha MigliacioAlex Wong
Published © GPL3+

Using the Pmod DHB1 with Arduino Uno

Application notes for Pmod DHB1 and Arduino Uno. In this app, motor control is carried out using the serial monitor.

EasyProtip1 hour162
Using the Pmod DHB1 with Arduino Uno

Things used in this project

Hardware components

Pmod DHB1
Digilent Pmod DHB1
×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 DHB1 and Arduino Uno Fritzing file

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

Pmod DHB1 and Arduino Uno Fritzing Image

Fritzing image displaying the connection between the Pmod DHB1 and Arduino Uno.
Pmoddhb1arduinouno bb yfqkifmf45

Code

Pmod DHB1 and Arduino Uno Code

Arduino
Using this code will control a motor using the serial monitor.
/************************************************************************
*
* Test of Pmod DHB1
*
*************************************************************************
* Description: Pmod_DHB1
* Motor control is carried out using the serial monitor.
*
* Material
* 1. Arduino Uno
* 2. Pmod DHB1 module (set jumper JP1 and JP2 on 1)
*
************************************************************************/
// Affectation of pins
#define DIRECTION 2
#define VALIDATION 3

char sens=0;
char recu[3];
boolean dir;
int vitesse=0;
int vitesse_moteur;

void setup()
{
 Serial.begin(9600); // initialization of the serial monitor
 pinMode(DIRECTION,OUTPUT); // Pin configuration
 pinMode(VALIDATION,OUTPUT);
}

void loop()
{
 Serial.println("Rentrer le sens (A: avance ou R:recule) puis Envoyer");
 while (Serial.available()==0); // Waiting for the way parameter
 sens=Serial.read(); // Reception of the way parameter
 Serial.println("Rentrer la vitesse (000..100) puis Envoyer");
 while (Serial.available()==0); // Waiting for the speed parameter
   for (int i=0;i<3;i++) // Reception of the speed parameter
   {
   recu[i]=Serial.read();
   delay(10);
   }
 vitesse=(recu[0]-48)*100+(recu[1]-48)*10+recu[2]-48; // Reconstruction of the speed variable
 vitesse_moteur=map(vitesse,0,100,0,255); // Change of scale for motor speed variable (0 to
255)
 Serial.print("Le moteur tourne dans le sens ");
 if (sens==65) // code ASCII for A
   {
    dir=HIGH;
    Serial.print("horaire");
   }
 if (sens==82) // code ASCII for R
   {
    dir=LOW;
    Serial.print("anti-horaire");
   }
  Serial.print(" avec une vitesse de ");
  Serial.print(vitesse);
  Serial.println(" %");
  Serial.println(" ");
  digitalWrite(DIRECTION,dir);
  analogWrite(VALIDATION,vitesse_moteur);
  delay(100);
}

Credits

Martha Migliacio

Martha Migliacio

49 projects • 5 followers
Alex Wong

Alex Wong

49 projects • 13 followers
I work in Digilent and like creating projects
Thanks to Lextronics.

Comments

Add projectSign up / Login