# Using two pins as input to one LED

Project: Light up drink coaster using 8 LEDs
When a drink is placed on the coaster the 8 LEDs blink on and off one by one in a circular pattern (pins 2-9). When the drink is almost empty the coaster will stop the circular pattern and start a glowing/pulsing pattern (just fading an LED) using PWM (pin 10 to power all 8 LEDs).

The programming for these two different patterns are very simple but I am confused as to how I will switch between them. The switch in patterns will be triggered by a force sensing resistor. When the weight of the drink is below the minimum threshold then I want to switch to the glowing/pulsing pattern.

I tried wiring 2-9 to one LED each and also wiring pin 10 to every LED however this did not work. How should I approach this? I am looking for advice about how to wire this project up, I have no problems programming.

I attached a diagram of how I tried to wire the LEDs up (I only did 3 instead of all 8 but it is the same idea for all). If you need any clarification just ask, I’m pretty new to this so my explanation might not be the best.

Thanks for any help!

Thats a great way to kill your arduino / led's, you need some resistance between your arduino and led's or led's and ground (~200 ohm)

I'd look into an 8 bit LED Driver with PWM.

*You'll only need to use a couple pins.(data, clock, latch) *You'll use a shiftout() function in the code, and control all permutations of on/off combinations of leds individually by sending an 8 bit value. *There is a lot of documentation and samples on the web that you will be able to look at for wiring. --Example would be Googling the 8x8 led panel or even just the shiftout() example on the arduino.cc site

Its probably a better approach to what you are trying to achieve, and hopefully you learn a bit more about wiring in the process.

Diode OR-ing.

You can supply DC from 2 sources by using a diode as a switch. Which ever diode would supply the higher potential will power the individual LEDs.

So - from each Arduino output you go through a diode and resistor to the LED. then you use a PNP transistor as a HIGH SIDE SWITCH trough diodes to each of the resistors. You will then have 2 diodes for each led, both diodes tied to the same side of the resistor. Whichever is the higher voltage will control the LEDs.

OR you might be able to do it this way -

From each output go to a resistor and its LED. the negative side of the LEDs go to an NPN transistor as a LOW SIDE SWITCH. PWM at max for the LEDS to flash singly, All LED outputs high to adjust them using PWM. This would let you do other effects also - as the bulbs cycle they dim an brighten, as they cycle they alternate dim and bright…

For both these approaches the voltage drop across the LED will be lower than when just connected to the resistor and out put port, so the resistor will have to be a lower value. In the first approach you will have a voltage drop across the diodes of approx 0.7V and the same in the second method with the transistor.

I'll suggest a software solution that I have not tried, but it should work.... I suggest you "roll your own" PWM.

For example, if you turn an LED on for 1mS and off for 1mS (in a loop) the LED will appear be 50% of full-brightness, On for 1mS, off for 9mS is 10% brightness. On for 9mS and off for 1mS is 90%, etc. The downside to this approach (especially with multiple LEDs) is that you are using-up lots of CPU time just to dim LEDs. But in your application, the CPU isn't doing much else anyway... It's just checking if the glass is getting empty.

You can start-out experimenting with the delay() function, but as you finalize your project you'll probably want to switch to the micros() function following the [u]Blink Without Delay[/u] example.

It's generally good practice to avoid delay(), because the CPU is just sitting there "doing nothing", and it tends to make the overall programming more difficult when the CPU spends most of it's time doing nothing.

The issue with milliseconds (vs. microseconds) is that you might start to see a flicker if your total blink time is more than about 20mS (say, you dim to 5% with 1mS on & 20mS off). Feel free to experiment, and if you see flicker switch from milliseconds to microseconds.

Thanks for the advice everyone. The diode or-ing might be what I'm looking to do here from looking at it briefly.

Osgeld: Thats a great way to kill your arduino / led's, you need some resistance between your arduino and led's or led's and ground (~200 ohm)

Why doesn't it matter where I put the resistor? Wouldn't I want to put it between the output pins and the anode of the LEDs? What is the purpose of putting the resistor before ground?

The LED just has to be somewhere between the Arduino pin and ground, Whether it is before or after the LED doesn't matter, the results for the LED will be the same as all the resistor does is limit the current.

Hi,

I second the software option, on the basis that it's possible and it's kind of the whole point of a micro controller.

I don't think you would need to build your own pwm library, there appears to be one called softPWM that already provides PWM on any selection of pins.

If you google 'arduino soft pwm library' you will find lots of info including demo videos of various led effects.

Duane B

rcarduino.blogspot.com

Might I suggest a TLC5940? Its a simple LED PWM IC. It can control up to 16 channels (16 leds) and it can PWM and just set as well. If you want to do RGB LEDs, it only works with common anode rgb leds.

You need resistance in between the arduino and the led. Its better to step down the voltage BEFORE it reaches the LED so it doesn't burn out and then the arduino won't have as much voltage coming back at it.

You can use a basic peizo pressure sensor or something if you like to sense the placement of a drink. Check out arduino Knock, there is a simple circuit that is perfect for what you want to do. The piezo sensors are extremely cheap and also extremely easy to use.

If you need hook up diagrams for the TLC5940, here they are http://code.google.com/p/tlc5940arduino/ You can get them as a sample if you are evaluating them from Texas Instruments. Otherwise you can buy them from sparkfun or TI or wherever. Here is the arduino library. http://www.arduino.cc/playground/Learning/TLC5940/

If you have questions about the 5940, just message me, I love that IC. I use it all the time.

No need for extra led drivers, multiplexors or diodes.
Simply connect one side of each LED to a separate output pin, and the common pins together to a pwm output. Don’t forget series resistors!
You can then switch each LED on or off separately, and use the PWM to adjust the intensity of all LEDs that are ‘on’ simultaneously.
Like this:

Lion251: No need for extra led drivers, multiplexors or diodes. Simply connect one side of each LED to a separate output pin, and the common pins together to a pwm output. Don't forget series resistors! You can then switch each LED on or off separately, and use the PWM to adjust the intensity of all LEDs that are 'on' simultaneously. Like this:

How do the LEDs turn on when they aren't connected to ground?

drummingbum: How do the LEDs turn on when they aren't connected to ground?

A digital output pin switches between Vcc and ground (HIGH and LOW). So, an output pin that is LOW in my setup is connected to ground, and will make the LED light up when the other pin is pulled HIGH by the PWM. When a digital output pin where a LED is connected to with its cathode is HIGH, no current can flow, and the LED stays off. Just try it; it works!