Project in progress
Twilight Switch With Levels

Twilight Switch With Levels © CC BY

We will use 4 LEDs, depending on the level of light that we capture with the LDR sensor.

  • 3,810 views
  • 1 comment
  • 11 respects

Components and supplies

About this project

We intend to make a twilight switch with levels, using 4 LEDs, depending on the level of light we capture with the LDR sensor. For the realization of this project, we used a small LDR range, in order to more easily visualize the results (in particular between 600 and 800). These LEDs simulate, for example, lighting of parts of the house or of different devices such as heating, etc.

Code

Code ArduinoArduino
Code Arduino
/*
   Interruptor Crepuscular con distintos niveles:
   Sistema para controlar el encendido de 4 leds
   en funcion de varios intervalos de intensidad luminosa
    LDR pin A0
   LED1 pin 12
   LED2 pin 11
   LED3 pin 10
   LED4 pin 9
      Abril 2018
   Rafael Salvador Jiménez
*/

// variables constantes para los pines
const int ldrPin = A0;    // establece el pin de la LDR
const int ledPin1 = 12; // establece el pin del LED1 rojo
const int ledPin2 = 11; // establece el pin del LED2 rojo
const int ledPin3 = 10; // establece el pin del LED3 rojo
const int ledPin4 = 9; // establece el pin del LED4 rojo

// variables que pueden cambiar
int ldrValue = 0; // variable para almacenar el valor de la LDR
int ldrlevel1=600; // nivel1 de cambio del valor de la LDR
int ldrlevel2=700; // nivel2 de cambio del valor de la LDR
int ldrlevel3=750; // nivel3 de cambio del valor de la LDR
int ldrlevel4=800; // nivel4 de cambio del valor de la LDR

void setup() {
  // establece el LED como una salida
  Serial.begin(9600);    
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
}

void loop() {
  ldrValue = analogRead(ldrPin);  // lee el valor del sensor
  Serial.println(ldrValue);
  // si el valor es menor en cada nivel enciende los LEDs correspondientes
  if (ldrValue < ldrlevel1) {
    digitalWrite(ledPin4, HIGH);
  }
  else if (ldrValue < ldrlevel2) {
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin3, HIGH);
  }
  else if (ldrValue < ldrlevel3) {
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin2, HIGH);
  }
  else if (ldrValue < ldrlevel4) {
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin1, HIGH);
  }
      // sino los apaga
  else {
    digitalWrite(ledPin1, LOW);
      }
   }

Schematics

Schematic Crescent swithc with levels
Miprimerproyecto rafaelsalvadorjimenez bb fmuuff56dy

Comments

Similar projects you might like

Control Your Light Switch with Your Smartphone

Project tutorial by Alasdair Allan

  • 13,535 views
  • 1 comment
  • 33 respects

Switch on the Light - SOL

Project showcase by Akash Ravichandran

  • 2,710 views
  • 3 comments
  • 5 respects

The Troll Switch

Project tutorial by Aitor Gamarra

  • 1,002 views
  • 1 comment
  • 2 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 260,306 views
  • 42 comments
  • 281 respects

How to control your light switch from your smartphone?

Project in progress by Mahmoud Ahmed

  • 22,609 views
  • 3 comments
  • 15 respects

Weather Clock

Project showcase by Tittiamo

  • 7,666 views
  • 7 comments
  • 22 respects
Add projectSign up / Login