For the new Mazda Keyfob, here is the way to change the battery. Applicable to 2020 year models and newer.
Change your battery and still having issues detecting key? Check out to remove power saving feature:
https://www.youtube.com/watch?v=7sO9Nud2Xr8