Arduino Lichtkontrolle

Im folgenden Projekt wird ein Arduino Nano zur Einschaltkontrolle des Hoflichts verwendet. Ausserdem gibt es noch eine Timerschaltung um ein LED-Stripe für 30sek einzuschalten. – Per Sensorschalter.

Bei  Google Chrome kann es Probleme mit der Bilddarstellung geben !

Die LED in Funktion.

Eingebaut in einen Kontrolltaster der Fa. Kopp.

 

Wird das Hoflicht eingeschaltet, wird dem Arduino über einen Optokoppler der Status ON mitgeteilt. Dieser schaltet dann das „GLT“ Relais und die RGB LED ein. Die LED ist im Taster eingebaut.

Projektbilder und downloads sind am Ende der Seite

 

Der Programmcode.

LDR02 und LDR03 sind für weitere Anwendungen vorgesehen.

Hoflicht AN (LDR01) = Relais 2 ON –> Meldung an GLT

Timer AN = Relais 1 ON –> Meldung an GLT, Relais 4 ON –> LDR Stripe ON



/*
    Blink RGB LED if LDR01 is "on"
    Power on LED-Stripe (relay 4) for 30s if input buttonpin2 is triggered
    LDR 2 for future use
    LDR 3 Daylight indicator
    
    output 6-12 = D6-D12

  v. 1.0 25.12.2017 JH


*/
// RGB LED has Common Anode !
// constants won't change. Used here to set a pin number :
const int ledPin0 = 12;         // RED	the number of the LED pin
const int ledPin1 = 11;		// GREEN
const int ledPin2 = 10;		// BLUE

const int RelPin1 = 9;    // Timer output              --> I/O (glt) Control
const int RelPin2 = 8;    // LDR 01 (RGB-LED)-ON       --> I/O (glt) Control
const int RelPin3 = 7;    // LDR 02 ON                 --> I/O (glt) Control
const int RelPin4 = 6;    // Timer output LED stripe ON/OFF

const int buttonPin1 = A0;		// switch for LED (LDR 01)
const int buttonPin2 = A3;  // switch for 30s timer
const int buttonPin3 = A4;   //  LDR 02
const int buttonPin4 = A5;   //  LDR 03

// Variables will change :
int ledState = LOW;             // ledState used to set the LED
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int timervbl = 0;
int LightOn_StartMillis;
int currentLightOnTime = 0;
int isLightOn = LOW;


// Generally, you should use "unsigned long" for variables that hold time
//
unsigned long previousMillis = 0;        // will store last time LED was updated


// constants won't change :
const long interval = 600;           // interval at which to blink (milliseconds)
int lednr = 0;
int LIGHT_ON_TIME = 30000;          // LED on time = 30s
int ldr_on = 200;                   // threshold for LDR -> LED on -- LDR dark = 60-90, light=> 250

void setup() {
  // set the digital pin as output:
  pinMode(ledPin0, OUTPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(RelPin1, OUTPUT);
  pinMode(RelPin2, OUTPUT);
  pinMode(RelPin3, OUTPUT);
  pinMode(RelPin4, OUTPUT);
  randomSeed(analogRead(0));
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  
// 4-Relay Module HIGH = Relais off, LOW = Relais ON
  
  digitalWrite(RelPin1, HIGH);
  digitalWrite(RelPin2, HIGH);
  digitalWrite(RelPin3, HIGH);
  digitalWrite(RelPin4, HIGH);
  Serial.begin(9600);
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

  unsigned long currentMillis = millis();

  // Button -> LDR 01

 // Button RGB-LED on -> LDR 01

  buttonState1 = analogRead(buttonPin1);

  //Serial.println(buttonState1);


  //-----------------------------------------------------------------

  // Button -> LDR 02
  //buttonState3 = digitalRead(buttonPin3);
  
  buttonState3 = analogRead(buttonPin3);

  // Button -> LDR 03
  
  buttonState4 = analogRead(buttonPin4);

  //-----------------------------------------------------------------
  // Button 2 time switch 30s on
  buttonState2 = digitalRead(buttonPin2);

  //Serial.println(buttonState2);

  if (buttonState2 == HIGH) {
    digitalWrite(RelPin1, LOW);
    digitalWrite(RelPin4, LOW);
    LightOn_StartMillis = millis();
    currentLightOnTime = 0;
    isLightOn = HIGH;

  } else {

    if (isLightOn == HIGH) {
      currentLightOnTime = millis() - LightOn_StartMillis;
      if (currentLightOnTime > LIGHT_ON_TIME) {
            digitalWrite(RelPin1, HIGH);
            digitalWrite(RelPin4, HIGH);
        isLightOn = LOW;
        //
      }
    }

  }
  //----------------- LDR 01 ------------------------------------------------

  // RGB-LED --> read LDR 01
  
  if (buttonState1 >= ldr_on) {
    if (currentMillis - previousMillis >= interval) {
      // save the last time you blinked the LED
      previousMillis = currentMillis;

      digitalWrite(RelPin2, LOW);

      // set the LED with the ledState of the variable: 0=red, 1=green, 2=blue
      switch (lednr) {
        case 0:
          // RED
          digitalWrite(ledPin0, LOW);
          digitalWrite(ledPin1, HIGH);
          digitalWrite(ledPin2, HIGH);
          break;
        case 2:
          // GREEN
          digitalWrite(ledPin1, LOW);
          digitalWrite(ledPin0, HIGH);
          digitalWrite(ledPin2, HIGH);
          break;
        case 4:
          // BLUE
          digitalWrite(ledPin2, LOW);
          digitalWrite(ledPin1, HIGH);
          digitalWrite(ledPin0, HIGH);
          break;
        case 6:
          // RED+BLUE = Magenta
          digitalWrite(ledPin2, HIGH);
          digitalWrite(ledPin1, LOW);
          digitalWrite(ledPin0, HIGH);
          break;
        case 8:
          // RED+GREEN = Yellow
          digitalWrite(ledPin2, LOW);
          digitalWrite(ledPin1, HIGH);
          digitalWrite(ledPin0, HIGH);
          break;
        case 10:
          // RED+GREEN+BLUE = white
          digitalWrite(ledPin2, LOW);
          digitalWrite(ledPin1, LOW);
          digitalWrite(ledPin0, LOW);
          break;

        default:
          digitalWrite(ledPin0, HIGH);
          digitalWrite(ledPin1, HIGH);
          digitalWrite(ledPin2, HIGH);
          delay(200);

      } // switch(lednr)

      //lednr = random(5);
      lednr++;
      if (lednr == 12) {
        lednr = 0;
      }

    } //if (currentMillis - previousMillis >= interval)

  } else {
    digitalWrite(RelPin2, HIGH);
    digitalWrite(ledPin0, HIGH);
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, HIGH);
  } // if (buttonState1 <= ldr_on) {


 //----------------- LDR 02 ------------------------------------------------
  
  if (buttonState3 <= ldr_on) {
      digitalWrite(RelPin3, HIGH);
  } else {
      digitalWrite(RelPin3, LOW);
  }

      
} // void(loop)

 

Download vom ino File: ino File fuer Arduino

Download Schaltplaene : Schaltplaene des Projektes

 

……….. Fortsetzung folgt  😎 

 

 

Sensorschalter Schaltplan
Hoflicht Kontrolle Schaltplan
Optokoppler 230 V
Hoflicht Kontrolle GLT