Week 8: Hands-free switch

Inspiration:

For this assignment, I was mainly inspired by the UV shoe sanitizer that is used to help fight bacteria in hospitals.

Process:

For the circuit, I have used 5 LEDs ( 4 red, 1 green), 8 wires, and one 320Ω resistor. The basic idea is that the individual waits for the green light to put his shoe on the platform, then the disinfection starts and takes 5 seconds to complete, when the green light goes on again, the individual can then remove his shoe.

View post on imgur.com

Platform:

View post on imgur.com

Setup:

I have used a for() loop and pinMode to avoid unnecessary repetition. I also have an array to store all the LEDs.

```void setup() {
pinMode(7, OUTPUT);
for (int i=0; i<4; i++){
pinMode(Led[i], OUTPUT);
}
}```
LEDs:

To tell the user that the disinfection is still going on, I have added an animation to the red LEDs, in which the light bounces between the two edges of the strip. To do that, I used the Delay function as well as two for() loops (for each direction), and digitalWrite() to control the LEDs.

```// Check when the shoe is sanitized
if (DONE){
for (int i=0; i<4; i++){
digitalWrite(Led[i], LOW);
digitalWrite(7, HIGH);
}
}

// If not sanitized
if (DONE==false){
digitalWrite(7, LOW);
// One way, left to right
for (int i=0; i<4; i++){
// 2 Leds at the same time
digitalWrite(Led[i], HIGH);
digitalWrite(Led[i+1], HIGH);
// Delay of 120
delay(120);
digitalWrite(Led[i], LOW);
digitalWrite(Led[i+1], LOW);}
// The other way , right to left
for (int i=3; i>=0; i--){
digitalWrite(Led[i], HIGH);
digitalWrite(Led[i-1], HIGH);
delay(120);
digitalWrite(Led[i], LOW);
digitalWrite(Led[i-1], LOW);
}
}```
Timer:

For the timer, I have used millis() to change a boolean variable every 5 seconds.

```// Timer for the sanitization
unsigned long curr = millis();
if (curr-prev>=5000){
prev=curr;
DONE=!DONE;
}```

One of the challenges I faced was setting up a good connection between wires as the tape was not ideal.

Demo:

View post on imgur.com

Code:
```int Led[]= {9, 10, 11, 12}; // list of Leds
boolean DONE= false; // check when the sanitization is done
unsigned long prev=0; // for the timer

void setup() {
pinMode(7, OUTPUT);
for (int i=0; i<4; i++){
pinMode(Led[i], OUTPUT);
}
}

void loop() {
// Timer for the sanitization
unsigned long curr = millis();
if (curr-prev>=5000){
prev=curr;
DONE=!DONE;
}

// Check when the shoe is sanitized
if (DONE){
for (int i=0; i<4; i++){
digitalWrite(Led[i], LOW);
digitalWrite(7, HIGH);
}
}

// If not sanitized
if (DONE==false){
digitalWrite(7, LOW);
// One way, left to right
for (int i=0; i<4; i++){
// 2 Leds at the same time
digitalWrite(Led[i], HIGH);
digitalWrite(Led[i+1], HIGH);
// Delay of 120
delay(120);
digitalWrite(Led[i], LOW);
digitalWrite(Led[i+1], LOW);}
// The other way , right to left
for (int i=3; i>=0; i--){
digitalWrite(Led[i], HIGH);
digitalWrite(Led[i-1], HIGH);
delay(120);
digitalWrite(Led[i], LOW);
digitalWrite(Led[i-1], LOW);
}
}
}```