
PinMode(BUTTON_PIN, INPUT_PULLUP) // set arduino pin to input pull-up mode Int currentButtonState // the current state of button Int lastButtonState // the previous state of button Int relayState = LOW // the current state of relay Arduino Code – Button Toggles Relay Without Debouncing const int BUTTON_PIN = 7 // Arduino pin connected to button's pinĬonst int RELAY_PIN = 3 // Arduino pin connected to relay's pin

Now copy the following code and upload it to Arduino IDE Software.
#Control high voltage devices arduino relay tutorial how to
Here is a simple step-by-step guide on “ How to Add Libraries in Arduino IDE“.

Installing Librariesīefore you start uploading a code, download and unzip the following libraries at /Progam Files(x86)/Arduino/Libraries (default), in order to use the sensor with the Arduino board. Here is a simple step-by-step guide on “ How to install Arduino IDE“. Make connections according to the circuit diagram given below.įirst, you need to install Arduino IDE Software from its official website Arduino.

Connect the pushbutton to pin 2, the relay module to pin 8, and the AC appliance to the relay module.
