HARTLAND — Seven Maine wastewater facilities are receiving $29.7 million in grants and loans for upgrades.

The U.S. Department of Agriculture Rural Development grants were announced Tuesday in Hartland in an event celebrating Earth Day. Nationally, a total $387 million is going to 116 similar projects in 40 states and Puerto Rico.

In Maine, the funds are being used for upgrades to wastewater systems the USDA says will help prevent contamination of the state’s waterways.

USDA Rural Development says it invested $462.5 million in rural Maine communities last fiscal year. Those funds went to projects that improve the economic stability of rural communities.

The Maine grant recipients are: Stonington Water Co., Wiscasset Water District, and the communities of Hartland, Gardiner, Oxford, Van Buren and Danforth.