Control Pin with Button

Learn how to react to a button press and toggle a LED in result

  1. joaomgcd
    IMPORTANT: Install the following sketch on your Arduino to use AutoArduino: https://github.com/joaomgcd/AutoArduino-Sketch/blob/master/pins.ino

    STEP 1 - CONNECT LED TO ARDUINO


    • Create a circuit like in this tutorial
    • Connect negative (shorter) end of the LED to GND on the Arduino
    • Connect positive (longer) end of the LED to Pin 4 on the Arduino


    STEP 2 - CREATE PROFILE


    • Create a new profile with the AutoArduino Input Changed event condition
    • Select Pin 3 under Pins
    (i) This will make this event trigger every time a change in pin 3 is detected
    • Select LOW and HIGH under Values
    (i) This will make this event trigger both when the pin is HIGH or LOW
    • Accept settings and create a Task associated with this profile


    STEP 3 - SHOW STATE CHANGE


    • Add a flash action and set the text to %aapin %aastate
    (i) This will show the number and state of the pin that changed in this event. The state can be either 0 if the pin is LOW or 1 if the pin is HIGH.


    STEP 4 - CHANGE LED STATE


    • Add an AutoArduino Write Pins action
    • Click on Direct Command
    • Write the text d4,%aastate;
    (i) This is a command that will change pin 4 to whatever state is in the %aastate variable. So, if %aastate is 0, pin 4 will be set to LOW, if it's 1, pin 4 will be set to HIGH. Since a LED is connected to pin 4 it'll change the state of the LED. If you want to learn more about the command format check the little (i) icon at the top right of this screen
    • Back out of Tasker to Save your new profile


    STEP 5 - TEST


    Make sure you are connected to your Arduino with AutoArduino so you can receive events. Check step 2 here to learn how to do that.

    Now when you press the button it'll set Pin 3 to LOW which will make the AutoArduino event you just configured fire, which in turn will set Pin 4 to LOW, making the LED turn off.

    On the other hand, if you release the button it'll set Pin 3 to HIGH which will set pin 4 to HIGH making the LED turn on!