Arduino Nano: Invert Button With Visuino

by BoianM in Circuits > Arduino

6094 Views, 44 Favorites, 0 Comments

Arduino Nano: Invert Button With Visuino

Arduino Nano: Invert button with Visuino

Buttons, and digital switches are one of the most often used sensors with Arduino. They are also easy to connect and use from code. Sometimes however the button or the switch provides True when we need False, and False when we need True. To compensate for this we need to invert the value in our code.

In this Instructable you will learn how to connect Button to an Arduino, and program the button to control the on-board LED, directly or with inverted value. It also will be a base for a number following Instructables that are in the works :-)

The programming will be done with the help of Visuino - an easy to use graphical development environment for Arduino.

Components

5675c88c45bceb565d00089e.jpeg
  1. One Arduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine )
  2. One Button Sensor module I got from this cheap 37 sensors set.
  3. 3 female-female jumper wires

Connect the Button to Arduino

5675c8b84fbade607100093f.jpeg
5675c8d44fbadefc6a00038c.jpeg
5675c6d64936d476f0000a3b.jpeg
5675c90115be4d21b9000157.jpeg
5675c7044936d476f0000a3c.jpeg
  1. Connect Ground(Black wire), Power(Red wire), and Data(Gray wire) to the Button Module (Picture 1)
  2. Connect the other end of the Power wire(Red wire) to the 5V power pin of the Arduino board(Picture 2)
  3. Connect the other end of the Ground wire(Black wire) to Ground pin of the Arduino board(Picture 2)
  4. Connect the other end of the Data wire(Gray wire) to Digital pin 2 of the Arduino board(Picture 3, and 4)
  5. Picture 5 shows where are the Ground, 5V Power, and Digital 2 pins of the Arduino Nano.

Start Visuino, Select the Arduino Board Type

SelectBoard.png
SelectBoard.png

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/.

Please be aware that there are some critical bugs in Arduino IDE 1.6.6.

Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino as shown in the first picture
  2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select Arduino Nano as shown in Picture 2

In Visuino: Connect the Button

Connect1.png
Connect2.png

Connect the "Out" pin of the "Digital[ 2 ]" channel of the Arduino component (Picture 1), to the "Digital" input pin of the "Digital[ 13 ]" channel of the Arduino component (Picture 2)

Generate, Compile, and Upload the Arduino Code

ComponentCompleteCropped.png
GenerateCtopped.png
ArduinoIDE1.png
  1. On the first picture you can see the completed Visuino diagram
  2. In Visuino, Press F9 or click on the button shown on Picture 2 to generate the Arduino code, and open the Arduino IDE
  3. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 3)

And Play...

DSC02448.JPG
DSC02452.JPG

As shown in Picture 1, when the button is Not Pressed, the LED on Pin 13 is ON.

If you Press the button, the LED will turn OFF (Picture 2)

Usually this is the opposite of what we want, so in the following steps we will invert the button to fix this.

In Visuino: Add Inverter Component, and Connect It

ComponentInvert.png
ComponentInvertConnect1.png
ComponentInvertConnect2.png
ComponentInvertCompleteCropped.png
  1. Type "inv" in the Filter box of the Component Toolbox then select the "Boolean Inverter" component (Picture 1), and drop it in the design area
  2. Connect the "Out" pin of the Digital[ 2 ] channel of the Arduino component to the "In" pin of the Inverter(Picture 2)
  3. Connect the "Out" pin of the Inverter to the "Digital" input pin of the Digital[ 13 ] channel of the Arduino component (Picture 3)
  4. The old connection between Digital[ 2 ], and Digital [ 3 ] will automatically be removed (Picture 4)

Generate, Compile, and Upload the Arduino Code

GenerateCtopped.png
ArduinoIDE2.png
  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

And Play...

DSC02439.JPG
DSC02444.JPG

As shown in Picture 1, when the button is Not Pressed, the LED on Pin 13 is OFF.

If you Press the button, the LED will turn ON (Picture 2)

This is exactly what we want :-)

Congratulations! You are now master of your Arduino connected button...

Also attached in the ZIP are the two Visuino projects, that I created for this Instructable. You can download and open them in Visuino: https://www.visuino.com