闪电云方案

闪电云是这样的一个装置,基本的功能是当有人经过的时候,会做出闪电的效果。

闪电云这个项目算是做的次数和种类最多的一个项目了,做过能知道实时天气的,能留言的,能发生的,加大的,joint版的、ESP8266版的。。。。

其实闪电云的技术难度是很低的,很适合各种年龄段的人做。这个教程是用最常见的材料实现最基本的功能的一种闪电云。

物料清单

  1. Arduino Nano
  2. 热释电传感器
  3. WS2812灯条
  4. 直径20cm灯笼
  5. PP棉
  6. 杜邦线6根(针对孔3,孔对孔3)

制作步骤

电路连接图

逻辑部分
电路部分

连接电路

清单

焊接杜邦线和灯带

焊接完成的样子

连接传感器灯带和Arduino





选择对应的Arduino型号和端口

烧写程序

查看效果

撑起灯笼

装入灯笼中查看效果

几个需要注意的地方

  1. Arduino Nano上有标注的只有一个5v。但是灯条和传感器都需要有5v的电压供电,这时候可以将其中的一个引脚连接到ICSP上。


    ICSP上5V和GND引脚的位置
  2. 杜邦线焊接的位置一定要是灯条上标有Din的那一端而不能是Dout的那一端。

外形制作

其实主要就是粘棉花了。。。

为了让外形开起来更像云而不是一个球,也可以增加两个透明的吸管。

将两个吸管插到一起以增加长度

如果想长期使用的话,为了保险建议用热熔胶加固一下链接部分

然后用热熔胶把Arduino固定在灯笼的横梁上

同样用热熔胶把热释电传感器固定在下面的横梁上


将吸管横穿灯笼,在连接处用热熔胶固定

在灯笼上涂热熔胶,然后将棉花粘贴在上面

完成图案

效果展示

注意的地方

  1. 尽量用大片的棉花粘,这样出来的外形会好看一些,更像云,不然会很像绵羊。。。
  2. 由于重力的原因,初期粘的时候尽量在上半边多粘一些,后面会下移一点,如果主要的棉花粘到了下面,过一段时间棉花就会往下掉。。。
  3. 热熔胶棒使用很快,我做这一个大概要用三根热熔胶棒。

程序烧写 下面是闪电云需要的程序

这个程序会在有人经过闪电云附近的时候随机触发4种效果,其中一种七彩效果的概率很低(概率是1/61),然后每隔100秒就触发一次自亮点效果,如果你想做出自己的效果,也可以自己改代码。另外运行这个代码需要下载Adafruit NEOpixel 的库,下载地址在这里:https://github.com/adafruit/Adafruit_NeoPixel

#include <Adafruit_NeoPixel.h>
   

#define PIXEL_PIN    6  //灯条链接引脚
#define SENSOR_PIN   9  //传感器链接引脚

#define PIXEL_COUNT 8  //灯珠的个数

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

int randomNumber;






void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

  pinMode(SENSOR_PIN, INPUT);
  randomSeed(analogRead(0));
  
  Serial.begin(9600);

}

void loop() {
  
  
  if( digitalRead(SENSOR_PIN) == HIGH){
    randomNumber = random(300);
    Serial.println(randomNumber % 61);
    thunder_strike(randomNumber % 61);
 
    delay(3000);

  }else{

    if(millis() % 100000 == 0){
      for(int i=20; i<100; i++){
        colorWipe(strip.Color(i,i-20,0),0);
          
      }
      for(int i=100; i>20; i--){
        colorWipe(strip.Color(i,i-20,0),0);
          
      }
      colorWipe(strip.Color(0,0,0),0);
      
      delay(3000);
       
    }

  }
        
    

      
  
}


void thunder_strike( int type) {
  if(type < 20){
      
        colorWipe_short(0, PIXEL_COUNT, strip.Color(73, 147, 255), 3);
        colorWipe(strip.Color(0, 0, 0), 0);
        delay(500);
        colorWipe_short(0, PIXEL_COUNT, strip.Color(73, 147, 255), 3);
        delay(20);
        colorWipe(strip.Color(0, 0, 0), 0);
        delay(500);

  }else if(type < 40){
      
        colorWipe(strip.Color(104, 94, 94), 3);
        colorWipe(strip.Color(0,0,0), 0);
        delay(500);
        colorWipe(strip.Color(104, 94, 94), 3);
        delay(20);
        colorWipe(strip.Color(0,0,0), 0);
        delay(500);
  }else if(type < 60){   
        colorWipe(strip.Color(181, 165, 95), 3);
        delay(1000);
        colorWipe(strip.Color(0,0,0), 0);
        delay(100);
        colorWipe(strip.Color(181, 165, 95), 3);
        delay(500);
        colorWipe(strip.Color(0,0,0), 0);
        delay(500);
  }else{
        rainbowCycle(5);
        colorWipe(strip.Color(0,0,0), 0);
  }
}


void colorWipe_short(uint16_t be, uint16_t en, uint32_t c, uint8_t wait){
  for (uint16_t i = be; i < en; i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }

}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256; j++) {
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
    for (int q = 0; q < 3; q++) {
      for (int i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, c);  //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (int i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j = 0; j < 256; j++) {   // cycle all 256 colors in the wheel
    for (int q = 0; q < 3; q++) {
      for (int i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, Wheel( (i + j) % 255)); //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (int i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
      }
    }
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容