Project showcase
Lightning Cloud

Lightning Cloud © CC BY

It has some LEDs inside something that refracts.

  • 500 views
  • 1 comment
  • 2 respects

Components and supplies

Apps and online services

About this project

I saw on reddit something similar and I thought that could be cool to make it and share how I made it.

Code

all codeC/C++
The potenciometer define the mode, in manual mode you choose manually the color of each led with every potenciometer
#include <Adafruit_Sensor.h>

#include <DHT.h>

#include <RGBLed.h>

//we initialize the libraries

#define DHTt DHT22 //select the model of DHT
 int rVal= 254;
 int gVal= 1;
 int bVal= 127;
int rVar= -1; //this is what we gona use on the rainbow
int gVar= 1; //mode
int bVar= -1;
 int rVal1= 127;
 int gVal1= 254; 
 int bVal1= 1; //LED 2
int rVar1= -1;
int gVar1= -1;
int bVar1= 1;
const int dPin= 12;
const int LED = 2;
const int pot0 = A1;
const int pot1 = A2;
const int pot2 = A3; //here we set the pinout
const int red = 9;
const int green= 10;
const int blue= 11;
const int red1 = 6;
const int green1 = 5;
const int blue1 =3;
RGBLed led(red, green, blue, COMMON_ANODE);//here we set the type
RGBLed led1(red1, green1, blue1, COMMON_ANODE); // of led
DHT dht(dPin, DHTt);  //set the sensor                          

