Robert StiltnerBenjamin Hodges
Published © GPL3+

The Asstron 3000

These motion activated toilet lights will change your entire outlook on using the bathroom.

IntermediateFull instructions provided6 hours2,236
The Asstron 3000

Things used in this project

Hardware components

Double Sided Tape
×1
Multicolor LED Strip
×2
Particle SPDT Relay
×1
Photon
Particle Photon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Particle Photon Maker Kit
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
12 volt batteries
×2

Software apps and online services

Ubidots
Ubidots

Story

Read more

Schematics

Motion Detector Schematic

This motion detector circuit is the most simple of the two circuits. There are three wires and the PIR motion sensor. The ground wire goes from the ground on the particle to the ground pin on the PIR sensor. The wire connected to the Vin(5 Volts) on the particle goes to the 5 volts on the PIR sensor. Finally the wire connected to the A1 pin is connected to the OUT pin on the sensor.

LED and Relay Schematic

The LED and Relay circuit is the most complex circuit in this project. The circuit involves a relay, a 1000 ohm resistor, a transistor and a diode. Each component is located in the schematic and can be connected as shown.

Code

Motion Detector Code

Arduino
This code is used to send the detected motion of the PIR Sensor on the particle located at the entrance to the door to the other particle located in the cabinet powering the LED lights. The code uses the buddy system so to speak. The particle with the motion sensor takes the motion and publishes the signal to the other particle which is the subscriber to the code. The delay in line 50 is used to determine how long the lights are active and is up to the person using the code and lights.
int led = D0;
int sensor = A1;


int intactValue;
int brokenValue;
int beamThreshold;

bool beamBroken = false;

// We start with the setup function.

void setup() {
  
 
 
  pinMode(sensor,INPUT);  
  pinMode(power,OUTPUT); 

  // Here we are going to subscribe to your buddy's event using Particle.subscribe
 
  // Subscribe will listen for the event motiondetect and, when it finds it, will run the function myHandler()
  

  


  

  

  intactValue = 4095;
  brokenValue = 0;
  beamThreshold = 2000;

}


void loop() {
  // This loop sends a publish when the motion is detected.
   
  if (analogRead(sensor)>beamThreshold) {
    if (beamBroken==true) {
        Particle.publish("motiondetect","intact");
        // publish this public event
        
        
        // Set the flag to reflect the current status of the beam.
        beamBroken=false;
        delay(450000);
    }
  }

  else {
      if (beamBroken==false) {
        // Same deal as before...
        Particle.publish("motiondetect","broken");
        beamBroken=true;
      }
  }

}

Relay Circuit

Arduino
This code is used to accept the PIR sensor output signal from the other particle photon. When the code receives a signal that shows motion has been detected, an output pin D6 is triggered to output voltage through a SPDT Relay, therefore allowing voltage to pass to the two LED strips in the toilet.
This code also sends data to a graphing program online called Ubidots. A pin on the particle, A2, measured analog voltage across the coil in the relay, therefore showing when the relay was activated. The data was collected every second and seemed to work fine, but taking a measurement every couple of minutes would be sufficient to accurately plot data.
#include "Ubidots/Ubidots.h"
#define TOKEN "dqkFj8sPgfMqSX33HpJ10HaTuXyuCr" 

int relay = D6;

Ubidots ubidots(TOKEN);
void setup() {
   Serial.begin(115200);
  pinMode(relay,OUTPUT); // Our relay is output as well
  
  // Here we are going to subscribe to your buddy's event using Particle.subscribe
  Particle.subscribe("motiondetect", myHandler);
  // Subscribe will listen for the event motiondetect and, when it finds it, will run the function myHandler()
 
void loop() {
  // This loop sends a publish when motion is detected
   float value1 = analogRead(A2);

    ubidots.add("motion", value1);  // Change for your variable name
    ubidots.sendAll();
    delay(1000);
}
// Now for the myHandler function, which is called when the cloud tells us that our buddy's event is published.
void myHandler(const char *event, const char *data)
{


  if (strcmp(data,"intact")==0) {

    digitalWrite(relay,HIGH);
  }
  else if (strcmp(data,"broken")==0) {
 
    digitalWrite(relay,LOW);
  }
  else {
    // if the data is something else, don't do anything.
    // Really the data shouldn't be anything but those two listed above.
  }
}

Credits

Robert Stiltner

Robert Stiltner

1 project • 1 follower
Benjamin Hodges

Benjamin Hodges

1 project • 1 follower

Comments

Add projectSign up / Login