Interfacing Atmega328P with MOC3021 (through a series LED)

Dear All,
I have a simple query. Please refer to the diagram.

Can I attach an LED (with resistor ) in series with Atmega328P pin and MOC3021 input ?

Depends a bit on the LED and the supply voltage of the uC. The led in the MOC has a forward voltage of 1,15V typical. A red LED around 2V and a blue/white around 3V. In series with the red that's 3,15V and with the blue/white it's 4,15V.

If Vcc is 3,3V you can forget it. And even with 5V Vcc in series with a blue/white LED it's just a bit tight. A red led in series is possible but

  1. Change the resister value
  2. remember the current is a lot more voltage dependent with a ed in series because the lower resistor value. Fine if you have a stable 5V, not fine if it can drop a bit (like USB power).

Why do you want to do this?

If you just want an indication of the opto being on just wire the resistor and LED in parallel to the opto. You still need a series resistor for the LED in the opto as well.