Working Theory
Take a look at the circuit diagram first, other wise you won't be able to understand what I'm saying. Whenever I press a switch the circuit will be completing through different number of resistors,
- In the circuit, if we press the 5th switch then the circuit is completing through all the 4 resistors,
- If we press the 4th switch the circuit is completing through 3 resistors,
- If we press the 3rd switch the circuit is completing through 2 resistors,
- If we press the 2nd switch the circuit is completing through 1 resistors,
- and if we press the 1st switch the circuit is completing without any resistors.
That means the current reaching the analog pin A1 will be different for each switches, so we will use analogRead() function to read the values from the pin A1 and then we use a if else if condition to perform different operations for each switches.
Video