Components Required

Image Component Quantity Available in Kit
evive 1
10 kOhm Resistor 1
Pushbutton 1
Male to Male Jumper Cable 20cm 3
USB A-B Cable 1

Introduction

Switch is a component which controls the open-ness or closed-ness of an electric circuit. Hence, the switch is open, circuit is broken and no current flows though the circuit. But when the switch is close current flows through it.

A switch can be of different type:

  • Maintained switches – like the light switches on your wall – stay in one state until actuated into a new one, and then remain in that state until acted upon once again.
  • Momentary switches only remain active as long as they’re actuated. If they’re not being actuated, they remain in their “off” state.

Interfacing switch with evive

Let’s say you have evive with one digital pin configured as an input. If there is nothing connected to the pin, and your program reads the state of the pin. Will it be high or low? It is difficult to tell. This phenomena is referred to as floating. To prevent this unknown state, a pull-up or pull-down resistor is connected in-between that ensure that the pin is in either a high or low state, while also using a low amount of current. While using switches you use pull-up or pull-down resistors. With a pull-up resistor, the input pin will read a high state when the button is not pressed. In other words, a small amount of current is flowing between VCC and the input pin (not to ground), thus the input pin reads close to VCC. When the button is pressed, it connects the input pin directly to ground. The current flows through the resistor to ground, thus the input pin reads a low state.

Pull Up Configuration

Hence, when the switch is not pressed, you get a HIGH reading on the digital pin and when the switch is pressed you get a LOW reading, when you are using pull-up resistor. Generally you use a resistor of 10 kohm. If you are using pull-down configuration, the result is exactly opposite.

Pull-up resistor example:

In this example we will change the state of the LED each time you press the switch. Build the circuit given below using a tactile switch, evive, 10k Ohm resistor, and jumper wires.

Circuit Diagram

Pull Up Circuit

Logic Chart

You can observe that the above configuration is pull-up configuration. For the above configuration the flow chart is given below.

Pull Up Flow Chart

Arduino IDE Sketch

Pull-down resistor example

With a pull-down resistor, the input pin will read a low state when the button is not pressed. In other words, no current is flowing between GND and the input pin , thus the input pin reads close to GND. When the button is pressed, it connects the input pin directly to VCC. The current flows through the resistor to ground, thus the input pin reads a high state.

Pull Down

In conlusion, when the switch is not pressed, you get a low reading on the digital pin and when the switch is pressed you get a high reading, when you are using pull-down resistor.

In this example also we are doing the same thing as above. Given below is the circuit diagram, flow chart and the Adruino IDE sketch.

Circuit Diagram

Logic Diagram

Pull Down Flow

Arduino IDE Sketch