Hurricane Hack – DIY LED Candle

Florida is about to get hit by a massive hurricane, and my home town is in the direct path! I am well prepared with lots of food, water, and communications equipment. While the storm itself is dangerous, part of getting ready for it means preparing for the potential to be out of power for weeks. A staple go-to for light when the power is out is candles. Instinctively people tend to reach for candles and kerosene lamps (in Florida they’re called hurricane lanterns). However, these sources of light can be extremely dangerous! With the storm one day away, my roommates and I began pooling our emergency supplies in the living room and I grew uneasy about how many matches and candles were accumulating. With severe weather, wind, falling trees, tornadoes, and projectiles blowing around there is an appreciable risk of knocking-over a flame and starting a fire. This risk multiplies when you consider that people often fall asleep with flames running, perhaps even in another room! I thought how great it would be to have a bunch of LED candles, but there is absolutely no way I can buy one now. Although I could just leave a flashlight on shining at the ceiling, it would produce too much light and the batteries would die before long. With the storm one day away, every store in this town is out of water, most groceries are out of canned foods, and most of the gas stations are out of gas and have locked up. Flashlights, radios, and LED candles are surely gone from all the stores as well. I decided to hack-together several LED candles to use around the house over the next several days, and the result came out great!

I taped together 2 AA batteries and soldered a resistor and a white LED in series with jumper to serve as an on/off switch. It’s not yellow and doesn’t flicker like fancy LED candles, but who cares? This is perfectly functional, and for lighting a room I would say it’s a superior alternative to fire-based candles when the power is out for long periods of time. The batteries will last much longer than they would if we just turned on a flashlight and aimed it at the ceiling too. My white LEDs (generic low current clear 5mm LEDs) have about a 20º light emission angle. To improve its function as a room light I taped a sheet of paper around a glass cup and set it over the top to act as a light diffuser. This couldn’t be simpler! It’s hard to capture on camera, but if the light diffuser is removed this thing works pretty well as a flashlight. I practiced walking around a dark closet and pointing it around and was impressed at how much it is able to illuminate a relatively narrow area. This is a good time to add a basic warning reminding people that soldering directly to batteries is potentially dangerous for the person (and may be destructive to the battery) and it should be avoided. Battery holders are superior, and batteries with solder tabs already on them are a superior alternative to generic batteries.

3xAAA Version

I found a box of battery holders and decided to make a second version of this device. I felt better about this one since I didn’t need to solder directly to any batteries. A dot of super glue is all it took to secure the LED to the enclosure, and it even stands upright!

How long will it last?

I’ll use some scratch match to predict how long this device will stay lit. I’ll run the math first for the 2xAA version. Placing an ammeter in the circuit while the LED was on revealed it consumes 1.8 mA of current. PowerStream has a great website showing battery discharge curves for various consumer grade batteries. Eyeballing the graph it looks like most batteries doesn’t start to drop voltage significantly until near the end of their life. To make calculations simple, let’s just use the mAH (milliamp hour) rating that the manufacturer provides… except I can’t find where Amazon specs their “Amazon basics” battery. A consumer review indicates 997 mAh at 100 mA discharge rate. I’m sure our duration would be far beyond this since we are drawing less than 1/50 of that much current, but let’s just say 1000 mAh to be conservative. We can double that since we are using two AA batteries in this circuit, so 2000 mAh / 1.8 mA = 46 days. Interestingly, the 3xAAA battery presents a larger voltage to the led/resistor so it draws more current (6.3 mA) and 3000 mAh / 6.3 mA it is expected to last only about 19 days. I could increase the value of the resistor to compensate, but it’s already built and it’s fine enough for my needs.

When the storm has passed and things return to normal, I’ll consider making a few different designs and testing how long they actually last. Many battery tests use relatively high current challenges so their discharge finishes in days rather than weeks or months… but with a sensitive voltmeter circuit attached to a logging raspberry pi or something, I’d be interested to see the battery discharge curve of a DIY LED candle on a weeks/months timescale! For now I feel prepared for the upcoming storm, and with several DIY LED candles to light my home instead of actual candles, I’ll feel safer as well.

 


     

PS4 Controller Hack – Adding Auto-Run

After a long day it can be really nice to have a relaxing hobby to clear your head, and few activities shut down your brain as effectively as video games. However, a newly released video game is physically hurting me as my impulse to move quickly causes me to perpetually click the run button. After a few days of game-play and a really sore left thumb, I decided to do something about it: hack-in a microchip to automatically click the button for me. Modifying game controllers to do things like automatically rapid fire is nothing new. I once modified a USB computer mouse to add an extra “rapid fire” button (link). Hackaday ran a story about a guy who hacked a PS4 controller to add mouse and keyboard functionality. Today’s hack isn’t quite as elaborate, but it’s very effective. Here I show how I modified a PlayStation 4 controller to automatically click the L3 button so I am always running. This auto-run functionality mimics the auto-run feature built into many games (like Titanfall 2 which spoiled me to expect this), but I built the circuit so it can be toggled on and off by clicking the L3 button. After playing Titanfall 2 for the last few months, the recent release of the Call of Duty WWII beta is driving me crazy as it requires me to click the run button over and over (every two seconds) which, after an afternoon of playing, is actually painful.

