2 or 3 LED colors on a single digital pin

It took longer than I thought for the Arduino to start-up and the red LED to go out. :clock130:
It can see that the red LED is emitting light! :bulb:
Yeah, this doesn't allow us to say "it is invisible to humans eye". :eyes:

Please accept my sincere apology and forgive me to I said lie. :confounded:

No apologies, my friend. It would have taken me a lot longer to get here without your help.

Thanks mate.
Did you finally solve the problem on this topic?

Since I wrote in the second half of #10, might as well so I'll try it myself when I get home what.

Yup, I eliminated the relays and the regulator to power them. The car shouldn't draw more than 6 amps with every possible thing going and probably much less normally. So, the P-MOS I have already is more than adequate to handle all the power.
I'm going to post an updated schematic tomorrow, but now it's just this power supply circuit and the 5V buck. So much simpler.

You'll have to make a post about your LED project too. I think 4 colors from one pin would be useful to a lot of pin hungry projects.

I was thinking about a way to make the unit power off with the button still depressed. I think it may have required a fundamental change to the design. The green to red LED was my simple compromise to signal the user instead of them holding the button forever while the unit stayed powered.
I couldn't be happier with the results.

It is difficult to turn off the power while pressing the button when drawing a signal from the button that makes up the hardware switch with wired-OR and using it as a shutdown button.
The circuit of the button part is not involved in the control from Arduino, because need to turn on the power without Arduino.
It means if even only that part execute power supply circuit with momentary switch that uses P-MOS.

I think I'll experiment with it when I get home after work.


EDIT: P.S.
In also some other threads you listen to my suggestions seriously, experiment quickly and summarized report the results.
It's one of the happy things about posters that post answers, and I'm getting the most satisfaction anytime from you.

1 Like

@er_name_not_found
I remembered (wired-OR) that if I pressing the button, 5V was output even if digitalWrite was LOW, so I update the simulator circuit according to the actual situation.

EDIT:
Changed to P-MOS and reduced unnecessary current consumption.

Hey friends.
The trick was successful. :partying_face:

Use two LEDs, two resistors and two additional capacitors...

Expand to show codes.
#define LED_OFF  0x00
#define LED_RED  0xD0
#define LED_BLUE 0x01
#define LED_BOTH 0xB2

const int LED_PIN = 3;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  TCCR2B ^= 5; // Freq Trick
}

void loop() {
  setLEDstate(LED_OFF);
  delay(1000);
  setLEDstate(LED_BOTH);
  delay(1000);
  setLEDstate(LED_BLUE);
  delay(1000);
  setLEDstate(LED_RED);
  delay(1000);
}

void setLEDstate(byte color) {
  analogWrite(LED_PIN, color);
}
1 Like

Very cool! I have so many questions.

I'm curious about the signal going to each LED. Could this same technique be use so that one pin can provide two states to other devices? In effect doubling its capabilities as an output pin.

Am I correct is seeing the capacitors as the key to this circuit and the resistors as only necessary for the LEDs?
Do the different PWM gaps allow for different and predictable states of discharge?
Are they the same value?

I also wonder if this could be made to work backwards as an input, given the logic voltage is known.

Sorry for the abundance of questions but it's the little things that really pique one's interest.

Sry, tuning in late. I know this is not the current line of inquiry, but I have to submit the first thing I did when I saw @er_name_not_found's schematic.

TBH I didn't even try to make sense of the original. A novel circuit, but upside down and using a PNP transistor WTF is this doing and would it even work?

Anyway, I see you are well on the way to the ne plus ultra power management device!

HTH and not trying to pick on anyone, just a B in my bicycle cap over Fritsinfs, Make Magazine cartoon component-orientated "schematics" &c.

A good schematic is a communication tool, the extent to which standards and customs are observed is the extent to which the work on the part of the reader is reduced.

This applies across the board - English prose, computer "code" &c. Rant off.

a7

Yes! and that is better.
I presented NPN(N-ch) first, but later realized that the PNP(P-ch) was better.

As already changed, the final simulator circuit has been modified that way.
Please see this post.

Thank you for interest.
I don't deny that the key-components of this circuit lies in the capacitor, but it must be said that resistor is just as important.
This circuit consists of two passive RC filters, A high-pass filter and a low-pass filter.
An LED is connected to the output via each filter.

High-pass filter = Blue
 Low-pass filter = Red

When a short pulse is output, only the blue LED lights up by passing only the high-pass filter.
The low-pass filter doesn't allow short pulses to pass, so the red LED doesn't light up.

When a long pulse (or DC) is output, only the red LED lights up by passing only the low-pass filter.
The high-pass filter doesn't allow DC to pass, so the blue LED doesn't light up.

The values of R and C of these two filters are set so that the characteristics overlap, so there is a point near the center where both can pass.
By using that points, two LEDs are lit at the same time.

Of course, both are turned off when no current is supplied.

https://en.wikipedia.org/wiki/High-pass_filter
https://en.wikipedia.org/wiki/Low-pass_filter

Cool, need to save that battery juice.
Off to Amazon for some signal P-MOSes.

My first attempt at making up a transistor circuit instead of just googling the solution.
My idea with the BJT over the FET was cost and the fact that I have thousands of 2N3906 and 2N3904 because they're 2 for 3 cents.

Working on it. Fritzing was the easiest for me to jump right in to. I still need to see the colored wires to understand the convention flow. I am going to teach myself to use Falstad though, because the simulator will probably help me to better answer my own questions.

While I'm under the microscope, what did you think of my code?

So my LED is blinking at very fast, but can't cofirm blink with the human eye.
I don't think it can be used as a signal, this is a pretty weird trick.

Probably a dumb idea but could you use an output like a buck converter does to smooth the value?

The passive RC filters are characterized by the value of the capacitor and resistor, so installing an additional smoothing capacitor will destroy the filter.
In other words, the capacitor for voltage stabilization of the converter is considered a low-pass filter.

Makes so much sense explained like that.
I still have loads more to read about it but it looks like I won't need to buy anymore band pass filters for future projects :partying_face:

From the math, selecting high or low pass, selecting the proper capacitor, using a variable resistor, and running it though my toy o-scope I can figure out the best resistor capacitor pair to make my own filters. I see another clock radio in my future. :radio: maybe with a 32X64 RGB LED display.

TL;DR: Didn't follow all the things about the capacitors and such but a single WS2812 controlled by a digital pin could indicate all sorts of things! :grin:

1 Like

@er_name_not_found
The characteristics of the passive filter have a calculation formula and can be easily calculated.
You can also simulate using a circuit simulator such as LTspice.

@Paul_B
Yes, it can display 16,777,216 colors with a 1-pin communication signal.
In addition, it can connect hundreds or more!

However, in the OP's circuit, it was necessary to change the LED color by the logic pin already built.
This logic pin already had a function and could not be used to control the WS2812.

Indeed, and that's great advice should be used in a lot of cases.

However, though not mentioned originally the signal wire used for the LED is tapped from an existing wire and could not be changed to generate a control signal for a WS2812B.

My goal was to find a way to not add another pin to an existing project but that got filtered out from my MRE that I used for the question. It's my fault for not mentioning it. I'm still working on that balance in my question asking.