Arduino LED - Hold Button 3s to Turn ON & 3s to Turn OFF

by RonFrtek in Circuits > Arduino

1442 Views, 2 Favorites, 0 Comments

Arduino LED - Hold Button 3s to Turn ON & 3s to Turn OFF

Arduino LED - Hold Button 3s to turn ON & 3s to turn OFF

In this project we will learn how to to Turn the LED ON or OFF by pressing a button for 3s.

Watch the Video!

What You Will Need

button module red 2-1000x1000.jpg
FMT2X9VKEY93G5P.jpg
djownload.jpg
redled.jpg
VisuinoAdvrtisementNewDesign1.jpg
arduino.jpg
  • Arduino UNO (or any other Arduino)
  • Button module
  • 200 ohm resistor
  • Jumper wires
  • LED
  • Visuino program: Download Visuino

The Circuit

2021-06-10_18-23-04.jpg
  • Connect Button1 pin [VCC] to Arduino positive pin[5V]
  • Connect Button1 pin [GND] to Arduino negative pin[GND]
  • Connect Button1 signal pin [S] to Arduino digital pin[4]
  • Connect LED positive pin [+] to 200 ohm resistor
  • Connect other side of the 200 ohm resistor to Arduino digital pin[11]
  • Connect LED negative pin [ - ] to Arduino negative pin[GND]

Start Visuino, and Select the Arduino UNO Board Type

FMW5CHBKFV47BP9.jpg
F311FBVK5AHN5HJ.LARGE.jpg

The Visuino: https://www.visuino.eu also needs to be installed. Download Free version or register for a Free Trial.

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

In Visuino Add & Set Components

2021-06-10_13-41-53.jpg
2021-06-10_13-42-16.jpg
2021-06-10_13-44-25.jpg
2021-06-10_13-44-55.jpg
2021-06-10_13-27-27.jpg
2021-06-10_13-28-18.jpg
2021-06-10_13-29-21.jpg
  • Add "Clock Generator" component
  • Add "Counter" component
  • Add "Compare Integer Value" component
  • Add "Toggle(T) Flip-Flop" component
  • Select "ClockGenerator1" and in the properties window click on the "Enabled" pin icon and select "Boolean SinkPin"
  • Select "Counter1" and in the properties set Max>Value to 3 and Min>Value to 0
  • Select "CompareValue1" and in the properties set Value to 3, Only Changed to False, Compare Type to ctBiggerOrEqual

In Visuino Connect Components

3sbutton.png
2021-06-10_13-26-46.jpg
2021-06-10_13-26-25.jpg
  1. Connect Arduino digital pin [4] to Counter1 pin [Reset] and ClockGenerator1 pin[Enabled]
  2. Connect ClockGenerator1 pin [Out] to Counter1 pin [In]
  3. Connect Counter1 pin [Out] to CompareValue1 pin [In]
  4. Connect CompareValue1 pin [Out] to TFlipFlop1 pin [Clock]
  5. Connect TFlipFlop1 pin [Out] to Arduino Digital pin [11]

Generate, Compile, and Upload the Arduino Code

2020-10-30_13-20-50.jpg

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Play

If you power the Arduino module, and Hold the button for 3s the LED will turn ON, if you again Hold the button for 3s the LED will turn OFF.

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Instructable, you can download it and open it in Visuino: https://www.visuino.eu