极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 16024|回复: 8

使用Arduino控制9个白炽灯节奏亮灯,运行一段时间会跳出的问题

[复制链接]
发表于 2017-5-15 15:49:43 | 显示全部楼层 |阅读模式
由于要做一个道具,于是想到了用Arduino去控制九个白炽灯。搭完装置、传程序执行、给Arduino供5v、给灯泡供220v电,继电器正常工作,可以按照预料的方式点灯,但是在过一段时间(时间不固定,有时可以完成整个程序、有时不能完成)之后,Arduino会莫名其妙复位,运行重新开始。(如果只给Arduino供电、不给灯泡供220v电,继电器正常工作,运行不会跳出。)

各位小哥哥、小姐姐们,是不是我连线的方式有问题?导致灯泡或继电器的供电有问题?不知道能不能解决,不开心。

整个装置的实物图如下:


整个装置的连接图如下,白炽灯用发光二极管代替一下:


装置的程序如下(个人觉得应该不是程序的问题),程序分为两种,第一段使用vixen控制灯的闪烁、第二段直接控制灯的亮灭:
1.使用vixen3控制:
  1. int A = 2;
  2. int B = 3;
  3. int C = 4;
  4. int D = 5;
  5. int E = 6;
  6. int F = 7;
  7. int H = 8;
  8. int I = 9;
  9. int J = 10;


  10. int i = 0;
  11. int incomingByte[8];

  12. void setup()
  13. {
  14.   Serial.begin(57600);
  15.   pinMode(A, OUTPUT);
  16.   pinMode(B, OUTPUT);
  17.   pinMode(C, OUTPUT);
  18.   pinMode(D, OUTPUT);
  19.   pinMode(E, OUTPUT);
  20.   pinMode(F, OUTPUT);
  21.   pinMode(H, OUTPUT);
  22.   pinMode(I, OUTPUT);
  23.   pinMode(J, OUTPUT);

  24. }

  25. void loop()
  26. {
  27.   if (Serial.available() >= 9)
  28.   {
  29.     for (int i=0; i<9;i++)
  30.     {
  31.       incomingByte[i] = Serial.read();
  32.       
  33.     }                                       // Arduino pins
  34.     digitalWrite(A,!incomingByte[0]);  // Pin 2
  35.     digitalWrite(B,!incomingByte[1]);  // Pin 3
  36.     digitalWrite(C,!incomingByte[2]);  // Pin 4
  37.     digitalWrite(D,!incomingByte[3]);  // Pin 5
  38.     digitalWrite(E,!incomingByte[4]);  // Pin 6
  39.     digitalWrite(F,!incomingByte[5]);  // Pin 7
  40.     digitalWrite(H,!incomingByte[6]);  // Pin 9
  41.     digitalWrite(I,!incomingByte[7]);  // Pin 10
  42.     digitalWrite(J,!incomingByte[8]);  // Pin 11
  43.   }
  44. }
复制代码


2.直接控制:
  1. int led[]={2,3,4,5,6,7,8,9,10};
  2. int ledCount=9;

  3. void setup() {
  4.   // put your setup code here, to run once:
  5.   for (int thisLed = 0; thisLed < ledCount; thisLed++) {
  6.     pinMode(led[thisLed], OUTPUT); } //分别定义针脚
  7. }


  8. void liushuiA(){
  9.     for (int thisLed = 0; thisLed < ledCount; thisLed+=2) {
  10.     digitalWrite(led[thisLed],HIGH);
  11. }
  12.     delay(200);
  13.     for (int thisLed =0; thisLed < ledCount; thisLed+=2) {
  14.     digitalWrite(led[thisLed],HIGH);
  15. }
  16.     delay(200);
  17.         for (int thisLed = 0; thisLed < ledCount; thisLed+=2) {
  18.     digitalWrite(led[thisLed],LOW);
  19. }
  20.     delay(200);
  21.         for (int thisLed = 0; thisLed < ledCount; thisLed+=2) {
  22.     digitalWrite(led[thisLed],LOW);
  23.     delay(200);
  24. }
  25. }

  26. void liushuiB(){
  27.     for (int thisLed = 0; thisLed < ledCount; thisLed+=1) {
  28.     digitalWrite(led[thisLed],HIGH);
  29.     delay(200);
  30. }
  31.     for (int thisLed = 0; thisLed < ledCount; thisLed+=1) {
  32.     digitalWrite(led[thisLed],LOW);
  33.     delay(200);
  34. }
  35. }

  36. void liushuiC(){
  37.     for (int thisLed = 0; thisLed < ledCount; thisLed+=2) {
  38.     digitalWrite(led[thisLed],HIGH);
  39. }
  40.     delay(500);
  41.     for (int thisLed = 0; thisLed < ledCount; thisLed+=2) {
  42.     digitalWrite(led[thisLed],LOW);
  43. }
  44.     for (int thisLed = 1; thisLed < ledCount; thisLed+=2) {
  45.     digitalWrite(led[thisLed],HIGH);
  46. }
  47.     delay(500);
  48.     for (int thisLed = 1; thisLed < ledCount; thisLed+=2) {
  49.     digitalWrite(led[thisLed],LOW);
  50. }
  51. }

  52. void liushuiD(){
  53.         for (int thisLed = 0; thisLed < 5; thisLed+=1) {
  54.     digitalWrite(led[thisLed],HIGH);
  55.     delay(500);
  56. }
  57.         for (int thisLed = 8; thisLed > 4; thisLed-=1) {
  58.     digitalWrite(led[thisLed],HIGH);
  59.     delay(500);
  60. }
  61.         for (int thisLed = 0; thisLed < 5; thisLed+=1) {
  62.     digitalWrite(led[thisLed],LOW);
  63.     delay(500);
  64. }
  65.         for (int thisLed = 8; thisLed > 4; thisLed-=1) {
  66.     digitalWrite(led[thisLed],LOW);
  67.     delay(500);
  68. }

  69.    
  70. }


  71. void loop() {

  72.    for(int i=0;i<3;i++){
  73.    liushuiA();
  74.    liushuiB();
  75.    }

  76.      for(int i=0;i<3;i++){
  77.     liushuiC();
  78.     liushuiD();
  79.    }

  80.      for(int i=0;i<3;i++){
  81.    liushuiB();
  82.     liushuiC();
  83.    }

  84.      for(int i=0;i<3;i++){
  85.    liushuiA();
  86.     liushuiD();
  87.    }

  88. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2017-5-15 16:03:54 | 显示全部楼层
本帖最后由 275891381 于 2017-5-15 16:12 编辑

复位一般都是供电的问题吧,是不是你的都是高电平点亮,总电流超过了最大电流;你更改继电器低电平导通试试(一般灌入电流都比输出大),或者每个输出引脚再串一个电阻试试
回复 支持 反对

使用道具 举报

发表于 2017-5-15 16:42:45 | 显示全部楼层
有可能是电磁干扰。
但是像这种纯电阻负载的灯泡在继电器通断时没有多大火花的。电灯不接电空跑没问题,把板子与灯泡独立供电试试,不要用开关电源。
回复 支持 反对

使用道具 举报

发表于 2017-5-15 19:33:27 | 显示全部楼层
继电器复位的大电流使Arduino版触发复位,这个论坛里有很多类似的帖子,可以借鉴一下
回复 支持 反对

使用道具 举报

发表于 2017-5-15 20:10:11 | 显示全部楼层
5V供电功率加大点,5V和地之间加大电容再试试~
回复 支持 反对

使用道具 举报

发表于 2017-5-16 00:19:36 | 显示全部楼层
是不是继电器隔离做得不好,可以用带光耦的继电器试一下
回复 支持 反对

使用道具 举报

发表于 2017-5-16 13:21:22 | 显示全部楼层
最好用固态继电器,一般都带有过零检测,电磁继电器在导通的时候,有可能220V电压刚好处于波峰位置,干扰比较严重。用电器有可能因此一通电就烧坏,不过灯泡烧坏概率还是蛮小的。固态继电器能检测火线零线电压为0的时候才导通,因此最高可能会有20ms的延迟。
回复 支持 反对

使用道具 举报

发表于 2017-5-17 15:18:01 | 显示全部楼层
本帖最后由 迷你强 于 2017-5-17 15:21 编辑

你的继电器板子不带自供电,如果用板子的自带电源供电,功率波动会传导到芯片,造成芯片电压波动,因为不知道你实际使用板子的LDO的质量情况,所以建议你继电器板子单独供电。

其实我推荐你用S-100

https://item.taobao.com/item.htm ... hNhQ&id=45576438031

专门针对设计过的电源系统,能够保证驱动器的mcu的稳定工作,只是不知道8个继电器够不够你用的


回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-6-5 14:50:27 | 显示全部楼层
哇 谢谢各位 问题基本上解决了。将继电器单独供电即可。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-28 20:33 , Processed in 0.052341 second(s), 26 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表