Instructions for controlling 230 V sockets with Arduino

The example shows how to control the sockets remotely or automatically using Arduino. With this solution, you can use the basic elements of a smart home.

The following elements are used in the example:

At the beginning the library should be added to Arduino environment (Sketch -> Include Library -> Add .ZIP Library...).

Connecting the receiver

To control the outlet, you must first read the codes from the remote control connected to the outlets. For this purpose we will use the receiver connected to Arduino.

Pins of the receiver

Pin Description
1

VCC - power supply

2 DATA - data pin
3 DATA - data pin
4 GND - system weight

Now connect the appropriate receiver pins from Arduino:

Connection

Pin Arduino Pin of the receiver
GND pin 1 - GND
D2 pin 2 or 3 - DATE
+5 V pin 4 - VCC

Then the program part. Open example ReceiveDemo_Advanced from included library (File -> Examples -> RCSwitch -> ReceiveDemo_Advanced) and upload it to Arduino.

Now with serial monitor (Tools -> Serial monitor) it is possible to read codes from remote control . Obtained values should look like on the screen below:

The first two lines are the button turning on the socket, the next two lines are the button turning off.

Connecting the transmitter

To connect the transmitter to Arduino, please refer to the pins of the transmitter:

Transmitter pins

Pin Description
1 DATA - data pin
2 VCC - power supply
3

GND - system weight

Now connect the appropriate transmitter pins from Arduino:

Connecting

Pin Arduino Transmitter pin
GND pin 1 - GND
+5 V pin 2 - VCC
pin 10 pin 3 - DATE

Programme code used

#include 
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.setPulseLength(325); // Wartość odczytana z serial monitora
mySwitch.enableTransmit(10); // Pin, do którego podpięty jest nadajnik
}
void loop() {
mySwitch.send("000000000000010101010001"); // Kod binarny z pierwszego przycisku
delay(5000);
mySwitch.send("000000000000010101010100"); // Kod binarny z drugiego przycisku
while (1); // Nieskończona pętla
}

The above code turns on the socket, then turns it off after 5 seconds.

Botland.store - shop for makers!