Assessing the PS4 Controller

I started out by looking online to see what the PS4 controller looked like inside. Imgur has a great PS4 dualshock controller teardown photo collection which was an excellent starting place. From these photos I realized this hack would be pretty easy since the L3 “click” action is achieved by a through-hole SPDT tactile switch placed under the joystick.

I was surprised to find my PS4 controller (below) was a little different (green for starters), but the overall layout was the same. I quickly identified the 4 pins of the L3 tactile switch and got to work…

After probing around with a multimeter and an oscilloscope, I was able to determine which pins do what. Just from looking at the trace it’s pretty obvious that two of the pins are the positive voltage rail. In this controller the positive voltage (VCC) is about 3 volts, so keep that in mind and don’t hook-up a 5V power supply if you decide to debug this thing.

To test my idea I attached 3 wires to VCC, GND, and SENSE and ran into the other room where my PS4 was. As I held the left joystick up in a game, shorting the SENSE and GND wires (by tapping them together) resulted in running! At this point I knew this hack would work, and proceeded to have a microcontroller control voltage of the L3 sense line.

Simulating L3 Presses with a Microcontroller

I glued a microcontroller (ATTiny85) to the circuit board, then ran some wires to the points of interest. Visual inspection (and a double check with a multimeter when the battery was in) provided easy points for positive and ground which could power my microcontroller. The “L3 sense” pin (which toggles between two voltages when you press the L3 button) was run to pin 3 (PB4) of the microcontroller. In a production environment current limiting resistors and debounce capacitors would make sense, but in the spirit of the hack I keep things minimalistic.

The device could be easily reassembled, and there was plenty of room for the battery pack and its plastic holder to snap in place over the wires. Excellent!

While I was in the controller, I removed the light-pipe that carries light to the diffuser on the back. The PS4 has an embarrassingly poor design (IMO) where the far side of the controller emits light depending on the state of the controller (blue for in use, black for off, orange for charging, etc). This is a terrible design in my opinion because if you have a glossy and reflective TV screen like I do, you see a blue light reflect back in the screen and bobble up and down as you hold the controller. Dumb! Removing the light pipe dramatically reduced the intensity, but still retains the original functionality.

Programming the microcontroller was achieved with an in circuit serial programmer (USBtinyISP) with test clips. This is my new favorite way to program microcontrollers for one-off projects. If the pins of the microcontroller aren’t directly accessable, breaking them out on 0.1″ headers is simple enough and they make great points of attachment for test clips. The simplest code to continuously auto-run is achieved by just swinging the sense line between 5V and 0V. This is the code to do that:

for(;;){ // do this forever
	// simulate a button press
	PORTB|=(1<<PB4); // pull high
	_delay_ms(50); // hold it there
	// simulate a button release
	PORTB&=~(1<<PB4); // pull low
	_delay_ms(50); // hold it there
}

Sensing Actual Button Presses to Toggle Auto-Run On/Off

Simulating L3 presses was as simple as toggling the sense line between VCC and GND, but sensing manual L3 presses wasn’t quite as easy. After probing the output on the scope (see video) I realized that manual button presses toggle between voltages of about 2V and 3V, and the line never really goes down to zero (or below VCC/2) so it’s never read as “off” by the digital input pin. Therefore, I changed my strategy a bit. Instead of clamping between 5V and 0V, I toggled between low impedance and high impedance states. This seemed like it would be gentler on the controller circuit, as well as allow me to use the ADC (analog-to-digital controller) of the microcontroller to read voltage on the line. If voltage is above a certain amount, the microcontroller detects a manual button press is happening and toggles the auto-run functionality on/off. The new code is this:

for(;;){ // do this forever

	// simulate a button press
	PORTB|=(1<<PB4); // pull high
	DDRB|=(1<<PB4); // make output
	_delay_ms(50); // hold it there
	
	// simulate a button release
	DDRB&=~(1<<PB4); // make input
	PORTB&=~(1<<PB4); // pull low
	_delay_ms(50); // hold it there
	
	// check if the button is actually pressed to togggle auto press
	if (ADC>200) { // if the button is manually pressed
		_delay_ms(100); // wait a bit
		while (ADC>200) {} // wait until it depresses
		while (ADC<200) {} // then wait for it to be pressed again
	}	
}

It works! My Call of Duty character is running just like a Titan Pilot. After giving it a spin on the Call of Duty WWII Beta, I’m happy to report that this circuit is holding up well and I’m running forever effortlessly. I still suck at aiming, shooting, and not dying though.

Follow-up: After playing the fast-paced and highly dynamic Titanfall 2 for so long, I rapidly became disenchanted with the Call of Duty WWII game-play which now feels slow and monotonous in comparison. Although this auto-sprint controller hack works, I don’t really use it because I barely play the game I made it for! I’m going back to exclusively playing Titanfall 2 for now, and if you get the chance I highly recommend giving it a spin!