Najad
Published © GPL3+

100+ Switches in a Single Pin of Arduino

Did you run out of input pins? Don't worry, here is a solution without any shift registers.

IntermediateFull instructions provided19,284

Things used in this project

Hardware components

UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
×1
UTSOURCE Breadboard
×1
Arduino Nano
×1
UTSOURCE pushbutton
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

circuit_bb_ViQSgzJlL3.jpg

With LEDs

Code

MultipleSw_SinglePin.ino

C/C++
//www.diyusthad.com
//https://www.youtube.com/channel/UCjwtJsOrZyH7E6sBr_YJSeA
//Code by Najad

#define sw A1 //name for analog pin A1
#define led1 12
#define led2 11
#define led3 10
#define led4 9
#define led5 8

void setup() 
{
  Serial.begin(9600);
  pinMode(led1,OUTPUT); digitalWrite(led1,HIGH); //setting led1 pin HIGH ie LED will be off according to our circuit
  pinMode(led2,OUTPUT); digitalWrite(led2,HIGH); //setting led2 pin HIGH ie LED will be off according to our circuit
  pinMode(led3,OUTPUT); digitalWrite(led3,HIGH); //setting led3 pin HIGH ie LED will be off according to our circuit
  pinMode(led4,OUTPUT); digitalWrite(led4,HIGH); //setting led4 pin HIGH ie LED will be off according to our circuit
  pinMode(led5,OUTPUT); digitalWrite(led5,HIGH); //setting led5 pin HIGH ie LED will be off according to our circuit

}

void loop() 
{
  Serial.println(analogRead(sw)); // reading and printing the values from analog pin A1

  if(analogRead(sw) >197 && analogRead(sw) <207 )
  digitalWrite(led1,LOW);// LED will turn ON
  else if(analogRead(sw) >248 && analogRead(sw) <258)
  digitalWrite(led2,LOW);// LED2 will turn ON
  else if(analogRead(sw) >333 && analogRead(sw) <343)
  digitalWrite(led3,LOW);// LED3 will turn ON
  else if(analogRead(sw) >509 && analogRead(sw) <514)
  digitalWrite(led4,LOW);// LED2 will turn ON
  else if(analogRead(sw) >1015 && analogRead(sw) <1023)
  digitalWrite(led5,LOW);// LED2 will turn ON
  

}

Multiple Switches Single Pin

Credits

Najad

Najad

30 projects • 96 followers
Just crazy stuff​

Comments