How to fade in and out light bulb(220V) (Arduino)
With a relay? You can't.

The relay contacts are either open (lamp fully off) or closed (lamp fully on) and can't switch a relay fast enough to give a dimming effect.







simulate this circuit &ndash; Schematic created using CircuitLab

What you're looking for is a triac controlled dimmer.







simulate this circuit

In this case an opto-coupled triac is used. Your micro would switch the LED D1 on at the appropriate point in the mains half-cycle turning on the triac. The triac stays on until the next zero-cross of the mains and then turns off. At 100 (50 Hz) or 120 (60 Hz) half-waves per second the flicker is not noticeable.

Your code would have to monitor the mains zero-cross somehow, ramp the delay in triggering the triac and pulse the optoisolator at the right time. Plenty of examples on a web search.