Oren Rehm
Published

Pressure Controlled Light Switch

The basic idea is to use a pressure sensor to ensure the lights in my room turn on when when I come home and turn off when I leave

BeginnerShowcase (no instructions)1
Pressure Controlled Light Switch

Things used in this project

Hardware components

LED (generic)
LED (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×2
Male/Male Jumper Wires
×3
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Breadboard (generic)
Breadboard (generic)
×1
Photon 2
Particle Photon 2
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Tape, Clear
Tape, Clear
Foam Board

Story

Read more

Schematics

Basic circuitry on breadboard

Code

Particle Web IDE Code

C/C++
Code flashed to the Photon 2
#include "Particle.h"
SYSTEM_MODE(AUTOMATIC);
SerialLogHandler logHandler(LOG_LEVEL_INFO);

int sensor = A5;
int led = 7;
int status;

void setup() {
    pinMode(led,OUTPUT);
    digitalWrite(led,HIGH);
    Serial.begin(9600);
    status = 0;
}

void loop() {
    //delay(1000);
    if(analogRead(sensor)>30 && status==0){
        Serial.println("Pressure detected");
        Particle.publish("toggle_wiz_on");
        digitalWrite(led,LOW);
        status = 1;
        delay(10000);
    }
    if (analogRead(sensor)<5 && status==0){
        Serial.println("No pressure - lights off");
    }
    if (analogRead(sensor)<31 && status==1){
        Serial.println("Pressure Removed");
        Particle.publish("toggle_wiz_off");
        digitalWrite(led,HIGH);
        status = 0;
        
    }
}

Credits

Oren Rehm
1 project • 1 follower

Comments