Using One Analog Pin to Read 4 Buttons - Arduino

by udubinsky in Circuits > Arduino

3734 Views, 40 Favorites, 0 Comments

Using One Analog Pin to Read 4 Buttons - Arduino

resistor_sensing_for_areas_seperation.jpg

The idea is to read the resistanse differense between them using resistors.
The buttons are connected in such way that each button add the resistors of the buttons before him to a serial out put.

I used 4 220ohm resistors and 4 buttons.

int sensorPin = A0;    
int sensorValue = 0;
void setup() {
  pinMode (sensorPin, INPUT_PULLUP);
  Serial.begin (9600);
}
void loop() {
  sensorValue = analogRead(sensorPin);    
  sensorValue =  (map (sensorValue, 18,44, 1, 5));
  if (sensorValue < 5 ) Serial.println (sensorValue); 
}