Tom NoblesCaleb Troxell
Published

Motion Detecting A/C Unit

This project will turn on an A/C unit when you are in your room and automatically turn off to save energy.

BeginnerFull instructions provided3 hours677
Motion Detecting A/C Unit

Things used in this project

Hardware components

Photon
Particle Photon
×2
Servo
Any brand or size should do the trick
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Servo Diagram

This is a simple setup which just includes connecting the power and ground wires to their respective locations on the photon and then putting the signal wire in a location that matches with the code

PIR Sensor Diagram

Same as the servo wiring, power and ground are connected as well as a signal wire.

Code

Servo Switch Code

SQL
In order to make the servo turn the correct amount to turn on/off the A/C unit, we had to 'guess and check' values until the desired angles were achieved.
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created


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


void setup( ) {
    pinMode(led,OUTPUT);
    digitalWrite(led,LOW);
  // attaches the servo on the D0 pin to the servo object
  myservo.attach(D0);

  // register the Spark function

  Particle.subscribe("motion", anything, "340049001051353338363333");
}

void anything(const char *event, const char *data)
{
     digitalWrite(led,HIGH);
     if (strcmp(data, "Movement")==0)
     {
myservo.write(30);
delay(3000);
myservo.write(55);
     }
}

void loop()
{
}

PIR Sensor Code

Arduino
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>
int PIRSensor = D0;
int state=0;
int Motion = 0;
TCPClient client;
unsigned int myChannelNumber = 256907; // replace with your ChannelID
const char * myWriteAPIKey = "IXPUI1EJ4696AFTO"; // replace with your WriteAPIKey
void setup(){
    ThingSpeak.begin(client);

pinMode(PIRSensor,INPUT);

}
void loop() {
    
  if (digitalRead(PIRSensor) == HIGH){

       Particle.publish("motion","Movement");
       state = !state;
       Motion= Motion+1;
       delay(5000);
        unsigned long now = millis();
ThingSpeak.setField(1,Motion);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);  
   delay(10);
}
}

Credits

Tom Nobles

Tom Nobles

1 project • 0 followers
Caleb Troxell

Caleb Troxell

1 project • 0 followers

Comments