Alex Chitnis
Published

Lane Tech PCL - Candle Closer

Home innovation project for Lane Tech PCL, Closes a lid on a candle after 2 hours of it being lit.

IntermediateProtip73
Lane Tech PCL - Candle Closer

Things used in this project

Hardware components

Argon
Particle Argon
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
ELEGOO 5 sets 28BYJ-48 5V Stepper Motor + ULN2003 Motor Driver Board for Arduino
ELEGOO 5 sets 28BYJ-48 5V Stepper Motor + ULN2003 Motor Driver Board for Arduino
×1
Elegoo Flame Sensor
×1
0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
SparkFun M-F Wires
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Led Matrix Editor

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Code

Main Code

C/C++
This is my main code that I used for the project
/*********************************************************************
 PROJECT
*********************************************************************/

//Libraries I used
#include <Stepper.h>
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"

// definining the oled display
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2

//defining the pins and variables for the flame sensor.
int flamePin = 3;
int flame;
bool flameOn = false; 

#define FULLSTEP 4

// Defining the Stepper Motor + its pins
const int stepsPerRevolution = 2048;
#define IN1 4
#define IN2 5
#define IN3 6
#define IN4 7
Stepper myStepper(stepsPerRevolution, IN1, IN3 , IN2, IN4);

//candle logo 
static const unsigned char candleLarge[] = {
  0B00000000,0B00000000,
  0B00000000,0B00000000,
  0B00000000,0B00000000,
  0B00000000,0B00000000,
  0B00000000,0B00000000,
  0B00000000,0B00000000,
  0B00000001,0B00000000,
  0B00000001,0B10000000,
  0B00000011,0B01000000,
  0B00000100,0B00110000,
  0B00001000,0B10001000,
  0B00010001,0B01001000,
  0B00100010,0B01000100,
  0B00100100,0B00100100,
  0B00100100,0B00100100,
  0B00010010,0B01001000,
  0B00001000,0B00010000,
  0B00000111,0B11100000,
  0B00000000,0B00000000,
  0B00000000,0B00000000,
  0B00000001,0B00000000,
  0B00000001,0B00000000,
  0B00000001,0B10000000,
  0B00000001, 0B10000000,
  0B00000001,0B10000000,
  0B01111111,0B11111110,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01010000,0B00000110,
  0B01101001,0B11001010,
  0B01001010,0B00101010,
  0B01000100,0B00010010,
  0B01010000,0B00000010,
  0B01011000,0B01000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01000000,0B00000010,
  0B01111111,0B11111110,
  0B00000000,0B00000000,

};


#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup() {
    Serial.begin(9600);
    
    // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);// initialize with the I2C addr 0x3D (for the 128x64)
    // makes it work

    display.clearDisplay(); 
    // clears display initially
    
    //draws the candle logo
    display.drawBitmap(56, 4, candleLarge, 16, 56, 1);
    display.display();
    
    //establishes the flame pin
    pinMode(flamePin,INPUT);
    
    //establishes the stepper motor speed
    myStepper.setSpeed(17);
    Serial.begin(9600);
}




void loop() {


    //checks if there is a flame
    flame = digitalRead(flamePin);
    if(flame == HIGH){
        flameOn = true;
    }
    

    if (flameOn == true){
     
        display.clearDisplay();
        display.setTextSize(2);
        display.setTextColor(WHITE);
        display.setCursor(2,10);
        display.print("Starting  timer.");
        display.display();
        delay(6000);
        display.clearDisplay();
        
        //coundown timer for two hours
        for(int i=1; i>=0; i--){
            for(int j=59; j>=0; j--){
                display.setTextSize(5);
                display.setTextColor(WHITE);
                display.setCursor(4,10);
                display.print(i);
                display.print(":");
                if(j<10){
                    display.print("0");
                }

                display.print(j);
                display.display();
                delay(60000);
                display.clearDisplay();
            }
        }
    
        //closes the stepper motor and waits for the flame to extingush before opening again
        myStepper.step(-512);
        display.clearDisplay();
        display.setTextSize(2);
        display.setTextColor(WHITE);
        display.setCursor(2,10);
        display.print("Extinguishing Now...");
        display.display();
        delay(18000);
        myStepper.step(512);
        
        
        display.clearDisplay();
        display.setTextSize(2);
        display.setTextColor(WHITE);
        display.setCursor(4,10);
        display.print("Complete!");
        display.display();
        delay(6000);
        flameOn = false;
    }
    
    //if there is no flame sensed it just shows the candle so you can tell that the machine is on + display is working
    if(flameOn == false){
        display.clearDisplay();
        display.drawBitmap(56, 4, candleLarge, 16, 56, 1);
        display.display();
    }


}

Credits

Alex Chitnis

Alex Chitnis

0 projects • 0 followers

Comments

Add projectSign up / Login