Arduino Nano - Button - Relay
This tutorial instructs you how to use the Arduino Nano and button to control the relay. By connecting the relay to a soleniod lock, light bulb, LED strip, motor, or actuator..., we can use a button to control the them. We will learn two different applications:
Application 1 - The relay state is synchronized with the button state. In detail:
- Arduino Nano turns on the relay when the button is being pressed.
- Arduino Nano turns off the relay when the button is NOT being pressed.
Application 2 - The relay state is toggled each time the button is pressed. More specifically:
- If Arduino Nano detects that the button has been pressed (changing from a HIGH state to a LOW state), it will turn ON the relay if it's currently OFF, or turn OFF the relay if it's currently ON.
- Releasing the button does not affect to the relay state.
In the Application 2, We need to debounce the button to make sure it works properly. We'll see why it's important by comparing how the relay behaves when we use the Arduino code with and without debouncing the button.
Or you can buy the following sensor kit:
|DIYables Sensor Kit 30 types, 69 units
This image is created using Fritzing. Click to enlarge image