John RussellNicholas Hanna
Published © GPL3+

MEGR 3171 Photon Controlled Switch - Spring 2019

We used a Particle Photon to control a linear servo motor to control a light switch.

BeginnerFull instructions provided1 hour1,979
MEGR 3171 Photon Controlled Switch - Spring 2019

Things used in this project

Hardware components

Photon
Particle Photon
×2
L12-R Micro Linear Servo
×1
Command Strips
×2
Jumper wires (generic)
Jumper wires (generic)
×5
Metal Wire
About 4 inches in length. 28 gauge galvanized steel wire was used for this project. Material does not matter as long as it's not too brittle.
×1
Particle Phototransistor
×1

Software apps and online services

Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Story

Read more

Schematics

Light Factor Graph

This graph was made by turning the lights on and off for a period of 20 minutes. The light factor is a value that when is over 10, will activate the servo motor. The data was sent to a Google sheet document via IFTTT.

Photo Transistor Circuit

Servo Motor Circuit

There was no linear servo motor in Fritzing, but a regular one was used and has the same connections.

Code

Photo Transistor Code

C/C++
int phototransistor = A0;
int analogValue;

void setup() {
pinMode(phototransistor, INPUT);
Particle.variable("analogValue",&analogValue, INT);
}

void loop() {
analogValue = analogRead(phototransistor);
 
if(analogValue>10) {
   delay(10000);
    Particle.publish("lighton","light is on",PUBLIC);

}
}

Servo Motor Photon Code

C/C++
Servo LinAct;  // create servo object to control a servo

int pos = 0;    // variable to store the servo position

void setup()
{
    Particle.subscribe("lighton", lighton, "3d0020000f51373331333230"); // subscribing to the published event from the phototransistor photon
    Particle.function("MEGR3171G12linearservo", light);  // function can be called from the cloud

    LinAct.attach(D0);   // attach the servo on the D0 pin to the servo object
    LinAct.write(55);    // testing servo
}

void lighton(const char *event, const char *data)
    {
    delay(1800000);     // delaying the action 30 minutes after light is detected
    LinAct.write(75);   // move servo to 75
    delay(2000);        // wait 2 seconds
    LinAct.write(50);   // move servo to 50
    }

int light(String command)   // when "light" is called, it will have a string command
{ 
    if(command == "on")   // this will move the servo to the on position
    {                            
        LinAct.write(50);   // move servo to 50
        delay(2000);        // wait 2 seconds
        LinAct.write(75);   // move servo to 75
        return 1;           // return a status of "1"
    }
    else if(command == "off")     // this will move the servo to the off position
    {                               
        {
        LinAct.write(75);       // move servo to 75
        delay(2000);            // wait 2 seconds
        LinAct.write(50);       // move servo to 50
        }
        return 2;               // return a status of "2"
    }
}

void loop()
{
}

Credits

John Russell

John Russell

1 project • 1 follower
MEGR Major UNC Charlotte
Nicholas Hanna

Nicholas Hanna

1 project • 1 follower
Thanks to Particle and Particle.

Comments

Add projectSign up / Login