Hardware Reference
In-Depth Information
2.3
Testing the Relay
It is now time to test the project. As the most important part of the project is the relay mod-
ule, this is what we are going to test here. We are simply going to switch the relay on and
off continuously every 5 seconds, just to check that the relay is working correctly. At this
point, you can 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.
This is the complete code for this section:
// Sketch to test the relay
// Relay pin
const int relay_pin = 7 ;
void setup () {
pinMode(relay_pin,OUTPUT);
}
void loop () {
// Activate relay
digitalWrite(relay_pin, HIGH);
// Wait for 5 seconds
delay( 5000 );
// Deactivate relay
digitalWrite(relay_pin, LOW);
// Wait for 5 seconds
delay( 5000 );
}
Note that all the files are available on the GitHub repository of the topic:
https://github.com/openhomeautomation/iot-book
 
Search WWH ::




Custom Search