Brandon CrowellCorey Hutcherson
Published

Door Sensor Project

This door sensor will have the capability to detect movement and return a sensor output to a separate location.

BeginnerWork in progress59
Door Sensor Project

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×2
Analog joystick (Generic)
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Door Sensor Receiver Diagram

This door sensor diagram involves the second particle and LED light combination for receiving a signal

Door Sensor Sender Diagram

This door sensor diagram involves the first particle and joystick combination for sending a signal.

Code

Motion Detector Joystick Code

Arduino
This code detects movement based on the y-axis deformation of the joystick sensor, which is attached to the door frame.
int joystickYPin = A0;

void setup() {
  pinMode(joystickYPin, INPUT);
}
void loop() {
  int joystickYValue = analogRead(joystickYPin);
    if (abs(joystickYValue - 512) > 50) {
    String message = "Joystick moved - Y: " + String(joystickYValue);
    Particle.publish("joystick-event", message);
    delay(1000);
  }
}

Motion Receiver LED Code

Arduino
This code receives movement and outputs a RGB light based on the y-axis deformation of the joystick sensor, which is attached to the door frame.
int LEDPin = D0;
int LEDThreshold = 2500;

void setup() {
  pinMode(LEDPin, OUTPUT);
  Particle.subscribe("joystick-event", joystickEventHandler);
}
void loop() {
}
void joystickEventHandler(const char *event, const char *data) {
  int joystickYValue = extractJoystickYValue(data);

  if (joystickYValue > LEDThreshold) {
    String message = "Door Sensor Activated";
    Particle.publish("door-event", message);
    digitalWrite(LEDPin, HIGH);
    delay(1000); 
    digitalWrite(LEDPin, LOW);
  }
}
int extractJoystickYValue(const char *data) {
  String dataString = String(data);
  int yIndex = dataString.indexOf("Y: ") + 3;
  return dataString.substring(yIndex).toInt();
}

Credits

Brandon Crowell
1 project • 1 follower
Contact
Corey Hutcherson
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.