Example - 03 : Controlling other electronics (Relay)
WHAT ARE WE DOING HERE?
This example showcases how to use the Grove-relay module to control a larger load, i.e. a desk
lamp light. A 3V voltage signal can cause the relay to switch on, allowing current to flow through
the connected appliance.
WARNING special care should be taken when using the Relay.
THE CIRCUIT
● Grove-Relay x1
● Grove cable x1
● Grove-Base BoosterPack x1
● LaunchPad Development Kit
Connections:
Plug the relay module into Grove connector
J14 on the BoosterPack. This will link the SIG
pin of the relay to pin 39 of the LaunchPad.
CODE
This is essentially the same as the blink LED code from Example #1. In this case, we are simply
opening & closing the relay switch once per second.
This example is available here: File > Sketchbook > LaunchPad_Kit > Grove_Modules > relay
Relay
The basic Energia example.
This example code is in the public domain.
*/
#define RELAY_PIN 39
// the setup routine runs once when you press reset:
void setup() {
pinMode(RELAY_PIN, OUTPUT); // initialize the digital pin as an output.
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(RELAY_PIN, HIGH); // turn the relay on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(RELAY_PIN, LOW); // turn the relay o by making the voltage LOW
delay(1000); // wait for a second
批注 [10]: update to proper file location
批注 [11]: update to latest code