Ahmed AldarwishFarouq Alsaihati
Published

Sunlight sensor - MEGR 3171 - Fall 2017

This project help you safe electricity. it will turn off the lights for you during the daylight in anyplace of the house you want.

BeginnerWork in progress3 hours643
Sunlight sensor - MEGR 3171 - Fall 2017

Things used in this project

Hardware components

Photo resistor
Photo resistor
×1
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×1
RobotGeek 180 Degree Robot Servo
RobotGeek 180 Degree Robot Servo
×1
3m tape
×1
Photon
Particle Photon
×2

Story

Read more

Schematics

Servo

Photo Resistor

Code

Servo

C/C++
This code accepts the event "light_output69" and actuates the servo to turn the light switch off.
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

void setup()
{
  myservo.attach(D0);  // attaches the servo on the D0 pin to the servo object
  // Only supported on pins that have PWM
myservo.write(10);
}

void loop()
{
Particle.subscribe("light_output69", lightsOut);
  // Subscribe will listen for the event buddy_unique_event_name and, when it finds it, will run the function
  delay(1000);
}

void lightsOut(const char *event, const char *data)
{
  /* Particle.subscribe handlers are void functions, which means they don't return anything.
  They take two variables-- the name of your event, and any data that goes along with your event. */
  
   if (strcmp(data,"on")==0) {
    // if your buddy's beam is intact, then turn your board LED off and move servo to 180 degrees
    myservo.write(33); 
    delay(1000);
    myservo.write(10); 
  }
 
}

Photo Resistor

C/C++
This code detects light and sends out the event "light_output69".
int light = A0;

int power = A5;

int noLightThreshold = 300;

int analogvalue;


void setup() {
    
    pinMode(light,INPUT);
    
    pinMode(power,OUTPUT); 
    
    digitalWrite(power,HIGH);

}

void loop() {
    
    analogvalue = analogRead(light);
    
    Particle.variable("analogvalue", &analogvalue, INT);
    
    if(analogRead(light) < noLightThreshold){
        Particle.publish("light_output69","off");
    }
    else{
        Particle.publish("light_output69","on");
    }
    delay(1000);

}

Credits

Ahmed Aldarwish

Ahmed Aldarwish

1 project • 0 followers
Farouq Alsaihati

Farouq Alsaihati

1 project • 0 followers

Comments

Add projectSign up / Login