I am working on a project using an Arduino that needs to calculate the area of a polygon made up of many points. I use surveyor’s theorem,

But the points are in random order, not (counter)clockwise. Some make lines that cross, and they make polygons like a bow-tie or hourglass, which don’t work for the surveyor’s theorem, so I need to sort them in (counter)clockwise order. what is the easiest way to do this?
You could find the center of gravity
(cx,cy)of the points and then calculate the angles of the points relative to(cx,cy).Then sort the points by angle.
Just beware that a random set of points does not describe a single unique polygon. So this method will just give you one of the possible polygons, and not necessarily the polygon you would have obtained if you had manually connected the dots.