Using Relay In Intel Galileo

In this article on IoT, I'll show you how to control Relay using the Galileo board. The Relay is basically an electrically controlled mechanical switch. Inside the Relay there is a plastic box that acts as an electromagnet when its energy causes a switch to trip.
  • Galileo
  • Bread Board
  • Led
  • Relay
  • Some Wires
  • Diode
  • NPN Transistor
  • Resistor  
  • Relay to digtial Pin 5
  • Relay Gnd to Gnd 
  • Anode pin to the 13
  • Cathode pin to the Gnd
  1. const int Relay=5;  
  2. int led=13;  
  4. void setup()  
  5. {  
  6.   pinMode(Relay,OUTPUT);  
  7.   pinMode(led,OUTPUT);  
  8. }  
  9. void loop()  
  10. {  
  11.   if(led == 13){  
  12.   digitalWrite(Relay,HIGH);  
  13.   digitalWrite(led,HIGH);  
  14.   delay(100);  
  15.   }  
  16.   else{  
  17.   digitalWrite(Relay,LOW);  
  18.   digitalWrite(led,LOW);  
  19.   delay(100);  
  20.   }  
  21. }  
The Relay will act like an on and off  switch, for that we sketch the program here. Make relay as const value in digital pin 5 and led as 13th pin in setup function. Set the pinMode for led and Relay and in the loop function, we want to give the condition for relay and how it wans to work; it takes the condition from the led pin. 
  1. if(led == 13){    
  2.   digitalWrite(Relay,HIGH);  // Relay ON  
  3.   digitalWrite(led,HIGH);    // LED ON
  4.   delay(100);    
  5.   }    
The above condition is true, which means the Relay is ON and Led also ON, or else the condition is false which means both will be in the off condition. 

Read more articles on Internet of Things: