2017-02-26

Injecting power into mains

This title sounds scary. In fact it really is :-)

I have long been experimenting with various solar panels initially to try to make some devices more autonomous (eg: self-recharging hexapod robot, long-lasting outdoor camera, etc) and noticed that solar panels have become very cheap and that low quality batteries can also be reasonably cheap. I started to think "what if I used a lot of batteries to power some of my home appliances like servers, water heater, etc?".

Let's do some math. Looking at my electricity invoice, I'm using on average 800W between february and august, and 1400W between august and february. I don't have more details, and both periods include some cold periods where the heating is used. I suppose that taking heating out of the equation I probably need
about 400W on average (light, PCs, water heating).

In order to deliver 400W 24 hours a day with 8 hours of charging, I'd need to charge at 1200W and to store 9.6 kWh of energy. A correct LiPo cell stores 2.6Ah at 3.7V, or 9.6Wh. Thus I'd need 1000 such batteries just to store the required energy. At about $2-3 a battery it's not interesting.

But I thought, why would I need batteries ? Two thirds of my consumption are during the day and one third at night. And these are differently priced so that the day is more expensive (15cts/kWh during day, 10cts at night). So by using 400W of direct solar energy I could expect to be able to cut the day consumption in half, resulting in a 37.5% overall saving on the daily bill.

This approach sounds interesting because it uses 3 times less solar panels and no batteries. But how to power devices on irregular energy sources ?

My idea was that if it were possible to inject the solar energy directly into the mains synchronized with the alternating current, I could in fact offload the energy provider from the energy I harvest from the sun, so that I don't have to care when a cloud passes. But it's possibly very hard to keep in sync with mains...

Then I started to think about some ZVS induction heaters I've made in the past, these ones are resonant self-oscillating circuits. Wouldn't it be possible to do this with mains ? That is, monitor the mains voltage to decide what polarity to send into a transformer ? After all in order to monitor the mains, I just need another independant transformer that's not too much affected by the power I feed into the secondary coil. Thus I ran an experiment with two miniature transformers (12V/1.2VA each) installed behind a 12/230V DC/AC converter (I prefer to use this than real mains during experiments like this). Impressively this worked pretty well out of the box, I could cancel the power consumption of the primary transformer.

That immediately made me think about these old transformers I salvaged from a dead UPS, I remembered they had some additional windings. I took one of them, a 400VA model, measured the voltage across its terminals and found that it matched the markings : 8V symmetric on a 50A circuit (designed to take 12V peaks on its input to produce the 325V peaks), and 14.5V on a low power circuit. This last one would be used to monitor the mains polarity. As long as I don't feed too strong a current, mains will always win and impose its polarity, and this monitoring winding would force the mosfets to reverse the current.

So I came up with the following diagram :

The primary (left part) of the transformer is connected to a power meter and to a 8W/230V lamp. The power meter is connected to the 12/230 converter for now. The assembled circuit looks like this (the MOSFETS are IRFB4110, they are directly mounted on the transformer terminals) :



The wave across the 14V monitor winding looks like this :



It's obvious that my 12/230 converter doesn't provide a sine wave, it's almost a square one! That's optimal to drive the transistors but it doesn't reflect reality. Since I had no smoke and I could manage to cancel the power usage by adjusting the DC voltage, I restarted the experiment plugged to real mains this time after double-checking every connection. The wave across the 14V winding looks much better :



The power meter showed that the transformer alone draws 4W of power and the lamp draws another 8W, leading to 12W total :



I progressively adjusted the input DC voltage until I saw exactly 0W on the power meter. The DC input showed 8.8V and the amp meter showed 2.26A, that's 19.9W total consumed power to produce 12W of power needed to power the lamp and the transformer losses resulting in 0W on the power meter  (I'm not cheating here, except by carefully adjusting the voltage to reach exactly 0, and the white reflect on the LCD comes from the lamp, entirely powered by my circuit) :



Note that some of these 19.9W are in fact injected into the mains, this explains why almost nothing heats here and why a higher current was needed to cancel consumption when connected to mains than to the DC/AC converter. Pushing the DC voltage higher results in the power meter showing a positive power again, indicating that I'm sending even more power into the house. At this point I stopped the experiment.

So yes, it is technically possible to re-inject some power into mains with a simple enough circuit. At this point one difficulty is to find the proper input DC voltage to cancel the mains without sending too much, because I don't want to dissipate too much power nor to send power back into the grid (with even the risk that it would make the disc spin again and charge me for the power I offer). Probably that producing only the minimum of any day's power usage would be a very simple way to solve this. Otherwise maybe a current meter on the mains connection to the grid could make it possible to have some feedback and regulate the injected power.

It's worth noting that during this experiment the delivered current was not very clean. On the image below it's visible that there were short peaks at each zero-crossing, caused by the short period during which none of the MOSFET is conducting, I even had to change the scope's time base because it couldn't stabilize on it :



But these artefacts should be very easy to cancel using a small capacitor across the transformer's terminals connected to the MOSFETs and it will also increase the efficiency and limit the MOSFET heating. Note that during this experiment, the MOSFETs were barely warm. Another improvement could consist in using a voltage comparator to always saturate the MOSFETs during the switch but given that the voltage is low at this moment it's not even certain that this is needed. I should also possibly use a choke in series with the central point of the transformer to absorb current impulses during the polarity inversion. But all this is very cheap and just a matter of experimenting a little bit.

Good solar panels having about 20% efficiency are found around $1/W nowadays, so for $400 it's possible to build a 400W array. Feeding 400W of power into the mains 8 hours a day every day at peak energy cost would save 175 EUR/yr, so the panels and circuits would be amoritzed in 2.5 years approximately.

Note that I thought about charging batteries at night and re-injecting the power during the day, but the cost difference and the inevitable losses would not make this worth, and it would take decades to amortize the batteries cost.

Has anyone successfully tried such a design ? Suggestions welcome.

Because the world runs on 5V

The success of USB as a power source is amazing.

15 years ago my friend Benoit Dolez told me "why not run a whole house on low voltage and avoid the risks of electric shock for everyone ?". I remember I responded "no, that wouldn't be practical, you'd need a very high amperage for this, it would require very thick cables and would cause too many losses". "Oh too bad" he said.

Of course I was wrong. Not on the technical side of things. On the social one. I didn't count on the possible success of portable devices making almost any device vendor provide a USB connector to receive some power.  Some even just draw copper lanes imitating the USB connector on their PCB. And this success wouldn't have been that huge without all those fantastic smartphones who stopped competing on how long they last on battery, and instead compete on how large the screen is and how fast their CPU can process pixels, even if that only lasts a few minutes before having to be plugged to the mains again (no single smartphone lasts as long as our 20-years old so-called cordless phones which could run on Ni-MH batteries for 8 hours talking).

All of this madness has resulted in the need for USB everywhere, instead of its usefulness. And when there is a need somewhere, there is a market, and there are innovations, products and progress.

I remember saying around 2008 in a shop "hey look they've put a USB connector on this wall plug, that's neat!". Right now in 2016 people visiting you at home routinely ask "where is the closest USB plug?". "The closest?". Not only it became obvious you have one, but you're even supposed to have many, all easily accessible! And that's true, we see USB-equipped power plugs everywhere. We even see USB-only power plugs. There are certainly more USB-equipped homes than WiFi equipped homes now. And that's what proves Benoit was right and I was wrong. No need for thick wires, just put a power supply into each and every plug and you're done! I tried to count the number of USB connectors I have at home and it's not easy given that every simple appliance has at least one. Counting those able to deliver power immediately or by just pressing a button or putting them in a very close plug is more meaningful. That seems to be around 20-60 on average, there are already 54 around my desk under power right now due to the PC, power plugs and the build farm. These days, small 5V power supplies cost around $1 shipping included and are cheaper than the equivalent high gauge cable you'd need to connect to the central panel under 5V. And a 6-10 port 60W USB power supply costs between $10 and $20.

But there's an area where it's less convenient to have 5V. When you're moving. Then you find lithium batteries coming in 1, 2, 3 or 4 cells, selling milliamps-hours. And all are lying since they advertise the cumulated mAh at the battery voltage instead of 5V, but since everyone does it, the first one not to do it would lose. What matters are Watt-hours (Wh), a unit for energy, they are the product of the voltage and the capacity in amp-hours. Batteries are thick and heavy (though lithium batteries are much lighter than lead or NiMH batteries). You tend to have as many as the places where you need them. I have one in my bag, another one with my laptop, another one in the room where I'm doing some hacking, another one with my bike serving for the front light (which is USB-based too, strangely). But with many batteries, you often have many nearly discharged batteries.

Thus this idea : why not have a very small battery in the pocket like you have your keys or your USB stick ? After all, most often you don't need the full capacity of your battery, and if you need it it's never large enough and you'd have preferred a larger one. So let's ignore heavy usages and go back to the most common ones : lighting a portable torch for a few minutes in the garage, recharging your phone to pass an quick call, powering a small WiFi router to connect your phone to a local network, recharging a bluetooth speaker or your TV's remote, having some light on your bike to go back home at night, etc... We all know such usages. And we'd be fine with a very small battery that's constantly in our pocket.

I decided to attack this idea with pretty good results. I ordered various small cheap batteries from a few Chinese vendors. I picked some models made for small drones because these ones are very cheap and support high charge and discharge rates (up to 5C charge and 20C discharge). I bought various capacities and tried to pick models that would be resonably small compared to the power conversion module. I ordered 100, 160, 240, 300, 380, 500, 680 mAh.

The reference on the batteries often have 6 digits such as "751517" on the 100mAh battery below. The first two digits correspond to the thickness in 1/10 millimeters. The 3rd and 4th one are the width in millimeters. The last two are the length in millimeters. This 100mAh battery is 7.5mm thick, 15mm wide and 17mm long. Yes that's tiny!



Then I ordered a few power conversion modules. These ones are made for the large 18650 lithium batteries. they're only 1.5 times larger than the USB connector and are both a step-up voltage converter (3.0-4.2 to 5.0V) and an adjustable lithium battery charger (often 0.5 to 1 amp output current) :



I started to build a few small devices by connecting the batteries to the modules and protecting them with heat shrink tubes. The 160mAh battery is as small as the PCB. The assembly was complicated because in order to save space, I had to desolder the USB connector and move it to the other side, so that I'd get a flat area at least on one side. It also required to modify the battery to move one wire to the other side :





The devices looked great but there was a lot of wasted area, especially on the largest ones (300mAh and more). On both photos below, the left one is the 160mAh version and the large one is the 300mAh one. Also I noticed that the modules were unable to deliver more than 800 mA, and my bike's front light needs 1.3 to 1.6 amp peak. More importantly, it always starts at the highest level which means that if the converter is not strong enough and cuts off, it's impossible to reach the lower power level.
 


Then I had another idea. I realized that this 5 volt frenzy is interesting, because nobody uses the 5V power line as is anymore. It's always converted to a lower voltage, sometimes 3.3V, sometimes 1.8V, or several intermediary values. In fact the USB bus itself requires 3.3 V pull-ups. I even observed that many USB webcams and WiFi adapters work pretty fine at any voltage between 3.3 and 5.0 V, and consume the same current, hence consume less power at lower voltages thanks to the LDO regulator inside which is only here to produce heat from any extra voltage above 3.3 V . Since each and every device comes with its own regulator to reconvert the 5V to something else, we could have imagined seeing a new trend of lower voltage devices or even better, wide range inputs. But that doesn't seem to be the case yet. So I tried to design my own such battery. The smallest one (160 mAh) was directly connected to the USB connector, without any PCB at all. It is pretty small :




My bike's front light liked it pretty much (a white led is 3.2V approximatively), however I found a few devices which couldn't run off it, often those which need to boost the voltage, because generally they employ low-Rdson MOSFETs which are not saturated below 4V which which leak a lot of power. So I stopped the experimentation there, still frustrated that I didn't have the ultimate universal battery.

After searching I finally found another module, based on a TP5400 chip, which can deliver about 1.2 amps on 5V from a fresh battery. I ordered two (just in case I'd kill one).

It's pretty well designed for my use case. Very little wasted space. One side has only low-profile components and the micro-usb connector, the other side has the USB connector, the inductor and the integrated circuit. It is possible to solder the 100 mAh battery on the flat side so that it doesn't increase the module's width at all.

Since the battery is only 100 mAh, I changed the charging resistor from 1.2k to 3.3k to limit the charging current to about 330 mA (about 20 minutes). This device is capable of powering my bike's light, and even to power my Clearfog base ARM-based server via a USB-to-12V converter. The module heats, but the device runs and works fine even with the Gigabit Ethernet cable plugged. Of course it will not last long, maybe 10 minutes only, at this rate. But sometimes it's useful. Just like my bike, at half light intensity (as I normally use it), it should last about 8 minutes. That's enough to cut through the woods at night when going back home... And I think I could put the 160 mAh battery there with a bit of effort. However, I noticed that my bike is pulling hard from this module, and if it had not been charged recently, it will cut off.

Finally I think I found a very good solution a few weeks ago, eventhough from an implementation perspective it's not optimal yet. Recently some powerful 3V-to-5V DC/DC modules have started to appear on the net, like this 5V/2A step-up module : http://www.ebay.com/itm/122122888739

It's important to note that they do not include the charger, but I already have plenty of TP4056-based chargers. So I ordered two of them and started again to try to assemble them. Interestingly this module extended with one USB connector is exactly the same dimensions as the TP4056, which is also the same dimensions as a 240mAh LiPo battery, and both modules are single-sided so they could be sandwiched to take less space :

   
I just had to surround it with some transparent heat shrink tube and fill every hole with some hot glue and this results in a reasonably strong power cube which easily accepts being dropped on the floor :


After a few tests, it appears very powerful. I could draw slightly more than 2 Amps from it, that's 10 Watts!
In addition I forgot to reprogram the TP4056 for a lower charge current, so it charges under 1A (which the battery supports as it's supposed to support 5C hence 1.2A), and is fully loaded in 15-20 minutes. The power conversion module eats a bit of power even when idle. I measured around 100 microamps, meaning that the battery will be depleted after 3 months not being used. But given that I have it every day in my pocket now it's not a problem. And it has already served me many times since I've built it! I've used it to power some development boards while I had no more USB port available, and last night to have some light on my bike when the original 2.2Ah battery gave up mid-trip. I managed to get at least 15 minutes of light, I don't know if it will give more but that was enough. The purpose was perfectly filled since I had it available in my pocket as every day now.

It's much smaller and lighter than the original 2.2Ah battery as can be seen below :




So what's the next step now ? I'm not interested at all in trying to create a business around this, but I'm pretty sure that many people would love to have a very small power reserve in their keychains. These devices are small enough to be arranged with the connectors inline opposed to each other and the battery in the middle. Just add a small keychain ring and you're done. I'd love it if one day I can buy a small keychain looking like this. Let's hope all the makers of programmable door remotes and USB flash keychains copy this idea and allow us to bring 5V everywhere with us with real power (at least 2A). I thought about using the same micro-USB connector as an input and an output but it would cause a cable issue as micro-usb to micro-usb is very rare. And using a male micro-usb connector would make it too fragile.

For the long term, it would be nice to see an evolution of the USB norm allowing certain categories of device to *officially* run from 3 to 5V. These ones would be advertised as "green power" or something like this because they don't require a conversion module which comes with losses, and would even smaller power blocks to be made (or with higher energy by converting the PCB space to battery space).

2016-11-13

Smallest, cheap ON-OFF switch for RC cars using a servo

A few months ago, my friend Erwan showed me his recently acquired RC car which was very powerful and quite fun. That was enough to convince me and my other friend Benoit to buy one each :

They are so fast and powerful that you definitely need some large places to play with them. We tried them on a parking on a late afternoon but night started to fall and I found that some light was missing. Given that there's an unused 3rd channel with a dedicated on/off button on the transmitter, that made me think that an obvious mod was going to happen in the form of LEDs.

The receiver has 4 channel outputs for servos. Only the first two ones are used, so I needed to connect a device accepting servo commands. I quickly checked on the net for RC ON/OFF switches replacing a servo but found very few which were quite expensive and large for what they are (around $8 minimum). In fact, you can find some small entry-level servos for less than $1. I thought "after all a servo will make it fine".

A servo contains 3 parts :
  - a motor
  - a potentiometer attached to the motor
  - the signal decoder, moving the motor in the same direction as the signal so that the potentiometer matches the signal length.

The signal decoder can drive a motor so it can deliver at least around 1 amp under 5V, which is perfect.

The signal is a 500-2500 microsecond pulse every 20 ms. I checked with my oscilloscope, and the OFF pulse is around 1300 microseconds, and the ON pulse is around 1700 microsecond large. Given that the center for servos is 1500 microseconds, I just need to detect the position around the center. That could be dealt with using a microcontroller but the servo approach looked cheaper and simpler. Thus I ordered a few of these servos and disassembled them. It's quite easy, there are only 4 screws. The servo looks huge here but all the photos were taken in macro. The servo is only 23 mm wide :
The PCB is extremely small (7x11 mm). Fortunately both the potentiometer and the mtor are soldered using wires, meaning their removal is trivial. It seems like the manufacturer thought about my use case, because the potentiometer pads are exactly aligned and spaced like common SMD resistors, and the motor pads are large and 2.54mm spaced, perfect to place a jumper header. Any pair of 1-10k resistor will fit, as we only want to pretend the potentiometer is at the center so that the controller sends the current either in one polarity or the other.


Just put that into some heat shrink tube :


And the circuit is complete! It's so small that it will easily fit on top of the receiver in the closed box in the car. A quick test shows that it works perfectly, it outputs either +5V or -5V depending on the selector position.

For the next step, I drilled a plastic tab of the appropriate width, I attached 4 white leds in parallel, each with their dedicated 150 ohm resistor, and screwed this at the front of the car. A 2-pin 2.54mm connector and a pair of wired was soldered to the leds, and plugged to the circuit :


That's only $1 and one hour of work in total to put front lights on this car. More importantly there was only 5 minutes of work on the signal decoder so it's really not worth buying a more expensive and larger board.

2016-10-16

Extreme power TV-B-Gone

Purpose

Almost every electronic hobbyist knows about the TV-b-gone project. For those who don't know, it's a nice little device which iterates over many TV ON/OFF remote codes and sends them to an IR led to turn off many TV (appreciable in noisy places or just to have fun).

I wondered if it was possible to build a really high-power one, to shut TVs in the neighborhood or across the street, so I ran a few experiments and finally built one such device. One point which started to make me think about it was after noticing that vegetation (such as tree leaves) appear white under infrared light, so they reflect infrared very well. I thought that if I could send a strong signal to trees, they could reflect it all around.

Example of photos of trees and grass in infrared

Selecting hardware

Not having a TV myself, I wanted the device to be portable for obvious reasons, and will have to be battery-powered. I found some code capable of running on ATTINY85 devices so I used one of my Digispark boards (17x20 mm) :

I made some experiments to drive high power LEDs from an ATTINY85 GPIO. After quite a numebr of tests and fried transistors, I came up with this design which works pretty well and provides clean square signals up to a few hundred kilohertz :

I needed some high-power IR LEDs. The highest power/price ratio I could find using 940nm LEDs (most common wavelength used by TVs) is found when buying packs of 10-20 3W LEDs. These ones need to be soldered on a plate and to use a lens to focus the beam. I found some aluminium PCBs for high power LEDs featuring 20 and 50 places. The 20-LED one was both cheap and small enough to be hand-held so I picked one, with 20 3W LEDs and as many 15° lenses.

Realising the driver

I'm a bit old-school when it comes to realizing PCBs, not even having a printer doesn't make it easy. So I picked the components, placed them like on the schematic, then draw the PCB with a pencil and etched it.

  

Installing the software

A working TV-B-Gone software can be found in Adafruit's Github repository. I performed a few changes such as setting the default region to EU instead of US, and looping forever between the two regions instead of doing a single round. I also changed the LEDs assignment so that the debug LED connected to PB1 can be used to monitor the activity. Then I flashed the device using my Bus Pirate board in order not to depend on any boot loader and have it boot fast. The modifications are available here. The original device uses a 8 MHz ceramic resonator because the internal RC oscillator is supposedly not accurate enough. But I think that receivers are not accurate either and it's not that much of a problem. So I went with the simpler solution consisting in using the internal RC oscillator only.

Assembly

I stuck the boards on the back of the aluminium plate using some double-sided tape, placed an ON/OFF switch, a capacitor and 4 Li-ion batteries providing 14.8V. The aluminium plate is very convenient as it serves as a LED support, a PCB support and as a heat spreader. The most painful part was to solder the LEDs because the solder cools down very quickly and you don't want to put too much of it otherwise there's no more room for the lenses.



Initial tests

I made a small IR detector based on an IR receptor and a green LED. When powering the tv-b-gone on, the receiver immediately receives the beam and blinks, showing the emitted signal. I found that it was possible to catch the signal in any room in my home provided the doors are not completely closed. This proves that the IR signal is powerful enough to be reflected multiple times on the walls.

I started to make some measurements. For this I soldered a 0.05 ohm resistor in series with the LEDs and connected my oscilloscope on it. I noticed that the signal was full of noise on the input, because the capacitor wasn't strong enough to withstand the high current pulse and easily falls by 2 volts when the LEDs emit a pulse. And indeed, this 4700 µF capacitor was warm... I also noticed that the current coming from the batteries is very low, a few hundreds of milliamps on average. The initial lenses had a 45° beam which I found was too large, so I replaced them with a 15° beam.

Modifications

I replaced the capacitor with two low-ESR 3300 µF capacitors. These ones now stand the load much better. The voltage across the 0.05 ohm resistor shows 0.7 volt during pulses. That's 11 amps under 13V, it's 143 Watts! IR LEDs generally support very high power pulses. Here there's 60W of LEDs (20x 3W) arranged in 4 parallel blocks of 5 LEDs. But under 13V  the current raises to around 2.7A, or more than twice the rated current.

I hesitated to add an extra battery but I didn't want to fry the ATTINY module's regulator, supposed to be limited to 16V. So instead I got rid of all these heavy batteries and replaced them with a DC-DC boost regulator calibrated to 15.7V. That's lighter and it provides even more power. Now the LEDs take 14A under 15V, that's 210 watts, or 3.5 times the ratedpower, and 3.5A flowing through each LED! It's interesting to note that the aluminium plate now warms a little bit after one minute.


New tests

I wondered how far the beam could be received. I ran a small test. I placed the device on one window, facing the trees in the garden, and picked my detector. I could receive the signal anywhere else in the house whenever it faces the garden, while there's no direct visibility between the windows, so it was clear that the signal was reflected on the trees :


I brought it to the office where we have a TV in the meeting room. I could turn it on and off from the corridor. But my best surprise was when I went downstairs and found another one turned on! It got the signal after multiple reflections on the walls across one stair! I could run another test with the device placed in my coat's pocket and facing the opposite direction relative to the TV. The TV would turn on again, so the signal was powerful enough so that my opaque coat would let a little bit of it escape and be detected by the TV.

I tested with my brother and could turn on and off his TV from the street (about 50m away).

I noticed that some TVs do not react at all. I don't know if it's because they use a different wavelength (like 850 nm) or because the signal is too faint or no code works. I replaced 4 LEDs with 850nm ones just to see if it makes a difference but have no successful reports for now (it's hard to find TVs in line of sight, and shops don't use them anymore for advertisement). One important point to note is that at this power level, the 850nm LEDs emit some pretty visible faint red flashes. It's normal, their spectrum curve is not perfectly straight and when you drive them to 10W, you can expect to see one milliwatt in the visible spectrum.

Future improvements

I thought about trying a much smaller design using an IR laser diode. I bought a 850nm 1W laser diode. By using a detuned, slightly divergent beam, one could expect having a few centimeters wide "spot" at a few tens/hundred meters. The problem is that IR not being visible, it's very hard to aim, so by having a larger spot it should help. But in practice a camera or smartphone sensitive enough to IR is required to aim the spot because it's very hard to aim with a few centimeters precision at a few tens of meters. So for now I don't think it's that good an idea in the end.

Some 100W 940nm LEDs can be found on the net nowadays. But they're still very expensive ($100) and operate at a high voltage making the circuit harder to design (>30V). Also it's important to consider that we want to overdrive them, this means something like 40-50V pulses, so it's really not a good idea. It seems for now that the 3W LEDs are the best fit. Additionally, many so-called 100W LEDs are only rated for half of this power, so that become quite expensive for something possibly less powerful than the current design.

Maybe this device could be installed in a torch. The electronic parts are quite small, and if someone were to do it from scratch, the ATTINY could be directly soldered on the driver board.

A test could be run with an external ceramic oscillator to see if it provides better results than the internal RC oscillator.

Last words

It's totally useless but was fun to build. It's small enough to put in a pocket and to carry in one's hand. However if you get caught outside or in a shop with this, you'll have a difficult moment trying to explain what it is :-)