jerzes
Published

UV light box

UV light box made with UV led and Wemos D1 mini v1 as timer and controller.

IntermediateShowcase (no instructions)5 hours159
UV light box

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
Grove - SPDT Relay(30A)
Seeed Studio Grove - SPDT Relay(30A)
×1
0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
EC11 Rotary Encoder Module
DFRobot EC11 Rotary Encoder Module
×1
Buzzer
Buzzer
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Code

Timer and LED power switch

C/C++
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Encoder.h>

const uint8_t sw = 2;       //D4
const uint8_t pinA = 14;    // D6
const uint8_t pinB = 12;    //D5
const uint8_t buzz = 13;    // D7
const uint8_t uvlamp = 15;  // D8
uint8_t runningflag = 0;

Encoder myEnc(pinB, pinA);
unsigned long lastButtonPress = 0;

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1  // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
long oldPosition = -999;
long newPosition = 0;
long settime = 0;
void setup() {
  //encoder
  Serial.begin(19200);
  pinMode(buzz, OUTPUT);
  pinMode(uvlamp, OUTPUT);
  pinMode(sw, INPUT);

  //encoder
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.display();

  display.setTextColor(WHITE);
}

void loop() {

  uint8_t sw_state = digitalRead(sw);
  //encoder
  if (sw_state == LOW && runningflag != 1 && settime > 0) {
    if (millis() - lastButtonPress > 550) {
      myEnc.write(0);
      display.clearDisplay();
      display.setCursor(4, 4);
      display.setTextSize(2);
      display.println("Starting");
      display.display();
      delay(500);
      runningflag = 1;
      startUV(settime);
    }
    lastButtonPress = millis();
  }

  newPosition = myEnc.read();


  if (newPosition != oldPosition) {
    oldPosition = newPosition;

    showTime();
  }
}
void showTime() {
  if (runningflag == 0) {
    settime = setTime(newPosition);
  }
  uint8_t sec;
  long min;

  display.clearDisplay();
  display.setCursor(4, 4);
  display.setTextSize(2);
  if (runningflag == 0) {
    display.println("Set time");
  } else {
    display.println("Remaining time");
  }
  display.setTextSize(3);
  if (settime >= 60) {
    display.setCursor(20, 42);
    sec = settime % 60;
    min = settime / 60;
    display.print(min);
    display.print(":");
    display.println(sec);
  } else {
    display.setCursor(40, 42);
    display.println(settime);
  }
  display.display();
}
long setTime(long rev) {
  if (rev <= 0) {
    myEnc.write(0);
    newPosition = myEnc.read();
    return 0;
  } else {
    return rev * 5;
  }
}
void startUV(long time) {
  showTime();
  digitalWrite(uvlamp, HIGH);
  uint8_t interval = 10;
  for (long i = settime; i > 0; i--) {
    delay(1000);
    settime--;
    interval--;
    if (interval == 0) {
      showTime();
      interval = 10;
    }
    if (settime <= 10) {
      showTime();
    }
  }

  digitalWrite(uvlamp, LOW);
  for (uint8_t j = 1; j < 6; j++) {
    digitalWrite(buzz, HIGH);
    delay(500);
    digitalWrite(buzz, LOW);
    delay(500);
    Serial.print("end buzzer ");
  }
  runningflag = 0;
}

Credits

jerzes
3 projects • 0 followers
Former IT specialist, now occupied by being unemployed
Contact

Comments

Please log in or sign up to comment.