Showing posts with label relay. Show all posts
Showing posts with label relay. Show all posts

Sunday, January 1, 2012

How Fast Relays Are?

From the time I learned about relays, I wondered if they can be used to make an H-Bridge for motors, I asked my professor and he said that you can't because they are slow.

I never knew how slow, till today, so I wrote a small code on my AVR ATmega168 microcontroller

basically, the code send an ON -> delay(x) -> OFF -> delay(x)

where x is a value (in ms) changing every time a button is pressed going down from 15 ms to 1ms

1:  #include <avr/io.h>  
2:  #include <util/delay.h>  
3:  #include <USART.h>  
4:  #define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))  
5:  #define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))  
6:  int main(void)  
7:  {  
8:       init_uart();  
9:        SETBIT(DDRB,0);  //Output pin (ON/OFF)
10:       CLEARBIT(DDRB,1); //Input to change time
11:       SETBIT(PORTB,1);  //Enable Pull-Up resistor
12:       for (;;)  
13:       {  
14:            for (uint16_t i=15; i>0; i--)  //repeat 15 times going down, used as delay
15:            {  
16:                 printf("i=%d\n",i);  //just to see whats the current delay value
17:                 _delay_ms(100);  //give me time to release button
18:                 while ((PINB & 0x02)==0x02)  //loop when I don't press button
19:                 {  
20:                      SETBIT(PORTB,0);   //ON
21:                      _delay_ms(i);      //i value as delay
22:                      CLEARBIT(PORTB,0); //OFF 
23:                      _delay_ms(i);
24:                 }  
25:            }  
26:       }  
27:       return 0;  
28:  } 

And then connected the relay, driving it with a NPN



I found that min time is 2ms, at 1ms, no switching will occur ( i was getting highly rippled 5v)



and here is an awesome sound of 1~15ms switching, at 0:16 the time is 1ms



~2ms (500Hz) is the min time (max freq) u can switch a typical relay




Friday, November 11, 2011

NetHome

I am extremely happy today, I am almost done with Light Control through Ethernet. I can't believe it was soooo easy!

I started this project about a week ago, not a new idea or any thing, it is for my own educational purpose

NetHome

I started with a rough sketch of the idea (pictures are hi res so it will take time to load)


After getting the required components I started implementing directly



5v power is supplied from USB, 3.3v regulator is used for the webserver WIZ200Web from Sparkfun

Relay PCB, to control the 220 VAC


Powering up!


Yay its working, now feedback sensor, Miniature Solar Cell



WIZ200Web - web server (from sparkfun)

Using this guy was awesome, only need to connect two 3.3v pins, four GND pins, Rx0, Tx0. Then from PC use configuration tool to connect/configure and download firmare/webpages.



Below, I was testing in external ATmega168 before using the server (which has ATmega128 with pins you can use for I/O ADC etc)




Ethernet link - blinking!



webpage:




I've connected my relay driver to PB4 pin (on J2) which is LED0 on the WIZ200web development board, so I was able to control the light.


After that I decided to make two interfaces, one from PC "PC Station" and an "Android Station" and maybe also "iPhone Station"

I started with the simplest, "PC Station" for which I used Visual Basic:






The PC Station is working fine, however, there is small problems with changing the IP Address, if the connection is successful and I tried to change the ip address, it would still say "connected"
Also, I've not implemented Syncing data yet

Since It is working, I thought I'd move to the next step, Android!

The UI on Virtual Manager





I am able so far to toggle the picture ON/OFF, however, I am still looking for how to control the light :D


.