Indeed, an approach would be, using the PWM capabilities of your controller. You can generate a PWM waveform by using the analogWrite() function.
Parameters for your function:
pin: the pin to write to.
value: the duty cycle: between 0 (always off) and 255 (always on).
So, if your duty cycle is 255 that means you will have 5V, for 3.3V duty cycle should be somewhere close to 168.
However remember that "On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11".
All you need to know about this matter, you can find here http://arduino.cc/en/Reference/analogWrite
Anyhow, don't forget that when dealing with LEDs - polarity is important and also you should (actually must) have a resistor in the circuit so that the current is limited.
Just one more thing - analogWrite, as you may already know, does not use the digital to analogue converter - it uses the PWM capabilities of you controller. This is just FYI :)
Regarding the issue that you mentioned "To avoid unnessesary power/heat (even if not too much)" as Olin mentioned above, run you LEDs at low currents.
For a standard LED 20mA would be the nominal value. However 20mA is the "recommended" maximum output for your controller outputs :)
Solution: If you think 15mA is OK for the LED and your planning on feeding it at 5V (from a digital output pin) and considering that the diode forward voltage is, as you said, 3.3V use this right here http://led.linear1.org/1led.wiz and you'll see that you're gonna need a 120 Ohm resistor :) A bigger value would lead to a less brighter LED and a smaller value to a brighter one, but keep in mind that a too low value resistor will lead to your controller port being... fried :)
Plan using a lot of LEDs? Try a LED matrix approach, either way I think that what you want is the resistor version, not the PWM.
Good luck and all the best, sorry for the rusty english,
Dan
Looks like a cool project.
literal answer
The optoisolator is not necessary in this application.
Because you are generating the 100 V, 1000 Hz power to drive the EL from relatively isolated battery power (rather than mains power), there is much less of a safety issue.
Systems without an optoisolator typically connect the A1 pin of the triac is connected to the VCC of the microcontroller (in your case, the +3V supply), using "negative gate current triggering" as recommended.
A digital output pin on your microcontroller is connected with a resistor to the gate of a triac.
When the digital logic pulls the gate pin low (towards the microcontroller GND), the triac is triggered and turns all the way on.
As long as the triac is on, the A1 and A2 pins act like they are shorted together.
Turning the triac off is a little more difficult.
(A few systems without an optoisolator connect the A1 pin of the triac to the GND pin of the microcontroller, using "positive gate current triggering", which is not recommended.
As I recently learned,
hooking the the "GND" pin of the microcontroller to A1 and pulling the gate through a resistor to +3 V or even +5 V doesn't work right with a logic level triac.)
Try to draw your schematic and lay out your parts so it's obvious that:
- one end of the inverter output is solidly connected to a harmless-to-the-microcontroller voltage (probably +3V) and pin A1 of the triac
- the other end of the inverter output (the "hot side") is not directly or indirectly connected to anything anywhere near the microcontroller -- except for the triac, and even then the hot side is only indirectly connected through the EL wire to pin A2 of the triac.
alternate approach
If you're only going to have one strand of EL wire,
why don't you connect it directly to the inverter output,
and use a FET (rather than a triac) to connect and disconnect the inverter input to the +3 V power?
Best Answer
Arduino Outputs
Some controllers have "5V tolerant" inputs, so you can provide 5V from your Arduino and the robot will register a logic high and not be adversely affected by the over-voltage signal. I'm not sure if the robot has this feature; you'll probably have to check the datasheet for the microcontroller in the robot. If it does not have this feature, yes, you can get away with a 5V -> 3.3V converter using a voltage divider.
You need two resistors on each output pin, in this configuration:
\$V_{in}\$ is your 5V signal from the Arduino, \$V_{out}\$ needs to be 3.3V or less. These voltages are related by the equation:
$$ V_{out} = V_{in} * \frac{R_2}{R_1 + R_2} $$
I suggest that you could use \$R_2 = 33\mbox{ }k\Omega\$ and \$R_1 = 22\mbox{ }k\Omega\$ for a safe output of 3V. Other combinations, or higher-tolerance resistors, could get you closer to 3.3V or reduce the power these resistors consume, but that's probably not necessary.
Arduino Inputs
I'm not sure what the interface is on that robot (since you didn't provide a datasheet or schematic), but I'm guessing that there will be some signals that are output by the robot and are used as inputs to the Arduino.
The outputs from the robot will be at 3.3V or less, while the Arduino (according to the "DC Characteristics" table in the ATmega datasheet) expects that the following inequality will hold for input high voltage \$V_{IH}\$:
$$ V_{CC} + 0.5 >= V_{IH} >= 0.6 * V_{CC}$$
Practically, this inequality means that your Arduino requires 3V minimum inputs before it will register a logic-high signal. The robot's controller may meet these requirements, or it may not. (Note that the I2C bus requires \$0.7 * V_{CC}\$, or 3.5V, which will not happen).
For example, a 3.3V Arduino may only provide ~2.4V as a logic high. You can't connect a 3.3V Arduino to a 5V Arduino 2.4V on an input pin would be ignored by the 5V Arduino.
What to do
First and foremost, find and read the datasheets for the controllers on your robot and Arduino. The Arduino's ATmega32 datasheet is here.
If the robot controller tolerates 5V inputs, and provides 3V or greater outputs, then you're good to go.
If not, you need a level translation or level shifting circuit. This can be created from discrete elements like resistors and transistors (especially easy in the 5V -> 3.3V direction), from generic level translators like the 74ALVC, or from protocol specific translators like the PCA9306 for I2C.
Alternatively, use a microcontroller that runs at 3.3V. Sparkfun sells a 3.3V "Arduino Pro" board, or PJRC offers a 3.3V Teensy. If you're willing to step away from the Arduino world, there's a lot of processors that run at 3.3V.