Design a site like this with
Get started

Arduino Dip-Switch Binary Adder

  • Wire the Dip-switches to ground on one side with 1Kohm resistors.
  • Wire the Dip-switches to Digital and Analog input pins D7-D10, A0-A3
  • UseINPUT_PULLUP in the code to indicate the negative wiring.
  • Treat the Analog input pins as digital by using digitalRead() instead of analogRead() .
  • Wire the LCD according to instructions found here on the website.
  • The left Dip-switch acts as input for the first binary integer. The second Dip-switch acts as input for the second binary integer.
  • Two different functions, digital_binary_to_int(), analog_binary_to_int() convert the binary inputs to decimal.
  • The Arduino adds the two decimal numbers together & displays them on the LCD screen.

The Code

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
  // Digital Pins 10,9,8,7 are for binary input 
  // for the left Dip-Switch.
  // INPUT_PULLUP is used since the DipSwitches
  // are wired to ground.
  pinMode(10, INPUT_PULLUP);
  pinMode(9,  INPUT_PULLUP);
  pinMode(8,  INPUT_PULLUP);
  pinMode(7,  INPUT_PULLUP);
  // Analog Pins A0, A1,A2, A3 are for binary input
  // for the right Dip-Switch.
  pinMode(A0, INPUT_PULLUP);
  pinMode(A1,  INPUT_PULLUP);
  pinMode(A2,  INPUT_PULLUP);
  pinMode(A3,  INPUT_PULLUP);

int digital_binary_to_int()
  int a = digitalRead(10);
  int b = digitalRead(9);
  int c = digitalRead(8);
  int d = digitalRead(7);
  return a*1 + b*2 + c*4 + d*8;

int analog_binary_to_int()
  float a = floor(digitalRead(A0));
  float b = floor(digitalRead(A1));
  float c = floor(digitalRead(A2));
  float d = floor(digitalRead(A3));
  return d*1 + c*2 + b*4 + a*8;

void loop()
  String output_add;
  int x = digital_binary_to_int();
  int y = analog_binary_to_int();
  int ans = x + y;
  output_add = String(ans);


0101 + 1001
Remember to check the Endian configuration.

Link to the TinkerCad Project


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: