Skip to content

DIYables/DIYables-DC-Motor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DIYables DC Motor Library for Arduino Motor Shield

Easy-to-use Arduino library for controlling DC motors via the **Arduino Motor Shield (L298P dual full-bridge driver). Supports both Channel A and Channel B with direction control, PWM speed, brake, and current sensing.

DIYables Motor Shield

Product

Tested Hardware

Board Tested
Arduino Uno R3
Arduino Uno R4 WiFi
Arduino Uno R4 Minima
Arduino Mega
Arduino Giga
DIYables STEM V4 IoT (works like Arduino Uno R4 WiFi)
DIYables STEM V4B IoT (works like Arduino Uno R4 WiFi)
DIYables STEM V3 (works like Arduino Uno R3)
DIYables STEM V4B Edu (works like Arduino Uno R4 Minima)
DIYables MEGA2560 R3 (works like Arduino Mega 2560 Rev3)
Other boards Not yet, expected to work

Features

  • Control DC motors on Channel A and/or Channel B
  • Set direction (forward / backward)
  • Set speed via PWM (0-255)
  • Activate and release brake
  • Read motor current via analog sensing pins
  • Support for custom pin assignments

Hardware Required

  • Arduino UNO (or compatible board)
  • Arduino Motor Shield Rev3
  • DC motor (6-12V)
  • External power source (e.g., 2x 3.7V Li-Ion 18650 batteries)

Pin Mapping (Motor Shield Rev3)

Function Channel A Channel B
Direction D12 D13
PWM (speed) D3 D11
Brake D9 D8
Current Sensing A0 A1

Quick Start

#include <DIYables_DC_Motor.h>

DIYables_DC_Motor motor(MOTOR_CH_A);

void setup() {
  motor.begin();
}

void loop() {
  motor.run(MOTOR_FORWARD, 100);   // forward at speed 100
  delay(2000);

  motor.brake();                    // stop
  delay(1000);

  motor.run(MOTOR_BACKWARD, 100);  // backward at speed 100
  delay(2000);

  motor.brake();                    // stop
  delay(1000);
}

Examples

  • ChannelA: Control a motor on Channel A
  • ChannelB: Control a motor on Channel B
  • BothChannels: Control two motors simultaneously
  • CurrentSensing: Read motor current draw
  • CustomPins: Use custom pin assignments

API Reference

See DIYables DC Motor Library Reference for the complete API documentation including all constructors, methods, and constants.

Tutorials

License

BSD. See license.txt.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages