MAKER:Giannis Vasilakis/译:趣无尽 Cherry(转载请注明出处)
本次教程介绍一款从原理图、PCB、源码、3D外壳图纸齐全的开源小项目,小巧实用的生态缸光照系统。该项目是基于 Atmega328p 微控制器和 Arduino 制作,很适合拿来练手。
功能特性:
1、支持通过串行监视器设置系统时间。
2、通过编程控制光照时间和颜色。
观看视频,感受一下灯光的实际效果:
下面罗列了主要的部件和资源,具体的 DIY 操作步骤不再赘述,如有问题欢迎在「趣小组」(https://talk.quwj.com) 交流。
材料清单
定制 PCB 电路板×1
Atmega328×1(带 Arduino UNO bootloader)
NeoPixel RGB LED 防水灯×1
DS1307串行 RTC×1
28 DIP插座×1
8 DIP插座×1
16 MHz 晶振×1
32.768 MHz 晶振×1
22 pF 电容×2
10 k电阻×3
纽扣电池座×1
2.54mm 2P 螺丝端子×1
2.54mm 5 针排针×1
电线×5
TTL 转 USB 模块×1(可选)
Arduino UNO 或 TTL 转 USB 模块
电路原理图和 PCB
如需下载和编辑,可以在这里查看:
https://easyeda.com/mi.vasilakis/Aquarium_RGB_Led_light-99e1c88d0aed47d3a384e2086172e1bf
编程
用五根线将 TTL 转 USB 模块与 PCB 上的TX、RX、RS、GND、5V相连,其中引脚 RX 和 TX 必须交叉连接。
注意:如果你使用的是 Arduino UNO,请先从板子上取下 ATmega328 芯片,然后将板子的 RX 接头连接到 RX 引脚,将 TX 接头连接到 TX 引脚。 RS 引脚必须连接到 Arduino UNO 复位引脚。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | /* Arduino based - Aquarium Auto Lighing System * More info can be found at: http://www.ardumotive.com * Dev:Michalis Vasilakis Date:21/2/2018 Var:1.0 */ //Libraries (many thanks to Developers) #include <Adafruit_NeoPixel.h> #include <RTClib.h> //Constants const int DIN = 2; //Neopixel DIN pin to Arduino Pin 2 const int PIXELS = 29; //How many neopixel leds do you have? RTC_DS1307 rtc; //Create an object for DS1307 I2C library Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXELS, DIN, NEO_GRB + NEO_KHZ800); //Create an object for NeoPixel library //Variables; int H,M; //H for hour and M for minutes String Time; // Use readTime(); Serial.print(Time); for printing the time in serial monitor //Variables For color setting boolean newColor = false; int r=0; int g=0; int b=0; //Following variables are used for the time setting from serial monitor boolean newMessage = false; boolean messageCompleted = false; char incomingByte; String command; //Delay without delay() for fade unsigned long previousMillis = 0; const long interval = 250; //Change this value (ms) void setup() { pixels.begin(); //Initialize the NeoPixel library rtc.begin(); //Initialize the RTC DS1307 library Serial.begin(9600); //This will run only if the rtc battery is low or rtc ic has wrong time set if (! rtc.isrunning()) { Serial.println("RTC is NOT running!"); // This line sets the RTC with an explicit date & time, for example to set // January 1, 2018 at 00:00am you would call: rtc.adjust(DateTime(2018, 01, 01, 00, 00, 0)); } Serial.println("Aquarium Auto Lighting System"); Serial.println("Visit the www.Ardumotive.com for more info \n"); readTime(); Serial.println(Time); Serial.println("- To set the time send '<SHH:MM>' (example: <S14:05>)"); } void loop() { setTime(); //Check for serial set command readTime(); //Change time and color values bellow if you want //From 00:00 to 07:00 if (H>=0 && H <7) { setColor(0,0,50); } //From 07:00 to 12:00 else if (H>=7 && H<12){ setColor(50,50,100); } else if( H>=12 && H<19){ setColor(180,180,180); } else if (H>=19 && H<21){ setColor(50,50,100); } } //Send color to led strip void setColor(int R,int G,int B){ while ((r!=R) || (g!=G) || (b!=B)){ setTime(); //Check for serial set command unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; for(int i=0;i<PIXELS;i++){ // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 pixels.setPixelColor(i, pixels.Color(r,g,b)); pixels.show(); } if (r!=R && r<R){ r++; } else if (r!=R && r>R){ r--; } if (g!=G && g<G){ g++; } else if (g!=G && g>G){ g--; } if (b!=B && b<B){ b++; } else if (b!=B && b>B){ b--; } } } } //Read time from RTC void readTime(){ DateTime now = rtc.now(); H = now.hour(); M = now.minute(); Time = "Current time in RTC: " + String(H) + ":" + String(M); } //Set time, send <SHH:MM> (example <S05:00>) void setTime(){ if (Serial.available()){ incomingByte = Serial.read(); if(incomingByte=='>'){ messageCompleted=true; newMessage=false; } else if (incomingByte=='<'){ newMessage=true; } if (newMessage){ command.concat(incomingByte); } } if(messageCompleted){ //Set time if (command.charAt(1)=='S'){ int h = (command.substring(2,4)).toInt(); int m = (command.substring(5,7)).toInt(); rtc.adjust(DateTime(2018,01,01,h,m,0)); Serial.println("Done"); readTime(); Serial.println(Time); } command=""; messageCompleted=false; } } |
代码文件在项目文件库中下载:
https://make.quwj.com/project/152
3D 打印外壳
3D 打印图纸在项目文件库中下载:
https://make.quwj.com/project/152
完成!
希望你喜欢这个项目,点亮起你的鱼缸。
发表评论
要发表评论,您必须先登录。