Motor Control Module

Motor Control

This module allows you to control actuators such as DC motors and servo motors.

To control a DC motor, select either Motor 1 or Motor 2. You can vary its speed using the slider and change the direction of rotation by selecting the respective button.

To control a servo, select either Servo 1 or Servo 2. You can vary the servo angle by sliding the yellow bar in the clockwise direction.

Introduction

The Motor Control module allows you to control actuators such as DC and Servo motors. 

You can control 2 DC Motors and 2 Servo Motors using this module.

DC Motor Control

Dabble Motor Control OFF

Using the DC Motor control you can control the direction in which the motor should rotate (clockwise or anti-clockwise) and the speed of rotation (adjustable from 0 to 100).

Dabble Motor Control ON

evive

For evive, you can control the motors connected to motor channel 1 and motor channel 2. 

evive motor channel

Arduino Uno/Mega

For controlling motors using Arduino Uno or Mega, you have to use a motor driver having controls through these pins: 

  1. Direction Pin 1 – Digital Pin
  2. Direction Pin 2 – Digital Pin
  3. PWM Pin – PWM Pin

You have to assign those pins in the Arduino Program to control the motor through this module. The example is given in the Arduino tab below.

Servo Motor Control

Dabble Motor Control Servo

Using the Servo Motor control you can control the direction of the servo from 0 degrees to 180 degrees by changing the yellow bar in the clockwise direction.

evive

For evive, you can control the servo motors attached to the servo motor channel 1 and 2. 

evive servo output channel

Arduino Uno/Mega

For controlling servo motors using Arduino Uno or Mega, you have connected signal pin to any digital pin on your board.

You have to assign those pins in the Arduino Program to control the servo motor through this module. The example is given in the Arduino tab below which will clear how to declare pins for motor and servos.

Arduino IDE Functions

Header

To include the Motor Control module in the Arduino program, you have to include the following header:

#define CUSTOM_SETTINGS

#define INCLUDE_MOTORCONTROL_MODULE

After defining the above mention headers, you have to include the dabble library:

#include <Dabble.h>

You can download the zip of Arduino Library for

  1. evive, Uno, Mega, and Nano – Dabble-Arduino 
  2. ESP32 – Dabble-ESP32

depending on the board you are using.

Specify pins of DC motor in case of Mega, Uno, and Nano

  • For controlling one DC motor from “Motor 1” block of Dabble app

motorControls Control = motorControls(pwm,direction1,direction2); 

In above command PWM, direction1 and  direction2 specify the pin that will be used to control connected DC motor.

  • For controlling two DC motors from “Motor 1” and “Motor 2” block of Dabble app.

motorControls Control = motorControls(pwm_m1,direction1_m1,direction2_m1,pwm_m2,direction1_m2,direction2_m2);

In above command parameters like pwm_m1, direction1_m1, etc specifies the pin that will be used to control connected DC motor.

Enabling Bluetooth Communication

To enable Bluetooth communication, you have to initialize serial communication using the following code:

  1. For evive and Arduino Mega, Uno and Nano
    Dabble.begin(Baud_Rate);

    Here Baud_Rate is the baud rate set for the Bluetooth module. With evive, you normally get 115200 baud rate modules.

  2. For ESP32
    Dabble.begin("Bluetooth_Name");

    In place of Bluetooth_Name  enter name that you want to keep for Bluetooth of ESP32. Default name given in the library is “MyEsp32”. 

Refreshing the data

To refresh the data that the device has got from the mobile app, you have to use the following line of code:

Dabble.processInput();

Functions

The following functions can be used to get the DC motor and servo motor control:

For evive, Mega, Uno, and Nano

  1. Control.runMotor1(): This function runs the motor as per commands send from “Motor 1” block in Dabble. In the case of evive, this function always controls motor connected to channel M1 on evive. For other Arduino boards, a motor connected to the pins mentioned by the user will be controlled.
  2. Control.runMotor2(): This function runs the motor as per commands send from “Motor 2” block in Dabble. In the case of evive, this function always controls motor connected to channel M2 on evive. For other Arduino boards, a motor connected to the pins mentioned by the user will be controlled.
  3. Control.getangle_Servo1(): Returns the value of angle as per the position of knob in “Servo 1” block of the motor control module of app.
  4. Control.getangle_Servo2(): Returns the value of angle as per the position of knob in “Servo 2” block of the motor control module of app.

