please tell me if this method contain any risk.
As-is, it's no more risky than any other AC project.
Adapting that circuit (or a similar circuit) for the Arduino could be VERY RISKY! You have to electrically isolate the low-voltage Arduino (and the user) from the AC power (usually optically) and you have to isolate the phase-detection circuit (optically or with a transformer)
I've made a phase-controlled incandescent light dimmer (a long time ago with a different microcontroller) and in my research I've noticed that motor-speed controllers use a different circuit from a light dimmer. Sorry, I don't know exactly what the difference is... It does use the same principal. I've also noticed that a fan speed controller that you buy from a home improvement store is a different product from a light dimmer.
another method i`m trying is to use relay to switch speed, but i cannot find any working example. that way i have to use 3 relay to control a fan.
If your ceiling fan has a 3-way speed-switch, you should be able to "reverse engineer it" and replace the switch with a relay (or maybe two).
If it's actually 2-speeds plus "off", it might simply have a diode. (A diode cuts-off the power for half the AC cycle.) I think my ceiling fans may only have high, low, and of. But, I'm not at home right now and I don't remember...
I've used a diode as a high-low light dimmer (and for a heating pad that was too hot), but I have NOT tried a diode with a motor. It's not a recommendation or suggestion, it's just a guess about how they might be doing it.
If a diode works, you'd need two relays. One to bypass the diode, and one to turn the fan on & off. If you try a diode, do it at your own risk! Don't blame me if the motor overheats and your house burns-down! :smiling_imp: