Skip to content

Instantly share code, notes, and snippets.

@T-rex2017
Last active June 26, 2020 09:56
Show Gist options
  • Save T-rex2017/99525f172ec49abec38d2f6311061881 to your computer and use it in GitHub Desktop.
Save T-rex2017/99525f172ec49abec38d2f6311061881 to your computer and use it in GitHub Desktop.

Sanitizer Dispenser

BOM

  1. arduino
  2. dc pump
  3. relay
  4. leds
  5. buttons
  6. ir sensor
  7. fluid level sensor
  8. pot
  9. wires
  10. some elctronic components

Tools

  1. soldring iron & led
  2. wire stripper
  3. pc with arduino IDE

Working

when device is turned on an led indicates it's ready when hand is placed under the sensor it dispense sanitizer and lights up another led the amount time it dispense the fluid can be controlled by th pot if the hand is still there after the set time it will not spill anything until hand is removed an reintroduced if the fluid in the tank go low another led will lightup and the device will not work untill fluid is refilled

// INPUTS
int sensorPin = 2;
int flotPin = 3;
int potPin = A0;
// OUTPUTS
int relayPin = 5;
int readyPin = 6;
int potVal;
int spillTime;
int trigTime;
bool isRunning = false;
bool sensorDetected;
bool noFluid;
bool isReady = false;
unsigned long readDelay = 1000;
unsigned long sqartMillis;
unsigned long sensorCounter;
unsigned long squartCounter;
void setup() {
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
pinMode(readyPin, OUTPUT);
pinMode(sensorPin, INPUT);
pinMode(flotPin, INPUT_PULLUP);
digitalWrite(readyPin, HIGH);
digitalWrite(relayPin, LOW);
}
void loop() {
pot();
if (digitalRead(flotPin) == LOW) {
noFluid = true;
}
else if(digitalRead(flotPin) == HIGH){
noFluid = false;
}
if (sensorDetected != true && digitalRead(sensorPin) == HIGH) {
sensorDetected = true;
sensorCounter = millis();
}
else if (digitalRead(sensorPin) == LOW) {
sensorDetected = false;
}
unsigned long currentMillis = millis();
if (isRunning != true && noFluid != true && sensorDetected == true && currentMillis - sensorCounter >= readDelay) {
trigTime = spillTime;
squartCounter = millis();
digitalWrite(relayPin, HIGH);
isRunning = true;
isReady = false;
}
if (isRunning == true) {
if (currentMillis - squartCounter >= trigTime || sensorDetected == false || noFluid == true) {
digitalWrite(relayPin, LOW);
isReady = true;
if(sensorDetected == false){
isRunning = false;
}
}
}
if (isReady == true && noFluid != true) {
digitalWrite(readyPin, HIGH);
}
else {
digitalWrite(readyPin, LOW);
}
} // loop
void pot() {
potVal = analogRead(potPin);
if (potVal >= 0 && potVal <= 93) {
spillTime = 500;
}
else if (potVal >= 93 && potVal <= 186) {
spillTime = 600;
}
else if (potVal >= 186 && potVal <= 279) {
spillTime = 700;
}
else if (potVal >= 279 && potVal <= 372) {
spillTime = 800;
}
else if (potVal >= 372 && potVal <= 465) {
spillTime = 900;
}
else if (potVal >= 465 && potVal <= 558) {
spillTime = 1000;
}
else if (potVal >= 588 && potVal <= 651) {
spillTime = 1100;
}
else if (potVal >= 651 && potVal <= 744) {
spillTime = 1200;
}
else if (potVal >= 744 && potVal <= 837) {
spillTime = 1300;
}
else if (potVal >= 837 && potVal <= 930) {
spillTime = 1400;
}
else if (potVal >= 930 && potVal <= 1023) {
spillTime = 1500;
}
}
@T-rex2017
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment