荣耀彩票代理

IT技术互动交流平台

手把手教你智能硬件开发(六)直流马达

来源:IT165收集  发布日期:2016-10-09 20:16:10

第6节 直流马达

MADASHIWOMENJINGCHANGSHIYONGDAODEDIANDONGZHUANGZHI,TAKEYIJIANGDIANNENGZHUANHUACHENGDONGNENG,QUDONGQITADONGXIDEYUNDONG。TINGQILAIHENCHOUXIANG,JUJIGELIZIBA。

WOMENXIAOSHIHOUWANDESIQUCHE,DAIDONGLUNZIZHUANDONGDENEIGEXIAOZHUANGZHIJIUSHIMADA;XIATIANRANGFENGSHANXUANZHUANDAIJIWOMENLIANGYI,YESHIMADADEGONGLAO。

GENJUSHIYONGDIANYUANDEBUTONG,KEYIJIANGMADAFENCHENGZHILIUMADAHEJIAOLIUMADA。WOMENZUOZHINENGYINGJIANSHIYONGDEJIBENDOUSHIZHILIUMADA,TONGGUOMADALAIQUDONGWAIJIESHEBEIYUNDONG。

6.1 工作原理

荣耀彩票代理JIANGDIANNENGZHUANHUACHENGDONGNENGDEWULIYUANLI,WOMENZAIZHONGXUEYIJINGXUEGUO,ZHEILILIYONGLELIANGGEYUANLI:DIANCIGANYINGHECITIEDETONGXINGXIANGCHIYIXINGXIANGXI。

将一根磁棒放在金属罩中间,两端悬上一个金属柱子,金属柱子上面有线圈; 当线圈通过电流的时候,就能产生磁场,磁棒根据极性改变位置; 改变电流方向,线圈磁场方向发生调换,磁棒再次根据极性改变位置; 如此往复,磁棒就旋转了起来。

YIGEMADADEWAIXINGDAZHIRUCI,

荣耀彩票代理MADAJIASHANGYIXIEJIEGOU,YULUNTAIJIEHEQILAIJIUCHENGLELUNZI

荣耀彩票代理TAYOULIANGGEJIEXIANDEDIFANG,YICHUJIEZHENGJI,LINGYICHUJIUJIEFUJI,

在不超过极限电压的情况下,对马达施加的电压越大,马达就转动的越快; 调转正负极的连接顺序,马达的旋转方向也发生调转;

6.2 连接方式

MADADEZHENGFUJIBUNENGZHIJIELIANJIEDAOArduinoKAIFABANDEYINJIAOSHANG,BIXUSHIYONGYIGEZHUANHUANDIANLU。FOUZEMADAZAIZHUANDONGDEGUOCHENGZHONGKENENGHUICHANSHENGQIANGDADEDIANLIU,JICHUANKAIFABANSHANGDEYUANQIJIAN。

WEICI,KEYISHIYONGZHUANMENDEMADAKUOZHANBAN,LAILIANJIESHIYONGMADA,

荣耀彩票代理YEKEYISHIYONGJICHENGLEZHUANHUANDIANLUDEMADAMOKUAI,LIRUFENGSHANMADAMOKUAI,

荣耀彩票代理ZAICIWOMENXUANYONGJICHENGLEZHUANHUANDIANLUDEFENGSHANMADAMOKUAILAIJIANGJIE。

GAIMOKUAIYOU4GEYINJIAO,

模块引脚 功能说明
INA 控制接口A
INB 控制接口B
VCC 直流电
GND 接地

荣耀彩票代理YINWEIYAODIAOZHENGZHILIUMADADEZHUANDONGSUDU,INAYUINBZUIHAOJIEDAOJUYOUPWMGONGNENGDEJIEKOUSHANG,TONGGUOSHEZHIGAIYINJIAODEJISHUSHU,LAIDIAOJIEMADADEZHUANSU。ZHEILI,WOMENJIANGINALIANJIEDAOD9,INBLIANJIEDAOD8,

模块引脚 连接 Arduino扩展板
INA <–> D9组S引脚
INB <–> D8组S引脚
VCC <–> D8组V引脚
GND <–> D8组G引脚

6.3 代码设计

荣耀彩票代理SHOUXIANYAOCHUSHIHUAINAYUINBLIANJIEDEJIEKOU,RANGArduinoKAIFABANYONGYOUXIANGTAMENSHUCHUDENENGLI,

//INA使用具有PWM功能的D9引脚
int INA = 9;
//INB使用具有PWM功能的D8引脚
int INB = 8;

void setup() {
    //设置引脚为输出
    pinMode(INA, OUTPUT);
    pinMode(INB, OUTPUT);
}

JIANGINAYINJIAOSHEZHICHENGDIDIANPINGLOW,GAIBIANINBYINJIAODEZHI,LAIDADAOKONGZHIMADAZHUANSUDEXIAOGUO,

void setup() {
    //设置引脚为输出
    pinMode(INA, OUTPUT);
    pinMode(INB, OUTPUT);
    digitalWrite(INA, LOW);
}

void loop() {
    //从0级到100级
    for(int level = 0 ; level < 100+1; level++)
    {
        //调整INB上的电压级数,达到改变风扇转速的效果
        analogWrite(INB, level);
        delay(100);
    }
}

荣耀彩票代理ZHEILIJIANGDIAOZHENGDEJISHU,DIAOZHENGZAILE0~100。LILUNSHANGKEYIDIAOZHENGDEJISHUYINGGAISHI0~255JI。DANSHIYOUYUMADADIANLIUFUZAIDEYUANYIN,SHEZHIDAOGAOJISHUSHI,LIRU245JI,HUIRANGKAIFABANGUOZAI。YINCIKEYIBAZUIDAJISHUSHEZHIDESHAOWEIXIAOYIDIAN,LIRU230JI,

int INA = 9;
int INB = 8;

int START_LEVEL = 0;
int END_LEVEL = 230;

void setup() {
  pinMode(INA, OUTPUT);
  pinMode(INB, OUTPUT);
  digitalWrite(INA, LOW);
}

void loop() {

    //从9级慢慢加速到230级
    for(int level = START_LEVEL ; level < END_LEVEL+1; level++)
    {
        analogWrite(INB, level);
        delay(100);
    }

    //从230级慢慢减速到0级
    for(int level = END_LEVEL; level > START_LEVEL ; level--)
    {
        analogWrite(INB, level);
        delay(100);
    }
}

6.4 结果观察

MADAKAISHIHUANMANDEXUANZHUAN,YUEZHUANYUEKUAI;DADAOZUIKUAIZHUANSUSHI,YOUKAISHIJIANSU,ZHIDAOTINGZHI;ZHENGGEGUOCHENGZHOUERFUSHI。

6.5 马达的反转

荣耀彩票代理RUGUOXIANGXIUGAIMADAXUANZHUANDEFANGXIANG,KEYIJIANGINBSHEZHIWEIDIDIANPINGLOW,GAIBIANINAYINJIAODEZHI,

int INA = 9;
int INB = 8;

int START_LEVEL = 0;
int END_LEVEL = 230;

void setup() {
  pinMode(INA, OUTPUT);
  pinMode(INB, OUTPUT);
}

void loop() {
    //朝着一个方向旋转,先加速,再减速
    //INA设置为LOW
    digitalWrite(INA, LOW);
    for(int level = START_LEVEL ; level < END_LEVEL+1; level++)
    {
        //改写INB的级数
        analogWrite(INB, level);
        delay(100);
    }
    for(int level = END_LEVEL; level > START_LEVEL ; level--)
    {
        //改写INB的级数
        analogWrite(INB, level);
        delay(100);
    }

    //朝着另一个方向旋转,先加速,再减速
    //INB设置为LOW
    digitalWrite(INB, LOW);
    for(int level = START_LEVEL ; level < END_LEVEL+1; level++)
    {
        //改写INA的级数
        analogWrite(INA, level);
        delay(100);
    }
    for(int level = END_LEVEL; level > START_LEVEL ; level--)
    {
        //改写INA的级数
        analogWrite(INA, level);
        delay(100);
    }
}

/*******************************************************************/
* 版权声明
* 本教程只在CSDN和安豆网发布,其他网站出现本教程均属侵权。

*另外,我们还推出了Arduino智能硬件相关的教程,您可以在我们的网店安豆的杂货铺荣耀彩票代理中购买相关硬件。同时也感谢大家对我们这些码农的支持。

*最后再次感谢各位读者对安豆的支持,谢谢:)
/*******************************************************************/

Tag标签:         
  • 专题推荐

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规