Skills Dev2 : Rahul Jha

Made by Rahul Jha

simple 2-in (sensors or inputs) 1-out (LED) device - representing automatic lights on/off system based on the natural light intensity in a room

Created: November 24th, 2021

0

Outcome

    • simple 2-inputs (sensors or inputs) 1-output (LED) device - representing automatic lights on/off (and dimming) system based on the natural light intensity in a room
    • Inputs: Photosensor (photo-resistor), Toggle Switch
    • Output: Led
    • Overall idea: to implement an automatic light on/off system using natural light intensity. Here the photosensor will sense the intensity of natural light in the room. As the intensity of natural light changes, the LED output intensity will change. The master toggle switch will provide overall control of the system. It provides an option to keep the system automatic or manual. When the toggle switch is ON, then only, output LED can be controlled using this system.  
0

Process

1. Initially connected an LED to the argon board and connected it at D2 pin.

2. Next wired photo sensor on the board using a pull-down resistor of 10 K ohm and connected it to A4 pin.

3. Developed the sketch (program ) to simply control the LED intensity with the corresponding change in the intensity of light falling on the photosensor.

4. Shared the value of photosensor online using 'particle.variable'.

0

Code for : photo-resistor as sensor input and LED as output

0
int ledPin = D2;

int photoresPin = A4;
int photoresRead = 0;

void setup() {
    
    //Set the LED as Output
    pinMode(ledPin, OUTPUT);
    
   
    
    Particle.variable("photoResValue", photoresRead);
    
}

void loop() {
    
    //0-4095
    photoresRead = analogRead(photoresPin);
    
    //using map function to convert the range
    int brightness = map(photoresRead, 0 , 4095, 0, 255 );
    
    analogWrite( ledPin, brightness );
    
    delay(200);
    
 }
Click to Expand
0

Link for youtube video (photo-resistor as sensor input and LED as output):

https://youtu.be/kbJwn5DyKzE

0
SkellDev2-1
rahuljha89 - https://youtu.be/kbJwn5DyKzE
0
5.  Added third component - toggle switch to the circuit. It controls the overall functionality, that is when the switch is ON then only, LED can be switched ON. Aalso published the switch ON/OFF events on the particle cloud.
0

Code after adding second input - toggle switch:

0
int ledPin = D2;
int switchPin = D4;
int switchState; //store the reading from the button 
int switchState_prev = LOW;

int photoresPin = A4;
int photoresRead = 0;

void setup() {
    
    //Set the LED as Output
    pinMode(ledPin, OUTPUT);
    
    //Set the switch as input
    pinMode (switchPin, INPUT_PULLUP); 
    
    Particle.variable("photoResValue", photoresRead);
    
}

void loop() {
    
    switchState = digitalRead( switchPin );
    
    
    if(switchState == HIGH){
        
        
        // added the below code to make sure publish happens only when..
        // switch state changes from previous state
        if (switchState != switchState_prev){
            Particle.publish( "Switch ON" );
        }
        switchState_prev = switchState;
        
        //0-4095
         photoresRead = analogRead(photoresPin);
    
        //using map function to convert the range
        int brightness = map(photoresRead, 0 , 4095, 0, 255 );
    
        analogWrite( ledPin, brightness );
    
        delay(200);
    
    }else{
        
        if (switchState != switchState_prev){
             Particle.publish( "Switch OFF" );
        }
        switchState_prev = switchState;
        
        
        int brightness = 0;
        analogWrite( ledPin, brightness );
        
    }

}
Click to Expand
0

Link for youtube video (after adding third component: second input - toggle switch):
https://youtu.be/Ky0jvFmMy0k


0
SkillDev2-2
rahuljha89 - https://youtu.be/Ky0jvFmMy0k
0

Reflection

  1. While doing this skill development, I learned about different sensors by reading through the available material. It gave me an opportunity to implement a sensor on a real circuit and control the behavior of output. This was an amazing experience for me.
  2. Another achievement was to publish the events and values on the cloud. 
  3. I learned about the pull-down resistor and how to design circuits for analog inputs. like photo-resistor.
  4. I had trouble synchronizing the intensity change in photocell to the corresponding intensity of LED light as a viewable (tangible) component. So I had to change the delay (milliseconds) in the code and come up with the appropriate value (200ms) that can allow to see the visible change.
  5. Right now, the photoresistor values and LED output are directly proportional. I would like to change this situation to inversely proportional. That is when the intensity of light on the photoresistor reduces then the LED should glow more, and vice-versa. This will represent an actual scenario of automatic light ON/OFF system in a room. 


x
Share this Project

Courses

About

simple 2-in (sensors or inputs) 1-out (LED) device - representing automatic lights on/off system based on the natural light intensity in a room