Here is how to turn an old phone into a surveillance camera with motion detection.
Keeping recordings in the cloud usually requires a paid plan.
Local storage (on the phone or an SD card) is free, but the oldest footage is usually deleted automatically once it fills up.
If the camera will show people, please be mindful of their privacy.