Smart RGB Lempa


#1

Fab Lab sukūrėme Smart Lempa. Lempa, kuri suplojus įsijungia ir išsijungia, taip pat ji reaguoja į temperatūrą. Galima keisti šviesas ir jų mirksėjimo dažnį. Pradinis sumanymas buvo sukurti į plojimą reaguojančią lempą ir mums tai pavyko.

Komponentų sąrašas:
Arduino Pro micro
Temperatūros jutiklis
Mikrofonas
Breadboard
RGB led
Potenciometras B20K
Rezistoriai 330kOmh
Laidai
Fanera lempos korpusui
Pleksiglasas lempos šviečiančiai daliai

Pirmiausia susiprojektavau lempos korpusą, štai pjovimo failas:
lempos%20korpusas

Tada sujungiau visus gautus komponentus su Breadboard:

Tuomet parašiau Arduino programą:

#include "dht.h"
#define dht_apin A1 // Analog Pin sensor is connected to
 
dht DHT;

boolean turnedOn = false;

    void setup(){
 
  Serial.begin(9600);
  delay(500);//Delay to let system boot
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");
  delay(1000);//Wait before accessing Sensor

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, INPUT);
 
}
 
void loop(){
    int sensor = analogRead(A2);
    
    DHT.read11(dht_apin);
    
    Serial.print("Current humidity = ");
    Serial.print(DHT.humidity);
    Serial.print("%  ");
    Serial.print("temperature = ");
    Serial.print(DHT.temperature); 
    Serial.println("C  ");
    Serial.println(sensor);
    delay(10);

    boolean val = digitalRead(5);
    Serial.println (val);
    // when the sensor detects a signal above the threshold value, LED flashes
    if (val==HIGH) {
      turnedOn = !turnedOn;
    }
    if (turnedOn == true) {
      if(sensor <= 341 && DHT.temperature < 31) {
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, LOW);
      }
      if(sensor <= 341 && DHT.temperature > 29) {
        digitalWrite(2, LOW);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH); 
      }
      if(sensor <= 341 && DHT.temperature >= 29 && DHT.temperature <= 31) {
        digitalWrite(2, HIGH);
        digitalWrite(3, LOW);    
        digitalWrite(4, HIGH);
      }
      if(sensor > 341 && sensor <= 682 && DHT.temperature < 31) {
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, LOW);
        delay(500);
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH);
        delay(500); 
      }
      if(sensor > 341 && sensor <= 682 && DHT.temperature > 29) {
        digitalWrite(2, LOW);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH); 
        delay(500);
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH); 
        delay(500);
      }
      if(sensor > 341 && sensor <= 682 && DHT.temperature >= 29 && DHT.temperature <= 31) {
        digitalWrite(2, HIGH);
        digitalWrite(3, LOW);    
        digitalWrite(4, HIGH);
        delay(500);
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH);
        delay(500); 
      }
      if(sensor > 682 && sensor < 1023 && DHT.temperature > 31) {
        digitalWrite(2, LOW);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH); 
        delay(100);
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH); 
        delay(100);
      }
      if(sensor > 682 && sensor < 1023 && DHT.temperature < 29) {
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, LOW);
        delay(100);
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH);
        delay(100);
      }
       if(sensor > 682 && sensor < 1023 && DHT.temperature >= 29 && DHT.temperature <= 31) {
        digitalWrite(2, HIGH);
        digitalWrite(3, LOW);    
        digitalWrite(4, HIGH);
        delay(100);
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH);
        delay(100);
      }
      if(sensor >= 1023 && DHT.temperature > 31) {
        digitalWrite(2, LOW);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH); 
        delay(50);
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH); 
        delay(50);
      }
      if(sensor >= 1023 && DHT.temperature < 29) {
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, LOW);
        delay(50);
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH);
        delay(50);
      }
      if(sensor >= 1023 && DHT.temperature >= 29 && DHT.temperature <= 31) {
        digitalWrite(2, HIGH);
        digitalWrite(3, LOW);    
        digitalWrite(4, HIGH);
        delay(50);
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH);
        delay(50);
      }
   }
    if (turnedOn == false) {
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);    
        digitalWrite(4, HIGH);
   }
}

Ir štai galutinis produktas:


Konkursas #2019 - Mokyklos Maker Faire