void setup() {
  pinMode (vol, INPUT_PULLUP);
  pinMode (LED, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(red1, OUTPUT);
  pinMode(green1, OUTPUT);//pinout and Serial for debugging
  pinMode(blue1, OUTPUT);
  pinMode(pot0, INPUT);
  pinMode(pot1, INPUT);
  pinMode(pot2, INPUT);
  digitalWrite(LED, HIGH);
  Serial.begin(9600);
  dht.begin();

}


//this is to select each mode
void loop() { 
  int pot0Value = analogRead(pot0);
  if((pot0Value <= 204)&&(pot0Value>0)){
    manual();
    }
    if ((pot0Value>=204)&&(pot0Value<=408)){
      rainbow();
      }
      if((pot0Value>=612)&&(pot0Value<=816)){
        rgb();
        }
        if((pot0Value>= 816)&&(pot0Value<=950)){
          flashy();
          }
          if((pot0Value>=950)&&(pot0Value<=1024)){
            vol1();
            
            }
  }

  void vol1() //this is for the weather mode
  {
   delay(2000);
   float hum= dht.readHumidity();
   float temp= dht.readTemperature();
   Serial.print (hum);
   Serial.println("%");
   Serial.print (temp);
   Serial.println("C");
   hum=map(hum, 20, 80, 255, 0);
   temp=map(temp,-20, 50, 255, 0);//we map this for the LEDs
   Serial.print (hum);
   Serial.println("%");
   Serial.print (temp);
   Serial.println("C");
   if(temp > 127 || hum < 127){
    rVal = temp / 2;
    rVal1=temp / 2;
    gVal= 255;
    gVal1= 255; // we set the color in hot or dry weather
    bVal= hum *2;
    bVal1= hum *2;
    }
    if(temp < 127 || hum > 127){
      rVal = temp *2;
      rVal1 = temp *2;
      gVal= 255;
      gVal1= 255; //color for wet or cool weather
      bVal = hum /2;
      bVal1= hum/2;
      }
 analogWrite(red, rVal);
 analogWrite(green, gVal);
 analogWrite(blue, bVal);
 analogWrite(red1, rVal1); //this is at the end of every mode
 analogWrite(green1, gVal1);
 analogWrite(blue1, bVal1);
  }

 void flashy(){

  led.flash(RGBLed::RED, 100, 20);
  led1.flash(RGBLed::BLUE, 100, 20);
  led.flash(RGBLed::BLUE, 100, 20); //here we set the flashy mode
  led1.flash(RGBLed::RED, 100, 20); //it just flashes 2 colors
  led1.flash(RGBLed::BLUE, 100, 20);//you can add more colors if you want
  led1.flash(RGBLed::RED, 100, 20);
  }
  
  void rgb(){
 
    led.fadeOut(RGBLed::RED, 5, 50);

    led.fadeOut(0, 0, 255, 5, 50);

    led.fadeOut(0, 255,0, 5, 50);

    led.fadeIn(RGBLed::RED, 5, 50);

    led.fadeIn(0, 0, 255, 5, 50); //this makes an LED to go trough 3 color
 
    led.fadeIn(0, 255,0, 5, 50); //while the other one is off

    led1.fadeOut(RGBLed::RED, 5, 50);

    led1.fadeOut(0, 0, 255, 5, 50);

    led1.fadeOut(0, 255,0, 5, 50);

    led1.fadeIn(RGBLed::RED, 5, 50);

    led1.fadeIn(0, 0, 255, 5, 50);

    led1.fadeIn(0, 255,0, 5, 50);
    }
  void rainbow(){
      
rVal= rVal + rVar;
 gVal= gVal + gVar;
bVal= bVal + bVar;
 rVal1= rVal1 + rVar1;
 gVal1= gVal1 + gVar1;
 bVal1= bVal1 + bVar1;
 analogWrite(red, rVal);
 analogWrite(green, gVal);
 analogWrite(blue, bVal);
 analogWrite(red1, rVal1);
 analogWrite(green1, gVal1);
 analogWrite(blue1, bVal1); //this is for making it go trought the

 
 if(rVal >= 255 || rVal <= 0){//rainbow colors
  rVar = rVar * -1;
  }
 if (gVal >= 255 || gVal <= 0){
  gVar = gVar * -1;
  } 
 if(bVal >= 255 || bVal <= 0){
  bVar = bVar * -1;
  } 
  if(rVal1 >= 255 || rVal1 <= 0){
  rVar1 = rVar1 * -1;
  }
 if (gVal1 >= 255 || gVal1 <= 0){
  gVar1 = gVar1 * -1;
  } 
 if(bVal1 >= 255 || bVal1 <= 0){
  bVar1 = bVar1 * -1;
  }
 delay (10);
    }
  
  void manual(){

 int rVal=0;
 int gVal=0;
 int bVal=0;
 int rVal1=0;
 int gVal1=0;
 int bVal1=0;
  int pot1Value = map (analogRead(pot1), 0, 1024, 0, 255);
  int pot2Value = map (analogRead(pot2), 0, 1024, 0, 255);
  if (pot1Value <=42){
    rVal = 255;
    gVal = pot1Value * 6;
    bVal = 0;
    } 
    if ((pot1Value >42) && (pot1Value <= 85)){//this is for the selection
      rVal = 255 - (pot1Value - 85) * 6;    //of color manually
      gVal = 255;
      bVal = 0;
      }
      if((pot1Value > 85) && (pot1Value <= 127)){
        rVal = 0;
        gVal = 255;
        bVal = (pot1Value - 85) * 6;
        }
        if((pot1Value >127)&& (pot1Value <= 170)){
          rVal = 0;
          gVal = 255 - (pot1Value - 127) * 6;
          bVal = 255;
          }
          if((pot1Value > 170) && (pot1Value <=212)){
            rVal=(pot1Value - 170)*6;
            gVal=0;
            bVal= 255;
            }
            if ((pot1Value > 212) && (pot1Value <=255)){
              rVal=255;
              gVal= 0;
              bVal= 255 - (pot1Value - 212) * 6;
              }
 if (pot2Value <=42){
    rVal1 = 255;
    gVal1 = pot2Value * 6;
    bVal1 = 0;
    } 
    if ((pot2Value >42) && (pot2Value <= 85)){
      rVal1 = 255 - (pot2Value - 85) * 6;
      gVal1 = 255;
      bVal1 = 0;
      }
      if((pot2Value > 85) && (pot2Value <= 127)){
        rVal1 = 0;
        gVal1 = 255;
        bVal1 = (pot2Value - 85) * 6;
        }
        if((pot2Value >127)&& (pot2Value <= 170)){
          rVal1 = 0;
          gVal1 = 255 - (pot2Value - 127) * 6;
          bVal1 = 255;
          }
          if((pot2Value > 170) && (pot2Value <=212)){
            rVal1=(pot2Value - 170)*6;
            gVal1=0;
            bVal1= 255;
            }
            if ((pot2Value > 212) && (pot2Value <=255)){
              rVal1=255;
              gVal1= 0;
              bVal1= 255 - (pot2Value - 212) * 6;
              }
   
  analogWrite(red, rVal);
  analogWrite(green, gVal);
  analogWrite(blue, bVal);
  analogWrite(red1, rVal1);
  analogWrite(green1, gVal1);
  analogWrite(blue1, bVal1);
  Serial.print("the color is");
    }

Schematics

Squeme
RED -> VCC
BLACK -> GNG
Others -> signal in/out
untitled_sketch_lzKUeLWMEG.fzz

Comments

Similar projects you might like

Leduindo - Smart Led Bike Lightning

Project tutorial by Marius Dima

  • 5,139 views
  • 1 comment
  • 20 respects

Both Physical & Cloud Cayenne Lights Switch

Project showcase by Laurence Daxes

  • 1,053 views
  • 0 comments
  • 5 respects

IoT Command Center - Using Samsung ARTIK Cloud

Project in progress by CJA3D

  • 3,900 views
  • 1 comment
  • 23 respects

IoT Cloud - Getting Started

by 5 developers

  • 43,728 views
  • 17 comments
  • 97 respects

Soil Control Grid: From The Ground To The Cloud

Project tutorial by Andrea De Gaetano

  • 2,154 views
  • 4 comments
  • 13 respects

Send Tweets Using Arduino with Artik Cloud

Project tutorial by Jasper

  • 1,837 views
  • 0 comments
  • 9 respects
Add projectSign up / Login