Step 5- A simple input device connection

If you are following our previous blogs (#1, #2, #3, #4), you would realize that so far we worked on connecting an LED (an output device!) to Genuino controller board. A microcontroller (in this case, the Genuino processor) can write (or show) data to an output device. But What if you want to write (or send) data to the microcontroller? Here we will take up a simple input device connection.

Switch – An Input Device!

An input device connects the physical world with the microcontroller system by providing input to it. It means, in simple terms, microcontroller can read the data from an input device. A simple switch is a common example of a binary input device – based on switch position, the microcontroller reads the value – on / off or high / low or 1 / 0.

Switches and logic output symbols

Based on how a switch is connected, it can give HIGH (or logic 1), or LOW (or logic 0) signal that can be read by a microcontroller.

Let’s try it! – Making an input device connection

The grove kit also includes a bunch of input devices. We will look at ‘push button’ module first. We will connect a button module and LED module to the Genuino board using Grove Base Shield and then turn the LED on when button is pressed.

So let’s take out the Genuino board, Grove Base Shield, a connector, LED module with an LED and button module. Connect then as show below:

  1. You will have to put the Grove base shield on top of Arduino
  2. Connect the LED module to D3 of base shield using connector cable
  3. Insert the LED into the LED module – take a note of polarity! The shorter lead or one near the flat spot is the ‘cathode’ or ‘negative’ terminal of the LED.
  4. Connect the button module to D2 of the base shield using connector

INput device connection - LED and Switch Connection

and, like always, we follow the 4 basic steps:

  1. Connect the Genuino board to computer using USB cable
  2. Open the Arduino IDE (the software)
  3. Open the sketch – BUTTON example code using the menu: File > Examples > 02.Digital > Button
  4. Ensure the BOARD and PORT settings are correct: Tools > Board & Tools > Port

In the sketch, you’ll have to modify the ‘LED Pin’ from 13 to 3, as we connected the LED module to D3.

Button sketch

Compile and upload the sketch, you should see LED glow whenever the button is pressed.

Can you do it?

  1. Try making the LED blink (1 flash per second) as long as button is pressed. LED should turn off when button is released.
  2. You may also like to try another variant – The LED flashes as long as button is pressed. Releasing of button make LED retain its state i.e., if the button is released when LED was on, it should remain ON (or vice versa).


Leave a Reply

Your email address will not be published. Required fields are marked *