It is now time to test the project. As the most important part of the project is the relay module, that’s what we are going to test here. We are simply going to switch the powerswitch on and off continuously every 5 seconds, just to check that it is working.

At this point, you should already plug a device (like the lamp I used as an example) into the project and connect the switch to an electrical socket, to see that all the connections are correctly made.

It starts by declaring on which pin the switch is connected to:

const int relay_pin = 8;
In the setup() function of the sketch, we set this pin as an output:

Then, in the loop() function of the sketch, we set this pin to a HIGH state, switching on the powerswitch:

digitalWrite(relay_pin, HIGH);
And wait for 5 seconds:

We then switch it off again:

digitalWrite(relay_pin, LOW);

And wait for 5 seconds before repeating the loop() function:


Note that you can find all the code for this part inside the GitHub repository of the project:

It’s now time to test the sketch. Make sure that the lamp is correctly connected to the project, and that the male plug is plugged to the mains electricity. Then, upload the Arduino sketch to the board. You should see that every 5 seconds, the powerswitch is switching, turning the device connected to it on and off.

This guide was first published on Sep 08, 2014. It was last updated on Sep 08, 2014.

This page (Testing the Project) was last updated on Jan 31, 2021.

Text editor powered by tinymce.