Components and supplies
Arduino Nano Every
Rotary potentiometer (generic)
RGB Diffused Common Anode
Breadboard (generic)
Apps and platforms
Arduino IDE
Project description
Code
all code
c_cpp
The potenciometer define the mode, in manual mode you choose manually the color of each led with every potenciometer
1#include <Adafruit_Sensor.h> 2 3#include <DHT.h> 4 5#include <RGBLed.h> 6 7//we initialize the libraries 8 9#define DHTt DHT22 //select the model of DHT 10 int rVal= 254; 11 int gVal= 1; 12 int bVal= 127; 13int rVar= -1; //this is what we gona use on the rainbow 14int gVar= 1; //mode 15int bVar= -1; 16 int rVal1= 127; 17 int gVal1= 254; 18 int bVal1= 1; //LED 2 19int rVar1= -1; 20int gVar1= -1; 21int bVar1= 1; 22const int dPin= 12; 23const int LED = 2; 24const int pot0 = A1; 25const int pot1 = A2; 26const int pot2 = A3; //here we set the pinout 27const int red = 9; 28const int green= 10; 29const int blue= 11; 30const int red1 = 6; 31const int green1 = 5; 32const int blue1 =3; 33RGBLed led(red, green, blue, COMMON_ANODE);//here we set the type 34RGBLed led1(red1, green1, blue1, COMMON_ANODE); // of led 35DHT dht(dPin, DHTt); //set the sensor 36 37void setup() { 38 pinMode (vol, INPUT_PULLUP); 39 pinMode (LED, OUTPUT); 40 pinMode(red, OUTPUT); 41 pinMode(green, OUTPUT); 42 pinMode(blue, OUTPUT); 43 pinMode(red1, OUTPUT); 44 pinMode(green1, OUTPUT);//pinout and Serial for debugging 45 pinMode(blue1, OUTPUT); 46 pinMode(pot0, INPUT); 47 pinMode(pot1, INPUT); 48 pinMode(pot2, INPUT); 49 digitalWrite(LED, HIGH); 50 Serial.begin(9600); 51 dht.begin(); 52 53} 54 55 56//this is to select each mode 57void loop() { 58 int pot0Value = analogRead(pot0); 59 if((pot0Value <= 204)&&(pot0Value>0)){ 60 manual(); 61 } 62 if ((pot0Value>=204)&&(pot0Value<=408)){ 63 rainbow(); 64 } 65 if((pot0Value>=612)&&(pot0Value<=816)){ 66 rgb(); 67 } 68 if((pot0Value>= 816)&&(pot0Value<=950)){ 69 flashy(); 70 } 71 if((pot0Value>=950)&&(pot0Value<=1024)){ 72 vol1(); 73 74 } 75 } 76 77 void vol1() //this is for the weather mode 78 { 79 delay(2000); 80 float hum= dht.readHumidity(); 81 float temp= dht.readTemperature(); 82 Serial.print (hum); 83 Serial.println("%"); 84 Serial.print (temp); 85 Serial.println("C"); 86 hum=map(hum, 20, 80, 255, 0); 87 temp=map(temp,-20, 50, 255, 0);//we map this for the LEDs 88 Serial.print (hum); 89 Serial.println("%"); 90 Serial.print (temp); 91 Serial.println("C"); 92 if(temp > 127 || hum < 127){ 93 rVal = temp / 2; 94 rVal1=temp / 2; 95 gVal= 255; 96 gVal1= 255; // we set the color in hot or dry weather 97 bVal= hum *2; 98 bVal1= hum *2; 99 } 100 if(temp < 127 || hum > 127){ 101 rVal = temp *2; 102 rVal1 = temp *2; 103 gVal= 255; 104 gVal1= 255; //color for wet or cool weather 105 bVal = hum /2; 106 bVal1= hum/2; 107 } 108 analogWrite(red, rVal); 109 analogWrite(green, gVal); 110 analogWrite(blue, bVal); 111 analogWrite(red1, rVal1); //this is at the end of every mode 112 analogWrite(green1, gVal1); 113 analogWrite(blue1, bVal1); 114 } 115 116 void flashy(){ 117 118 led.flash(RGBLed::RED, 100, 20); 119 led1.flash(RGBLed::BLUE, 100, 20); 120 led.flash(RGBLed::BLUE, 100, 20); //here we set the flashy mode 121 led1.flash(RGBLed::RED, 100, 20); //it just flashes 2 colors 122 led1.flash(RGBLed::BLUE, 100, 20);//you can add more colors if you want 123 led1.flash(RGBLed::RED, 100, 20); 124 } 125 126 void rgb(){ 127 128 led.fadeOut(RGBLed::RED, 5, 50); 129 130 led.fadeOut(0, 0, 255, 5, 50); 131 132 led.fadeOut(0, 255,0, 5, 50); 133 134 led.fadeIn(RGBLed::RED, 5, 50); 135 136 led.fadeIn(0, 0, 255, 5, 50); //this makes an LED to go trough 3 color 137 138 led.fadeIn(0, 255,0, 5, 50); //while the other one is off 139 140 led1.fadeOut(RGBLed::RED, 5, 50); 141 142 led1.fadeOut(0, 0, 255, 5, 50); 143 144 led1.fadeOut(0, 255,0, 5, 50); 145 146 led1.fadeIn(RGBLed::RED, 5, 50); 147 148 led1.fadeIn(0, 0, 255, 5, 50); 149 150 led1.fadeIn(0, 255,0, 5, 50); 151 } 152 void rainbow(){ 153 154rVal= rVal + rVar; 155 gVal= gVal + gVar; 156bVal= bVal + bVar; 157 rVal1= rVal1 + rVar1; 158 gVal1= gVal1 + gVar1; 159 bVal1= bVal1 + bVar1; 160 analogWrite(red, rVal); 161 analogWrite(green, gVal); 162 analogWrite(blue, bVal); 163 analogWrite(red1, rVal1); 164 analogWrite(green1, gVal1); 165 analogWrite(blue1, bVal1); //this is for making it go trought the 166 167 168 if(rVal >= 255 || rVal <= 0){//rainbow colors 169 rVar = rVar * -1; 170 } 171 if (gVal >= 255 || gVal <= 0){ 172 gVar = gVar * -1; 173 } 174 if(bVal >= 255 || bVal <= 0){ 175 bVar = bVar * -1; 176 } 177 if(rVal1 >= 255 || rVal1 <= 0){ 178 rVar1 = rVar1 * -1; 179 } 180 if (gVal1 >= 255 || gVal1 <= 0){ 181 gVar1 = gVar1 * -1; 182 } 183 if(bVal1 >= 255 || bVal1 <= 0){ 184 bVar1 = bVar1 * -1; 185 } 186 delay (10); 187 } 188 189 void manual(){ 190 191 int rVal=0; 192 int gVal=0; 193 int bVal=0; 194 int rVal1=0; 195 int gVal1=0; 196 int bVal1=0; 197 int pot1Value = map (analogRead(pot1), 0, 1024, 0, 255); 198 int pot2Value = map (analogRead(pot2), 0, 1024, 0, 255); 199 if (pot1Value <=42){ 200 rVal = 255; 201 gVal = pot1Value * 6; 202 bVal = 0; 203 } 204 if ((pot1Value >42) && (pot1Value <= 85)){//this is for the selection 205 rVal = 255 - (pot1Value - 85) * 6; //of color manually 206 gVal = 255; 207 bVal = 0; 208 } 209 if((pot1Value > 85) && (pot1Value <= 127)){ 210 rVal = 0; 211 gVal = 255; 212 bVal = (pot1Value - 85) * 6; 213 } 214 if((pot1Value >127)&& (pot1Value <= 170)){ 215 rVal = 0; 216 gVal = 255 - (pot1Value - 127) * 6; 217 bVal = 255; 218 } 219 if((pot1Value > 170) && (pot1Value <=212)){ 220 rVal=(pot1Value - 170)*6; 221 gVal=0; 222 bVal= 255; 223 } 224 if ((pot1Value > 212) && (pot1Value <=255)){ 225 rVal=255; 226 gVal= 0; 227 bVal= 255 - (pot1Value - 212) * 6; 228 } 229 if (pot2Value <=42){ 230 rVal1 = 255; 231 gVal1 = pot2Value * 6; 232 bVal1 = 0; 233 } 234 if ((pot2Value >42) && (pot2Value <= 85)){ 235 rVal1 = 255 - (pot2Value - 85) * 6; 236 gVal1 = 255; 237 bVal1 = 0; 238 } 239 if((pot2Value > 85) && (pot2Value <= 127)){ 240 rVal1 = 0; 241 gVal1 = 255; 242 bVal1 = (pot2Value - 85) * 6; 243 } 244 if((pot2Value >127)&& (pot2Value <= 170)){ 245 rVal1 = 0; 246 gVal1 = 255 - (pot2Value - 127) * 6; 247 bVal1 = 255; 248 } 249 if((pot2Value > 170) && (pot2Value <=212)){ 250 rVal1=(pot2Value - 170)*6; 251 gVal1=0; 252 bVal1= 255; 253 } 254 if ((pot2Value > 212) && (pot2Value <=255)){ 255 rVal1=255; 256 gVal1= 0; 257 bVal1= 255 - (pot2Value - 212) * 6; 258 } 259 260 analogWrite(red, rVal); 261 analogWrite(green, gVal); 262 analogWrite(blue, bVal); 263 analogWrite(red1, rVal1); 264 analogWrite(green1, gVal1); 265 analogWrite(blue1, bVal1); 266 Serial.print("the color is"); 267 }
all code
c_cpp
The potenciometer define the mode, in manual mode you choose manually the color of each led with every potenciometer
1#include <Adafruit_Sensor.h> 2 3#include <DHT.h> 4 5#include <RGBLed.h> 6 7//we 8 initialize the libraries 9 10#define DHTt DHT22 //select the model of DHT 11 12 int rVal= 254; 13 int gVal= 1; 14 int bVal= 127; 15int rVar= -1; //this is what 16 we gona use on the rainbow 17int gVar= 1; //mode 18int bVar= -1; 19 int rVal1= 20 127; 21 int gVal1= 254; 22 int bVal1= 1; //LED 2 23int rVar1= -1; 24int gVar1= 25 -1; 26int bVar1= 1; 27const int dPin= 12; 28const int LED = 2; 29const int pot0 30 = A1; 31const int pot1 = A2; 32const int pot2 = A3; //here we set the pinout 33const 34 int red = 9; 35const int green= 10; 36const int blue= 11; 37const int red1 = 38 6; 39const int green1 = 5; 40const int blue1 =3; 41RGBLed led(red, green, blue, 42 COMMON_ANODE);//here we set the type 43RGBLed led1(red1, green1, blue1, COMMON_ANODE); 44 // of led 45DHT dht(dPin, DHTt); //set the sensor 46 47void 48 setup() { 49 pinMode (vol, INPUT_PULLUP); 50 pinMode (LED, OUTPUT); 51 pinMode(red, 52 OUTPUT); 53 pinMode(green, OUTPUT); 54 pinMode(blue, OUTPUT); 55 pinMode(red1, 56 OUTPUT); 57 pinMode(green1, OUTPUT);//pinout and Serial for debugging 58 pinMode(blue1, 59 OUTPUT); 60 pinMode(pot0, INPUT); 61 pinMode(pot1, INPUT); 62 pinMode(pot2, 63 INPUT); 64 digitalWrite(LED, HIGH); 65 Serial.begin(9600); 66 dht.begin(); 67 68} 69 70 71//this 72 is to select each mode 73void loop() { 74 int pot0Value = analogRead(pot0); 75 76 if((pot0Value <= 204)&&(pot0Value>0)){ 77 manual(); 78 } 79 if ((pot0Value>=204)&&(pot0Value<=408)){ 80 81 rainbow(); 82 } 83 if((pot0Value>=612)&&(pot0Value<=816)){ 84 85 rgb(); 86 } 87 if((pot0Value>= 816)&&(pot0Value<=950)){ 88 89 flashy(); 90 } 91 if((pot0Value>=950)&&(pot0Value<=1024)){ 92 93 vol1(); 94 95 } 96 } 97 98 void vol1() 99 //this is for the weather mode 100 { 101 delay(2000); 102 float hum= dht.readHumidity(); 103 104 float temp= dht.readTemperature(); 105 Serial.print (hum); 106 Serial.println("%"); 107 108 Serial.print (temp); 109 Serial.println("C"); 110 hum=map(hum, 20, 80, 111 255, 0); 112 temp=map(temp,-20, 50, 255, 0);//we map this for the LEDs 113 Serial.print 114 (hum); 115 Serial.println("%"); 116 Serial.print (temp); 117 Serial.println("C"); 118 119 if(temp > 127 || hum < 127){ 120 rVal = temp / 2; 121 rVal1=temp / 2; 122 123 gVal= 255; 124 gVal1= 255; // we set the color in hot or dry weather 125 126 bVal= hum *2; 127 bVal1= hum *2; 128 } 129 if(temp < 127 || hum > 127){ 130 131 rVal = temp *2; 132 rVal1 = temp *2; 133 gVal= 255; 134 gVal1= 135 255; //color for wet or cool weather 136 bVal = hum /2; 137 bVal1= hum/2; 138 139 } 140 analogWrite(red, rVal); 141 analogWrite(green, gVal); 142 analogWrite(blue, 143 bVal); 144 analogWrite(red1, rVal1); //this is at the end of every mode 145 analogWrite(green1, 146 gVal1); 147 analogWrite(blue1, bVal1); 148 } 149 150 void flashy(){ 151 152 led.flash(RGBLed::RED, 153 100, 20); 154 led1.flash(RGBLed::BLUE, 100, 20); 155 led.flash(RGBLed::BLUE, 100, 156 20); //here we set the flashy mode 157 led1.flash(RGBLed::RED, 100, 20); //it just 158 flashes 2 colors 159 led1.flash(RGBLed::BLUE, 100, 20);//you can add more colors 160 if you want 161 led1.flash(RGBLed::RED, 100, 20); 162 } 163 164 void rgb(){ 165 166 167 led.fadeOut(RGBLed::RED, 5, 50); 168 169 led.fadeOut(0, 0, 255, 5, 50); 170 171 172 led.fadeOut(0, 255,0, 5, 50); 173 174 led.fadeIn(RGBLed::RED, 5, 50); 175 176 177 led.fadeIn(0, 0, 255, 5, 50); //this makes an LED to go trough 3 color 178 179 180 led.fadeIn(0, 255,0, 5, 50); //while the other one is off 181 182 led1.fadeOut(RGBLed::RED, 183 5, 50); 184 185 led1.fadeOut(0, 0, 255, 5, 50); 186 187 led1.fadeOut(0, 255,0, 188 5, 50); 189 190 led1.fadeIn(RGBLed::RED, 5, 50); 191 192 led1.fadeIn(0, 0, 193 255, 5, 50); 194 195 led1.fadeIn(0, 255,0, 5, 50); 196 } 197 void rainbow(){ 198 199 200rVal= rVal + rVar; 201 gVal= gVal + gVar; 202bVal= bVal + bVar; 203 rVal1= 204 rVal1 + rVar1; 205 gVal1= gVal1 + gVar1; 206 bVal1= bVal1 + bVar1; 207 analogWrite(red, 208 rVal); 209 analogWrite(green, gVal); 210 analogWrite(blue, bVal); 211 analogWrite(red1, 212 rVal1); 213 analogWrite(green1, gVal1); 214 analogWrite(blue1, bVal1); //this is 215 for making it go trought the 216 217 218 if(rVal >= 255 || rVal <= 0){//rainbow 219 colors 220 rVar = rVar * -1; 221 } 222 if (gVal >= 255 || gVal <= 0){ 223 gVar 224 = gVar * -1; 225 } 226 if(bVal >= 255 || bVal <= 0){ 227 bVar = bVar * -1; 228 229 } 230 if(rVal1 >= 255 || rVal1 <= 0){ 231 rVar1 = rVar1 * -1; 232 } 233 if 234 (gVal1 >= 255 || gVal1 <= 0){ 235 gVar1 = gVar1 * -1; 236 } 237 if(bVal1 >= 255 238 || bVal1 <= 0){ 239 bVar1 = bVar1 * -1; 240 } 241 delay (10); 242 } 243 244 245 void manual(){ 246 247 int rVal=0; 248 int gVal=0; 249 int bVal=0; 250 int rVal1=0; 251 252 int gVal1=0; 253 int bVal1=0; 254 int pot1Value = map (analogRead(pot1), 0, 1024, 255 0, 255); 256 int pot2Value = map (analogRead(pot2), 0, 1024, 0, 255); 257 if (pot1Value 258 <=42){ 259 rVal = 255; 260 gVal = pot1Value * 6; 261 bVal = 0; 262 } 263 264 if ((pot1Value >42) && (pot1Value <= 85)){//this is for the selection 265 266 rVal = 255 - (pot1Value - 85) * 6; //of color manually 267 gVal = 268 255; 269 bVal = 0; 270 } 271 if((pot1Value > 85) && (pot1Value <= 272 127)){ 273 rVal = 0; 274 gVal = 255; 275 bVal = (pot1Value 276 - 85) * 6; 277 } 278 if((pot1Value >127)&& (pot1Value <= 170)){ 279 280 rVal = 0; 281 gVal = 255 - (pot1Value - 127) * 6; 282 bVal 283 = 255; 284 } 285 if((pot1Value > 170) && (pot1Value <=212)){ 286 287 rVal=(pot1Value - 170)*6; 288 gVal=0; 289 bVal= 290 255; 291 } 292 if ((pot1Value > 212) && (pot1Value <=255)){ 293 294 rVal=255; 295 gVal= 0; 296 bVal= 255 - (pot1Value 297 - 212) * 6; 298 } 299 if (pot2Value <=42){ 300 rVal1 = 255; 301 302 gVal1 = pot2Value * 6; 303 bVal1 = 0; 304 } 305 if ((pot2Value >42) 306 && (pot2Value <= 85)){ 307 rVal1 = 255 - (pot2Value - 85) * 6; 308 gVal1 309 = 255; 310 bVal1 = 0; 311 } 312 if((pot2Value > 85) && (pot2Value 313 <= 127)){ 314 rVal1 = 0; 315 gVal1 = 255; 316 bVal1 = (pot2Value 317 - 85) * 6; 318 } 319 if((pot2Value >127)&& (pot2Value <= 170)){ 320 321 rVal1 = 0; 322 gVal1 = 255 - (pot2Value - 127) * 6; 323 bVal1 324 = 255; 325 } 326 if((pot2Value > 170) && (pot2Value <=212)){ 327 328 rVal1=(pot2Value - 170)*6; 329 gVal1=0; 330 bVal1= 331 255; 332 } 333 if ((pot2Value > 212) && (pot2Value <=255)){ 334 335 rVal1=255; 336 gVal1= 0; 337 bVal1= 255 338 - (pot2Value - 212) * 6; 339 } 340 341 analogWrite(red, rVal); 342 343 analogWrite(green, gVal); 344 analogWrite(blue, bVal); 345 analogWrite(red1, 346 rVal1); 347 analogWrite(green1, gVal1); 348 analogWrite(blue1, bVal1); 349 Serial.print("the 350 color is"); 351 }
Downloadable files
Squeme
RED -> VCC BLACK -> GNG Others -> signal in/out
Squeme
Comments
Only logged in users can leave comments
lebo
0 Followers
•0 Projects
Table of contents
Intro
5
0