# Convert 12V PWM to 5V for Arduino input (ZigBee LED controller)

I got this ZigBee controller. The output of which I assume a 12V PWM signal because of the 12V LED strip you can connect it to. I want to connect it to my Arduino input. This way the ZigBee controller can control, through an Arduino, servo motors etc.

I've tried different circuits I've found on the internet to convert the 12V signal to a 5V one, but none worked for me. Perhaps I did something wrong. Maybe it does work well for me because the ZigBee controller outputs one constant 12V signal and uses the cathode side ('gnd side') of the strip to change the brightness.

Looking at the Zigbee controller, how can I convert the PWM signal so the Arduino can read it as an input? Could you include a schematic?

• You must define tolerances for ANY DESIGN. Pls include frequency, resolution of min. duty cycle and % output ripple with scale 0 to 5V Commented Jan 23, 2022 at 16:49
• Customer reviews suggest there are some quality issues but I found the [distributor][1] who indicated fsw is 3 kHz. But you have to decide how fast a response time and ripple of voltage, which are analog tradeoffs, otherwise digital counter it's faster. Do you care? [1]: gledopto.eu Commented Jan 23, 2022 at 17:17

According to the information that the circuit is "common anode", we can guess that the constrol logic is on the "lower" side (ie connected to the R, G, B and W pins).

What is less clear, is how this lower side is constroled.

They speak about "constant voltage" : that might be that R, C, B and W pins are driven at a DC voltage (above GND and bellow V+), but it seems to be a rather strange way to control the LED's brigtness.

I would rather guess that it means that the V+ is constant (ie independent on input voltage).

If so, then we have no clue about how the R, C B and W pins are driven : constant current? Or resistor + PWM?

If you own a scope, then connect a LED, and measure the voltage to see if it is constant or not.

If you don't own a scope, then I would suggest the following procedure :

1. connect a LED as usual between pins V+ and R (the correct way). Nb : use a LED like those made to be used with the device (ie a power LED, not a small signal one) in case your device supplies "huge" current.
2. Put a voltage divider between V- and R using 2 resistors R1 and R2, such that V+*R1/(R1+R2) < 5V (idealy between 3 and 4V, so it is big enough to get good signal, but you keep a reasonable margin with the 5V limit of the arduino). R1+R2 should be greater than 10k.
3. Connect the ground of the Arduino to V-, and the point between R1 and R2 to the analog input
4. sample with a frequency as high as you can, and report back (so to determine if it is PWM or constant current control (accordingly, we can the suggest the most adapted circuit).

simulate this circuit – Schematic created using CircuitLab

NB : if you are happy to stick with this setup, you can just add a capacitor in parallel to R1, and you get an analog value depending on the brigtness (that will not be changing much over time if you get PWM control). For chosing the capacitance, you have to choose your cutting frequency, which is a compromise between removing the variations due to PWM and reacting fast to changes in the brigtness setting.

• Hi! Thanks for your reply! I conected everything as you said. When I put the ZigBee controller 100% open (full light) I get a value of 700-750 in the A0 pin of the Arduino. At 0% (no light) I get a value of 0 on A0. When I give it a % inbetwee I get values of 0's and 700+'s. (for examle: 0, 0, 0, 0, 0, 0, 743, 744, 735, 723, 733, 0, 0, 0, 0, ). --------- Because I connected the V- wire (to the 'front' of the Zigbee controller) there is some leakage so the led won't turn off completely. ------ What size of Capacitor would you suggest?
– Mark
Commented Jan 23, 2022 at 18:37
• Ok, so it seems that it is PWM control (because you read only 2 types of values : 0 and in range 700-750). In order to get the "best" value for the capacitor, I would need 3 more pieces of information : - what values did you choose for R1 and R2 ? - what is the frequency of the PWM (for this, turn on timestamps on the serial monitor, and tell me the duration between 2 successive starts of the 0 sequences) - how fast do you want to react to a change in the "brigtness"? Commented Jan 23, 2022 at 18:54
• Another question : do you want to get an analog value, or do you want the PWM duty cycle? In the second case, a more precise solution would be to connect the signal to a digital pin, and measure the duration of high and low states (nb : it's rather easy to do if you require to measure only the PWM duty cycle for one channel (ie only for red LED chanel for exemple), but not as easy if you want to do it for all 3 or 4 channels) Commented Jan 23, 2022 at 18:57
• Hi! Thanks for your clear reply! I managed to get this schematic to work; i.sstatic.net/T7Lyd.png. I read PWM signals from 0 - 1023 and there is no leakage: the led turn. 1: As in your schematic, 22k and 10k. As in mine: 10k 10k. --- 2: tested with my schematic with a baud rate 9600: 20:01:06.140 -> sensor = 0 20:01:06.140 -> sensor = 0 20:01:06.187 -> sensor = 0 20:01:06.187 -> sensor = 0 20:00:53.104 -> sensor = 1020 20:00:53.104 -> sensor = 1020 20:00:53.151 -> sensor = 1020 20:00:53.198 -> sensor = 1021
– Mark
Commented Jan 23, 2022 at 19:10
• 3: it doesn't need to be fast, it doesn't need to be precise. As long I can differentiate between 0%, 25%, 50%, 75%, 100% I'm happy :). ---- 4: analogue value would be great! --- 5: in the end, I would like to use all RGBW channels.
– Mark
Commented Jan 23, 2022 at 19:10

Simple. Use an optocoupler. Using an appropriate resistor, connect the opto's led to 12V and the ground/signal you want. Then the other side can be connected as an open drain connection to your 5V arduino

Generally like this:

The led controller is already designed for modulating an led, so take advantage of that. And this provides galvanic isolation, so no need to worry about possible ground issues between your controller and the arduino

The rest is a different issue. The frequency of the pwm may not translate so well. Some optoisolators are better at handling the frequency of the pwm. Then your arduino has to read the input pwm and figure it out.

• Hi! Thanks for the schematic! I got a few LDR's lying around. I could re-create this ofc. Thanks for the inspiration!
– Mark
Commented Jan 23, 2022 at 19:12
• @mark diy optos may not work too well with the frequencies involved. Standard optos are cheap. Commented Jan 23, 2022 at 19:21
• Thanks, ill make sure ill get my hand on a pc817
– Mark
Commented Jan 23, 2022 at 19:22
• Ps, I would like to get an analogue value (not a PWM value). Would these work for that?
– Mark
Commented Jan 23, 2022 at 19:23
• @mark i think just by adding a small cap to the line and read it a few times and get the average value. See arduino.stackexchange.com/questions/10041/… Commented Jan 23, 2022 at 19:37