USocket – USB controlled Socket with PIC18F4550
The idea of this project is to control (switch off/on) two power sockets with a computer by using its USB port. I’ve chosen USB in first place because I wanted to experiment with the PIC18F4550 microchip’s microcontroller, and secondly because the power supplied by this port (500mA) is enough to activate a relay without any additional power supply.
The firmware is based in SIXCA USBDAQ which is in turn based on microchip’s CDC sample. USBDAQ is extremely easy to use. It implements a very simple set of ASCII commands to turn on/off the digital outputs, that I use to control the two relays. I just needed to adjust the bMaxPower in order to negotiate the 500mA with the host, and I also changed the vendor ID and the name of the device to USocket.
I’ve also made the schematic and board design of the circuit with Eagle, but I never used it since I made it on a strip board , so if you plan to use it please double check everything before.
The whole project including PIC firmware and Eagle files is available for download. You are free to use or modify it as you like, but please verify Microchip’s CDC sample license if you plan to use it for commercial applications.
Disclaimer: This project involves high voltage electricity. You should not attempt this project unless you are comfortable with basic concepts of AC and DC electricity, induction, and reading circuit schematics. You and your adult supervisor are responsible for your safety when doing this project!
Advice: Despites the high voltage part of the circuit is virtually isolated from the controller circuit by relays, these devices always represents a risk of mechanical failure and they can possibly damage your equipment or even cause physical injuries, so we (the author or the webmasters) are not responsible of any lose or damage.
Pretty much the same as USBDAQ but two (identical) sub-circuits were added to control the relays. A Darlington-transistor is used to protect the hardware. Once again, the idea was obtained from the web (thanks to google) and here is the link to the original article.
The PCB is divided in 3 little boards, for commodity and socket case space issues. (I’ve used only 2 strip boards in the actual prototype).
List of materials:
- IC1 – PIC16F4550 Microchip’s micro-controller (datasheet)
- Q2 – Crystal 20Mhz
- R1 – Resistor 4.7K
- R2 – Resistor 1M
- R3, R5 – Resistors 150
- R4, R6 – Resistors 100K
- K1, K3 – 5v Relays. I’ve used FBR211 by Fujitsu (datasheet)
- D1, D2, D3. D4 – Diodes 1N4004
- Q1, Q3 – BC517 Darlington-transistors (datasheet)
- LED1, LED2 – Regular leds
- C1, C2 – Capacitors 22pF
- C3 – Capacitor 470pF
- X1 – Mini-USB Connector Type B (datasheet)
Here is what I needed to modify from the original SIXCA USBDAQ:
I set bMaxPower to 250, which means 500mA. The power provided by hosts and hubs is twice the value of bMaxPower field, but in reality they are likely to allocate either 100 or 500 milliamperes rather than the specified amount.
Programming the PIC
I’ve used WinPic800 to program the PIC. Here is a screenshot of the parameters I used to program it.
I didn’t modified any of the USBDAQ commands. They are all available but I only need to use these 4 commands:
- *A01 (activate relay 1)
- *A00 (deactivate relay 1)
- *A11 (activate relay 2)
- *A10 (deactivate relay 2)
All the commands are followed by an enter (chr(13) or ‘\n’).
For more detail: USocket – USB controlled Socket with PIC18F4550
We recommend EasyEDA for electronic circuit design.
From Schematic to PCB Production, Just Need One Tool
Free Circuit Design Software: learn to use Editor quickly and easily
Cheapest PCB: 10pcs 2-layers 10cm×10cm only $8.21, 3-day build time, 100% E-test
Current Project / Post can also be found using:
- pic18f4550 Microchip vendor id