Using a KY024 in order to find the initial position

Hi all, I have a stepper motor and it should go to his "home" position everytime I turn it on.

Let me explain:

The stepper work with buttons (left and right) but of course everytime I turn it on it's not in the initial position. I've found sort of a solution via google and spent all day toying around with that KY024. The sensor does work but how should I code it in order to: "boot-find magnet (I'll put the magnet exactly where the initial position will be)"

Any ideas?

Thank you