For ESP32

  1. Control.runMotor1(pwmMotor1,dir1Motor1,dir2Motor1): This function runs motor as per the commands send from “Motor 1” block in Dabble. Here parameters pwmMotor1, dir1Motor1, and dir2Motor1 specifies the pins of esp32 on which motor will be connected with the help of the motor driver.
  2. Control.runMotor2(pwmMotor2,dir1Motor2,dir2Motor2): This function runs motor as per the commands send from “Motor 2” block in Dabble. Here parameters pwmMotor2, dir1Motor2, and dir2Motor2 specifies the pins of esp32 on which motor will be connected with the help of the motor driver.
  3. Control.runServo1(pinServo1): This function runs motor as per the commands send from “Servo 1” block in Dabble. Parameter pinServo1 specifies the pin of ESP32 on which signal pin of servo motor will be connected.
  4. Control.runServo2(pinServo2): This function runs motor as per the commands send from “Servo 2” block in Dabble. Parameter pinServo2 specifies the pin of ESP32 on which signal pin of servo motor will be connected.

PictoBlox (Scratch) blocks

evive

There are two blocks available in PictoBlox for Motor Control module. One is for running DC motors as per command send from the motor control module of Dabble and one is for running Servo Motors.

  • enable motor channel ()”  is a stacked block with two options in its drop-down for selecting the motor channel and corresponding its corresponding control in Dabble. This means on selecting ‘1‘ from drop down you will be able to control motor channel M1 on evive with “Motor 1” module of the motor control module. Similarly “Motor2” module runs motor channel M2  on evive.
  • enable Servo () for servo connected to channel ()” is a stacked block with two drop downs. First drop down is for selecting which servo module in the motor control module will be used for controlling a servo motor connected to pin selected from the second drop down. As per the pin number listed in the second drop down it is possible for the user to connect the servo to servo channel S1 and S2 as well as on digital pin 2 to 13.  

Mega, Uno, and Nano

  • enable motor () connected to direction pin (), () and pwm pin ()” is a stacked block that has 4 drop downs. First drop down is for selecting which motor module of Dabble will control the motor driver connected to digital pins selected from the other three drop downs. In turn, the motor driver will control the DC motor connected to it. For example, if you select ‘2‘ in the first drop down then “Motor 2” module of Dabble will control motor connected to pins selected from other three drop downs. 
  • enable servo () connected to pin ()” is a stacked block with two drop downs. First drop down is for selecting which servo module in the motor control module will be used for controlling a servo motor connected to pin selected from the second drop down. For example, if ‘2‘ is selected from the first drop down and ‘5‘ is selected from the second drop down, a servo connected to pin 5 will be controlled by “Servo 2” module of Dabble.  

 

evive Notes Icon
Note: When you are using this module with Arduino Uno, Mega, and Nano,  you have to set the Bluetooth baud rate to the baud rate of the Bluetooth module to have proper communication between the board and the module. To set the baud rate you have to use set bluetooth baud rate to () block.

set bluetooth baud rate to

Examples

Click here to view Arduino IDE Example for Motor Control Module

You can either copy code stated below or navigate to “Files>>Examples>>Dabble>>” and select motor control code as per your board.

evive

In this example, a motor and servo connected on evive will be controlled through the Dabble app.

For other boards, you have to connect motors to motor driver and mention the pins of your boards that you have used in with the motor driver. Below mentioned code controls two motors and two servos.

Mega, Uno, and Nano

ESP32

 

Click here to view PictoBlox (Scratch) Example for Motor Control Module

Enable Motor Control Block

To enable the Motor Control feature, you have to make the following script in Upload mode

Change the head block as per the selected board. PictoBlox does not support ESP32 but its support will be added soon. 

Projects

3D-Printed-Text-Display
DIY 3D Printed Text Display
IntroductionIf you’re looking for the perfect gift for someone special, look no further! The DIY…
All articles loaded
No more articles to load

Leave a Reply

Close Menu
×

Cart