Sunday, November 11, 2012

Time Switch_5: Driving a relay.


In the previous post I mentioned about the designing the alarm. Now it’s the time to drive just one light. Within the microcontroller we don’t need to do much, just one or two entries. But in hardware we have some new things coming in to our design to facilitate the tripping of the light.

Following image will let you know how to connect the relay to the circuit.


We should connect the microcontroller to the Base of the transistor and then the transistor to the relay. That is because the current from the microcontroller is not enough to drive the relay and we need to amplify it using the transistor. The D1 diode is used to provide a current path in the transient stage of the solenoid inside the relay.


Following is the relay connected to the microcontroller.


Finally we should alter the program inside the microcontroller. Following is the alteration we need. There what we do is instead of driving the LCD we program microcontroller so that it will drive the relay by making a pin in microcontroller HIGH.

void interrupt(){

INTCON.GIE = 0;            // global interrupts disabled
if(INTCON.T0IF){             // handling the timer0 interrupt
timer_val++;
if(timer_val == 15000){          // 19531.25 overflows per second
timer_sec++;
timer_val = 0;

 if(timer_sec = 60){
  //minute
time_val--;
 i(time_val == 0){

PORTA.RA0 = 1;

 }
 }
 timer_sec = 0;
}
}
}
INTCON.T0IF = 0;           // clearing the interrupt flag bit
INTCON.GIE = 1;             // enabling global interrupts
}

That's basically it.

Thank you.


No comments:

Post a Comment