Brandon PantasJesse WilliamsJohn R McAlpine V Mac
Published

Pointless Light Switch

The newest innovation in oppressive light control!

BeginnerWork in progress1,026

Things used in this project

Hardware components

Photon
Particle Photon
×2
Photo resistor
Photo resistor
×1
Resistor 22.1 ohm
Resistor 22.1 ohm
×1
Servos (Tower Pro MG996R)
×1

Story

Read more

Schematics

Light Detector

Servo Control

Code

Servo Controls

Plain text
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(180); 
    delay(1000);
    myservo.write(10); 
  }
 
}

Light Detector

Plain text
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

Brandon Pantas

Brandon Pantas

1 project • 0 followers
Jesse Williams

Jesse Williams

1 project • 0 followers
John R McAlpine V Mac

John R McAlpine V Mac

12 projects • 49 followers
www.MACSBOOST.com Assistant Teaching Professor at UNC Charlotte MEGR3171 Instrumentation, Motorsports Research

Comments