navigationGo.pngQuick Navigation
allprojects32.pngAll projects

favoriteStar32.pngTop projects
Alan numitron clock
Clapclap 2313/1386
SNES Pi Webserver
USB Volume/USB toys
Smokey amp
Laser cutter
ardReveil v3
SNES Arcade cabinet
Game boy projects
Home Presence Detector


navigationMail.pngContact me

3flags.pngWho's Alan?

Rand Nerd Tut
Datasheet Lib
Reddit Elec
Carnet du maker (fr)
ATmel blog (defunct)


kalshagar - noardPowerSwitch
FOREWORD : this is all based and cloned to a few details to the excellent solution you can find here. All credits for the author, I'm just making small variation based on his work :


Same project as ardPowerSwitch, except without an Arduino!
Have a windows interface to controll on/off different things plugged around your pc. Ie, turn on/off that DVD reader that you use once a while and that has that annoying switch behind the case under the pc itself under the tv (see what I mean ?). It's a smart version of Auto USB power box, using 5Amp relays to drive power-hog DVD reader, sound system, ...
This project is a good pretext for:
  • Playing with relays
  • Implement USB without RS232 or other FTDI chip but using the great library V-USB
  • More chance to burn down my place (do NOT play with AC power if you don't know what you're doing)
  • Continue the fun after the Clapclap that turns light on in my room


20110102: well after a few weeks this project stated, I finally managed to make it work with a ATmega328 (using the M.Ishikawa's library ) to discover that on Windows 7 64bits Japanese (which happen to be my pc) you can't have this work without you windows running in some test mode for drivers, launching some weird applications, rebooting many times,... and finally having still not work that much. Big deception... So let's forget that and move to the HID solution that should work without a driver.




Preparatory work

Power considerations

external image voltage-reduction-with-diodes.gif
Ok, USB VCC/GND is a nice 5v BUT the Data wires (D%20/D-) are 3.3volters. How to solve this ? It's explained here, don't try to be the smart-a$$ :
For the records, I used the solution A, 2nd variation : meaning diode in serial to artificially create a approximative 3.3v VCC. I use 2 diodes in serial and get the predictable 3.6v which I hearsay is "acceptable". Cheap and easy, hope it will work. Btw, ATmega runs fine in 1.8-5.5v range, so no worries. That VCC will trigger the transistor that will drive the relay, but those will use the original USB 5v Vcc to be turned on (transistor C-E).


You must use a 12Mhz crystal, not 16Mhz. The library CAN work with 16 Mhz but the code as it is now cannot. So use a 12 Mhz crystal.

Setup the ATmega328

Since in my solution I use a 16 12 MHz crystal, you have to set the fuses accordingly (this is not the default settings, that is internal RC Oscillator with scale of 8 => you run at 1 Mhz)
You should use this site for calculating the fuse or blindingly type the following
#SET fuses to use a external crystal (sends an error in the end but just worked fine ... mystery)
avrdude -v -v -p m328p -c avrispv2 -P COM1 -U lfuse:w:0xf7:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m

Setup the Attiny2313


Code upload

I use the Pololu programmer, cheap and works just fine, nice baby. I had to solder the ISP programmer (waste of time but spares swapping the chip between my arduino and the board for tests). Note that on the ISP the Vcc I linked is the 5v USB one, not the 3.3v. Programmation seems to work just fine for now.
This time I can't use the trick "code in Arduino IDE, compile and upload the .hex to the chip", since the libraries used will mostly not work. I will try with Programmers Notepad delivered with WinAVR (a must have!)


All content on this site is shared under the MIT licence (do what u want, don't sue me, hat tip appreciated) ~ Formerly known as (AlanFromJapan [2009 - 2019])