Skip to content

Instantly share code, notes, and snippets.

@T-rex2017
Last active June 26, 2020 08:48
Show Gist options
  • Save T-rex2017/6f3d473209cab0c4fab0430e2a899902 to your computer and use it in GitHub Desktop.
Save T-rex2017/6f3d473209cab0c4fab0430e2a899902 to your computer and use it in GitHub Desktop.

DIY UV Box For Sanitizing Objects

BOM

  1. arduino
  2. UV light
  3. relay
  4. limit switch
  5. leds
  6. pot
  7. push buttons
  8. leds
  9. wiresrelay

Tools

  1. soldering iron & lead
  2. wire stripper
  3. male female headers
  4. pc with arduino IDE

Working

  • open the enclosure and put the object inside it
  • set sanitizing time using pot and press start button
  • ones done the uv light will turn off
  • if the door is opend during cleaning the uv will get turned off
const int GatePin = 5 ;
const int StartPin = 6;
const int uvPin = 4;
const int potPin = A0;
const int Green_led = 7;
const int Red_led = 8;
unsigned long bTime = 0;
unsigned long bfor = 0;
int potVal = 0;
bool isOpen = true;
bool uvState = false;
unsigned long startMillis = 0;
bool debug = true;
void setup() {
if (debug == true)
Serial.begin(9600);
pinMode(GatePin, INPUT);
pinMode(StartPin, INPUT);
pinMode(uvPin, OUTPUT);
digitalWrite(Green_led,HIGH);
}
void loop() {
if (debug == true)
Serial.println();
// Read Gate State
if (digitalRead(GatePin) == LOW) {
isOpen = false;
if (debug == true)
Serial.print("Door : Closed ");
}
else {
isOpen = true;
if (debug == true)
Serial.print("Door : Opened ");
}
// Read Pot Value
potVal = analogRead(potPin);
if (debug == true)
Serial.print("bTime : ");
if (potVal > 0 && potVal <= 255) {
bTime = 15000;
if (debug == true)
Serial.print("15k ");
}
else if (potVal > 255 && potVal <= 560) {
bTime = 30000;
if (debug == true)
Serial.print("30k ");
}
else if (potVal > 560 && potVal <= 715) {
bTime = 45000;
if (debug == true)
Serial.print("45k ");
}
else if (potVal > 715 && potVal <= 1023) {
bTime = 60000;
if (debug == true)
Serial.print("60k ");
}
//start baking if startbtn pressed
if (uvState != true) {
if (digitalRead(StartPin) == LOW && digitalRead(GatePin) == LOW) {
startMillis = millis();
uvState = true;
bfor = bTime;
digitalWrite(uvPin, HIGH);
digitalWrite(Red_led,HIGH);
digitalWrite(Green_led,LOW);
}
}
if (uvState == true)
Serial.print("UV : ON ");
Serial.print("LED : ON ");
unsigned long currentMillis = millis();
if (currentMillis - startMillis >= bfor || digitalRead(GatePin) == HIGH) {
uvState = false;
digitalWrite(uvPin, LOW);
digitalWrite(Red_led,LOW);
digitalWrite(Green_led,HIGH);
if (debug == true)
Serial.print("UV : OFF ");
}
if (debug == true && uvState == true){
Serial.print("Time : ");
Serial.print(currentMillis - startMillis);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment