Britney A. King
Published

PixelShifter

Internet of Things - smart home device that triggers wemo, hue light bulbs, and OLED Display using a PIR Sensor.

BeginnerShowcase (no instructions)59
PixelShifter

Things used in this project

Hardware components

Photon
Particle Photon
×1
0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
SparkFun RGB Encoder
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Schematics

Fritzing

Circuit Diagram

Code

PixelShifter

C/C++
/* 
 * Project PixelShifter
 * Author: Britney A. King
 * Date: 10/29/24
 */

#include "Particle.h"
#include "IoTClassroom_CNM.h"
#include "encoder.h"
#include "Adafruit_SSD1306.h"
#include "Adafruit_GFX.h"
#include "DeadPacBitMap.h"
#include "AlivePacBitMap.h"

//OLED Display
const int OLED_RESET=-1; 
Adafruit_SSD1306 display(OLED_RESET);

SYSTEM_MODE(SEMI_AUTOMATIC);

// 1 hue light bulbs (manual/user presses button to turn off on/will be magenta color)
bool Buttonpin;
const int BUTTONPIN = D3;
Button button(BUTTONPIN);
int buttonState;

const int BULB_1 = 1;
const int BULB_2 = 2;
const int BULB_3 = 3;
const int BULB_4 = 4;

const int BULB_5 = 5;
const int BULB_6 = 6;

int color;

// [2] 2 wemo outlets
const int MYWEMO = 4;
const int MYWEMO_5 = 5;
//

// [3] AUTOMATIC MODE / user presses button to active automatic mode, will use PIR Sensor to trigger OLED display + n

// PIR Sensor
  const int PIR_SENSOR_OUTPUT_PIN = D4;
  int ON;
//

void setup() {

//[1] // hue light bulb on & off
  Serial.begin(9600);
  waitFor(Serial.isConnected,15000);

  WiFi.on();
  WiFi.clearCredentials();
  WiFi.setCredentials("IoTNetwork");
  
  WiFi.connect();
       while(WiFi.connecting()) {
        Serial.printf(".");
  }
         Serial.printf("\n\n");

// encoder
      pinMode(D3,OUTPUT);
      pinMode(BUTTONPIN,INPUT_PULLDOWN);

// PIR Sensor
      pinMode(PIR_SENSOR_OUTPUT_PIN, INPUT);
        Serial.begin(9600);	/* Define baud rate for serial communication */
           delay(10000);	/* Power On Warm Up Delay */

// OLED Display
       display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
       display.display();
       delay(1000);
       display.clearDisplay();
       display.display();
}

void loop() {

// Encoder button clicked will activate 5 Hue lights
   if(button.isClicked()){
    buttonState = !buttonState;
    if (!buttonState){
// Hue light
  Serial.printf("Setting color of bulb %i to color %06i\n",52428);
     setHue(BULB_1,true,52428,255,255);
     setHue(BULB_2,true,52428,255,255);
     setHue(BULB_3,true,52428,255,255);
     setHue(BULB_4,true,52428,255,255);
     setHue(BULB_5,true,52428,255,255);
        delay(1000);
//My Wemo Serial Print
      Serial.printf ("Button state is on \n");
      Serial.printf("Turning on Wemo# %i\n",MYWEMO);
         wemoWrite(MYWEMO,HIGH);
         wemoWrite(MYWEMO_5,HIGH);
    }

  else {
   Serial.printf("Setting color of bulb %i to color %06i\n",52428);
     setHue(BULB_1,false,52428,255,255);
     setHue(BULB_2,false,52428,255,255);
     setHue(BULB_3,false,52428,255,255);
     setHue(BULB_4,false,52428,255,255);
     setHue(BULB_5,false,52428,255,255);
        delay(1000);

     // My Wemo
      Serial.printf ("Button state is off \n");
      Serial.printf ("Turning off Wemoa# %i\n",MYWEMO);
        wemoWrite(MYWEMO,LOW);
        wemoWrite(MYWEMO_5,LOW);
        }
   }

//PIR Sensor + Serial Print
      int sensor_output;
      sensor_output = digitalRead(PIR_SENSOR_OUTPUT_PIN);

      if(sensor_output == LOW )
  {
    //   if(ON == 1 )
      Serial.print("I don't see you\n\n");
      ON = 0;
      delay(1000);
//OLED Display + Custom Pacman Bitmap
        display.setCursor(0,0);
        display.drawBitmap(0, 0, AlivePacBitMap, 128, 64, 1);
 //display.printf("I DON'T SEE YOU\n\n");
        display.setTextColor(WHITE);
        display.display();
        display.clearDisplay();
//   Serial.printf("Setting color of bulb %i to color %06i\n",52428);
     setHue(BULB_6,false,52428,255,255); 
        delay(1000);
  }
      else
  {
       Serial.print("I SEE YOU\n\n");    
  //     ON = 1;
       delay(1000);

        display.setCursor(0,0);
        display.drawBitmap(0, 0, DeadPacBitMap, 128, 64, 1);
//display.printf("I SEE YOU\n\n");
        display.setTextColor(WHITE);
        display.display();
        display.clearDisplay();

        ///
          Serial.printf("Setting color of bulb 6 %i to color %06i\n",52428);
     setHue(BULB_6,true,52428,255,255);
        delay(1000);
  }

    }
  

Credits

Britney A. King
3 projects • 6 followers
Digital Artist. Designer. Educator.
Contact

Comments

Please log in or sign up to comment.