As said before, but with too much hedging for my liking, Yes the pips are directly based on the US Navy. In fact having already known the Star Trek pips, when I joined the Navy I could immediately recognize officer ranks by their stripes. While the pips are physically a different object than shoulder or sleeve stripes, they use the same method of distinction, 1 = Ensign 1 + "half pip" (i.e. a dark in the middle pip) = LT JG, while in the Navy it's 1 full stripe and one half stripe. Then 2 full for LT, then 2 1/2 for LTCDR, then 3 full for CDR, then 4 full for Captain. It's that order of full and half versions that is entirely unique to the Navy and Coast Guard and not seen in any other branch or any other military on Earth, which is directly translated to pips in Star Trek.
And yes it goes off the rails for Admirals and Enlisted, but those are much rarer characters so the showrunners didn't seem to bother making those consistent. Until of course DS9. Navy enlisted use chevrons until you reach chief where the 3 chevrons are topped off by a "rocker" that arches over the eagle. Since Star Fleet isn't America, an eagle makes no sense, so there's nothing there. Navy enlisted chiefs get stars above their rocker. A Navy Senior Chief has 1 star, and a Master Chief has 2 stars. This is slightly different with Star Fleet because they have no rocker or rating they just start with a dot, so 1 for Chief, 2 for Senior Chief, etc. While there's only one, there is a 3 star version Master Chief in the Navy, the Master Chief Petty Officer of the Navy (MCPON) has 3 stars, same position as dots for a Master Chief in Star Fleet.
Enterprise took this even further with their low ranking enlisted actually having stripes like Navy Seamen. They even follow the current quirk in the Navy where a Seaman Recruit has nothing (used to be 1 stripe) and an Apprentice moves right to 2 stripes.