gczuloo.blogg.se

Control high voltage devices arduino relay tutorial
Control high voltage devices arduino relay tutorial







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

control high voltage devices arduino relay tutorial

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“.

control high voltage devices arduino relay tutorial

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.

  • Press the button and observe the relay state toggle on the board and the serial monitor.
  • Open the serial monitor and set the baud rate to 9600.
  • Upload the sketch to the Arduino UNO board.
  • Use the serial monitor to display the current state of the relay:.
  • Use an if statement to check if the button has been pressed:.
  • Int buttonState = digitalRead(buttonPin)
  • In the loop() function, read the state of the pushbutton:.
  • In the setup() function, configure the pushbutton and relay pins as inputs and outputs:.
  • Declare a variable to store the current state of the relay:.
  • Declare the pin numbers for the pushbutton and relay module as constants:.
  • Open the Arduino IDE and create a new sketch (program).
  • control high voltage devices arduino relay tutorial

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







    Control high voltage devices arduino relay tutorial