How do I drive a TRIAC from a microcontroller (for low voltages)?
Playing with mains can lead to death of drive equipment, load, TRIAC, yourself or users if you get it wrong.   

Try hard not to.   

Use of an isolated driver IC greatly enhances the chances of you and your drive electronics living much longer.  Anything driving mains equipment directly is potentially at mains potential at any time unless you have a properly implemented isolation barrier. This applies to equipment in EITHER mains lead. Being in the "neutral" lead is no guarantee of not experiencing full mains potential.It also applies to any part of the equipment even when "switched off". Only removal from mains by physical disconnection is a certain means of mains not being absent. Then you just have storage capacitors to watch for. 

Drive is from gate to main terminal 1.
 As MT1 is at mains potential your driver is too.

You CAN drive directly if your port MINIMUM drive current at gate MINIMUM voltage meets gate MAXIMUM current need. The gate to MT1 is a silicon junction (or two) and requires a minimum (or greater) current to trigger the coupler reliably. A TRIAC conducts AC bidirectionally once triggered and continues to do so until the holding current in MT1-MT2 main circuit drops below some data sheet defined level.

You are very very very very strongly advised to use an isolated driver such as the
 MOC30xx family optical TRIAC driver. This is a random turn on version that triggers the TRIAC when you trigger the opto coupler but you can get zero crossing versions. The driver comes in various versisons and needs as little as 5 mA or as much as 30 mA max to trigger - see data sheet page 3.

Here is a Fairchild FOD410 zero crossing optocoupled TRIAC driver.

Circuits below are examples only - see data sheet:





Lower voltages:

For a lower voltage- eg 24 VAC, the personal safety aspects are much relaxed, but the microcontroller safety aspects are still a significant consideration. 

When (not if) the small TRIAC shown dies due to enthusiastic experimentation or an excess of exposure to reality, one of the failure modes will be worst-possible-input-hard-shorted-to-worst-possible-output. Murphy loves these. Connecting 24 VAC to almost anywhere on an Arduino will usually spoil its day. 

An opto-coupled TRIAC driver will both provide protection against worst case TRIAC failure and also allow "floating" TRIAC drive - the opto-coupler ouput is not ground referenced or referenced to anything in the drive circuit before the OPTO COUPLER.