Site Tools


Sidebar

Content

pub:dc_motor_fan

Dc_motor_fan

L911S: L9110 is a driver chip which is used to control and drive motor. The chip has two TTL/CMOS compatible input terminals, and possesses the property of anti-interference: it has high current driving capability, two output terminals that can directly drive DC motor, each output port can provide 750~800mA dynamic current, and its peak current can reach 1.5~2.0A; L9110 is widely applied to various motor drives, such as toy cars, stepper motor, power switches and other electric circuits.


OA, OB: These are used to connect the DC motor.
VCC: Power supply (+5V)
GND: The cathode of the power supply (Ground).
IA, IB: The input terminal of drive signal

DC_motor: A DC motor is any of a class of electrical machines that converts direct current electrical power into mechanical power. The most common types rely on the forces produced by magnetic fields. Nearly all types of DC motors have some internal mechanism, either electromechanical or electronic, to periodically change the direction of current flow in part of the motor. Most types produce rotary motion; a linear motor directly produces force and motion in a straight line. DC motors were the first type widely used, since they could be powered from existing direct-current lighting power distribution systems. A DC motor's speed can be controlled over a wide range, using either a variable supply voltage or by changing the strength of current in its field windings. Small DC motors are used in tools, toys, and appliances. The universal motor can operate on direct current but is a lightweight motor used for portable power tools and appliances

Pins information:

B Digital output
A Digital output
+ VCC
- GND



Microbit

Components
1 * microbit
1 * microbit expansion board
1 * USB cable
1 * Adeept motor fan
- Several Jumper wires


Adeept microbit DC motor Module
Pin1 B
Pin0 A
3.3V +
GND -

Code:
Makecode:


MU Python:

  #-----------------------------------------------------------
# File name   : DC_fan.py
# Description : micro control DC motor.
# Author      : jason
# E-mail      : jason@adeept.com
# Website     : www.adeept.com
# Date        : 2019/01/08
#-----------------------------------------------------------
from microbit import *
 
while True:
    if button_a.is_pressed():
        pin0.write_digital(0)
        pin1.write_analog(800)
        sleep(50)
    if button_b.is_pressed():
        pin1.write_analog(0)
        sleep(50)
 

Click “flash” and download the code onto the micro:bit.
When the button A is pressed, the DC motor fan blows outwards counterclockwise, and when the button B is pressed, the DC motor fan blows clockwise.
Effect Picture:



Arduino

Components
- 1 * Adeept Arduino UNO R3 Board
- 1 * DC Motor Module
- 1 * USB Cable
- 1 * 4-Pin Wires

Build the circuit


Adeept UNO R3 Board DC Motor Module
D10 B
D11 A
Vin(+5V) +
GND -

Code:

  /***********************************************************
File name: _26_DCMotorModule.ino
Description: The state of DC motor includes its forward, reverse,
             acceleration, deceleration and stop. And you will 
             see the data on the serial monitor 
Website: www.adeept.com
E-mail: support@adeept.com
Author: Tom
Date: 2019/01/08 
***********************************************************/
 
const int APin = 11;                       //DC motor module A pin connected to digital 11 pin
const int BPin = 10;                       //DC motor module B pin connected to digital 10 pin
int DCmotorspeed = 60;                      //motor speed  0~255
 
void setup()
{
  pinMode(APin,OUTPUT);                    //initialize the A pin as output 
  pinMode(BPin,OUTPUT);                    //initialize the B pin as output 
//Serial.begin(9600);                      //opens serial port, sets data rate to 9600 bps
}
 
void loop()
{
  clockwise(0);                             //motor stop
//Serial.println(0);                       //send data to the serial monitor
  delay(1000);                              //delay 1s
  DCmotorspeed = 60;
  for(int i=0;i<7;i++){
    DCmotorspeed = DCmotorspeed + 20;       //motor speed increases 20
    clockwise(DCmotorspeed);                //motor forward
//  Serial.println(DCmotorspeed);          //send data to the serial monitor
    delay(1000);                            //delay 1s
  }
  for(int i=0;i<6;i++){
    DCmotorspeed = DCmotorspeed - 20;       //motor speed reduction 20
    clockwise(DCmotorspeed);                //motor forward
//  Serial.println(DCmotorspeed);          //send data to the serial monitor
    delay(1000);                            //delay 1s
  }
  clockwise(0);                             //motor stop
  Serial.println(0);                       //send data to the serial monitor
  delay(1000);                              //delay 1s
  DCmotorspeed = 60;
  for(int i=0;i<7;i++){
    DCmotorspeed = DCmotorspeed + 20;       //motor speed increases 20
    counterclockwise(DCmotorspeed);         //motor reverse
//  Serial.println(DCmotorspeed);          //send data to the serial monitor
    delay(1000);                            //delay 1s
  }
  for(int i=0;i<6;i++){
    DCmotorspeed = DCmotorspeed - 20;        //motor speed reduction 20
    counterclockwise(DCmotorspeed);         //motor reverse
//  Serial.println(DCmotorspeed);           //send data to the serial monitor
    delay(1000);                            //delay 1s
  }
}
void clockwise(int Speed)                   //the function to drive motor rotate clockwise
{
  analogWrite(APin,Speed);                  //set the speed of motor
  analogWrite(BPin,0);                      //stop the B pin of motor
}
void counterclockwise(int Speed)            //the function to drive motor rotate counterclockwise
{
  analogWrite(APin,0);                      //stop the A pin of motor
  analogWrite(BPin,Speed);                  //set the speed of motor
}

