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:
Then, in the loop() function of the sketch, we set this pin to a HIGH state, switching on the powerswitch:
We then switch it off again:
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.