Collin OwensbyJ. Bird
Published

Automatic Window Blinds (MEGR 3171 Spring 2023)

This will show the process, schematic, components, code, and a video presentation of the device.

IntermediateShowcase (no instructions)4
Automatic Window Blinds (MEGR 3171 Spring 2023)

Things used in this project

Hardware components

Argon
Particle Argon
×2
Photo resistor
Photo resistor
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
AA Batteries
AA Batteries
×4
wires
×1
battery case
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Code

Photoresistor Code

C#
This code is for the photoresistor and uses the tinker to read a high low value, the code then reads in a loop if a high value is read the code writes "on". At a low value the code reads "off".
int photoresistor = A1;
int led1 = D7;
int buffer = 2000;
int limit = 1500;
int lightlevel;

void setup()
{
    //pinmodes
    pinMode(photoresistor, INPUT);
    pinMode(led1, OUTPUT);
   
    //subscribe to switch inputs
    Particle.subscribe("servopower", myHandler);
}

void loop()
{
    lightlevel = analogRead(photoresistor);
    Particle.publish("thingSpeakWrite", String(lightlevel), PRIVATE);
   
    if(lightlevel >= limit)
    {
        Particle.publish("lightlevel","open",PRIVATE);
        delay(buffer);
    }
   
    else
    {
        Particle.publish("lightlevel","close",PRIVATE);
        delay(buffer);
    }
}

void myHandler(const char *event, const char *data)
{
    if (strcmp(data,"on")==0) //servo is and light up D7
  {
    digitalWrite(led1, HIGH);
  }

  else if (strcmp(data,"off")==0) //servo is off and turn off D7
  {
    digitalWrite(led1, LOW);
  }
}

Servo And Switch Code

C#
This code controls the servo motor and has a push button switch aswell.
//servo pins and values
Servo myservo;
int servo1 = A0;
int orginstate = 1;
int openstate = 1;
int closestate= 90;


//switch pins and values
int buttonstate;
int switchpin = D7;

void setup() {

    //pinmodes
    pinMode(switchpin,INPUT);
    myservo.attach(servo1);

    //initial readings and values to start with
    myservo.write(orginstate);
   
    //subscibe to receive events from the photoresistor
    Particle.subscribe("lightlevel", myHandler);

}

void loop()
{
    buttonstate = digitalRead(switchpin);
   
    if (buttonstate == 0)
    {
       
        Particle.publish("servopower","on", ALL_DEVICES);
       
    }
   
    else if (buttonstate == 1)
    {
        Particle.publish("servopower","off",ALL_DEVICES);
       
    }
    delay(2000);
}

void myHandler(const char *event, const char *data)
{
 
  digitalRead(buttonstate);
 
  if (strcmp(data,"open")==0 && buttonstate == 0) //go to open state, strcmp compares data and open and returns 0 if true
  {
    myservo.write(openstate);
    delay(1000);
  }

  else if (strcmp(data,"close")==0 && buttonstate == 0) //go to closed state
  {
    myservo.write(closestate);
    delay(1000);
  }

  else {
    // if the data is something else, don't do anything.
  }
}

Credits

Collin Owensby

Collin Owensby

0 projects • 0 followers
J. Bird

J. Bird

0 projects • 0 followers

Comments

Add projectSign up / Login