Hi

I am currently doing a project which can calculate or track the phase of the voltage signal of the mains(120V ac) as well as the current.

how can I do this?

i want to calculate power, p = V*I*cos(phase between voltage and current)

The easy part is a zero voltage crossing detector. Then you need a current zero crossing detector.

Hopefully your load is fairly linear in nature, otherwise the current measurement could be problematic. Is this for a specific situation or a generalized measurement?

I am actually doing a power meter, where we can see how much power an appliance is taking from the outlet

so i know how to get the voltage and current safetly

my problem is that i have to calculate the phase difference of the voltage and current

is giving me headaches

That's the easiest part! Are you thinking in degrees? Arduino trig functions require inputs in radians...

i am aware of the radians

but, my real problem is that since i dont know much with coding

i researched about it, and i found a code that does that

but again, I am trying to understand how to calculate and how to code

Thank You

The next step would be to post your code with code tags, use the </> icon.