Page
Stránky / Súčiastky ku Arduinu /
The relay is a component that lets you control other electrical devices. It works as a switch. On the one side it is controlled by electrical signals and, on the other side, it can turn on or off another electric circuit. It is possible to buy a separate relay or buy a whole module that contains additional components that make it easier to control the relay.
Inside the relay, the solenoid switches the contacts mechanically. These are not connected to the control part of the relay and therefore you can switch any electrical circuit. You can also control electrical devices that are connected to an alternating current.
On the other hand, the relay clicks audibly. Since this is a mechanical contact, the relay as a switch is a slow component and can not be controlled by a PWM signal.
Relay modules are usually connected differently than you would expect. It is important to buy a module that suits your requirements. Some relays require higher voltages that Arduino can not deliver. Here is a relay that can be operated at a voltage of 5 V. The logic side has three terminals:
There are three pins on the output side. On this module, they are not numbered but with small pictograms. They work so that pin 2-1 or pin 2-3 is always connected.
I have modified the Blink program to test the relay. The LED diode is on pin 9 and the intervals are set to 2 seconds. This gives you time to monitor relay behavior.
int led = 9;
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(2000); // wait for 2 second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(2000); // wait for 2 second
}
The source code is located on the GitHub server.
20.03.2018