Compile and download the sketch to the UNO R3 board.



Now you can see the fan rotates forward, accelerate, speed down, stop, start and accelerate, speed down again, and stop again. At the same time the value of the speed set will be sent to and displayed on Serial Monitor.



Raspberry pi

Components
- 1 * Raspberry Pi
- 1 * GPIO Extension Board
- 1 * 40-Pin GPIO Cable
- 1 * Breadboard
- 1 * DC Motor Module
- 1 * 4-Pin Wires

Build the circuit


Cdoe:
C code :

  /*
* File name   : motor.c
* Description : controlling a 5V DC motor
* Website     : www.adeept.com
* E-mail      : support@adeept.com
* Author      : Jason
* Date        : 2019/01/08
*/
#include <wiringPi.h>
#include <softPwm.h>
#include <stdio.h>
 
#define MotorPin_A   0
#define MotorPin_B   1
 
void motor(int status, int dir)
{
	pinMode(MotorPin_A, OUTPUT);
	pinMode(MotorPin_B, OUTPUT);
 
	if(0 == status){   //stop
		digitalWrite(MotorPin_A, HIGH);
		digitalWrite(MotorPin_B, HIGH);
	}else{  //run
		if(0 == dir){  //clockwise
			digitalWrite(MotorPin_A, HIGH);
			digitalWrite(MotorPin_B, LOW);
		}else{  //anticlockwise
			digitalWrite(MotorPin_A, LOW);
			digitalWrite(MotorPin_B, HIGH);
		}
	}
}
 
int main(void)
{
	if(wiringPiSetup() == -1){
		printf("setup wiringPi failed !\n");
		return -1; 
	}
 
	while(1){
		motor(1, 1);
		delay(5000);
 
		motor(0, 1);//stop
		delay(5000);
 
		motor(1, 0);
		delay(5000);
	}
 
	return 0;
}

Python code:

  #!/usr/bin/env python
import RPi.GPIO as GPIO
import time
 
MotorPin_A  = 11
MotorPin_B  = 12
 
def motorStop():
	GPIO.output(MotorPin_A, GPIO.HIGH)
	GPIO.output(MotorPin_B, GPIO.HIGH)
 
def setup():
	GPIO.setwarnings(False)
	GPIO.setmode(GPIO.BOARD)
	GPIO.setup(MotorPin_A, GPIO.OUT)
	GPIO.setup(MotorPin_B, GPIO.OUT)
	motorStop()
 
def motor(status, direction):
	if status == 1:  # run
		if direction == 1:
			GPIO.output(MotorPin_A, GPIO.HIGH)
			GPIO.output(MotorPin_B, GPIO.LOW)
		else:
			GPIO.output(MotorPin_A, GPIO.LOW)
			GPIO.output(MotorPin_B, GPIO.HIGH)
	else:  # stop
		motorStop()
 
def loop():
	while True:
		motor(1, 1)
		time.sleep(5000)
		motor(0, 1)
		time.sleep(5000)
		motor(1, 0)
		time.sleep(5000)
 
def destroy():
	motorStop()
	GPIO.cleanup()             # Release resource
 
if __name__ == '__main__':     # Program start from here
	setup()
	try:
		loop()
	except KeyboardInterrupt:
		destroy()

For C language users:

Step 2: Edit and save the code with vim or nano.

(code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/11_motor/motor.c)

Step 3: Compile

$ sudo gcc motor.c -o motor -lwiringPiStep 

4: Run

$ sudo ./motor

For Python users:

Step 2: Edit and save the code with vim or nano.

(code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/11_motor.py)

Step 3: Run

$ sudo ./11_motor.py

Now you can see the fan rotates forward, stop, reverse.


Reference material:http://www.adeept.com/learn/
Video:http://www.adeept.com/video/

pub/dc_motor_fan.txt · Last modified: 2019/01/09 11:14 by Adeept