Yes you can, in fact, the safest way to use coffee grounds in the garden is by adding them to your compost pile. However, if you drink a lot of coffee, you will want to watch how much you add to your pile, as coffee grounds should only make up 10 to 20 percent of your total compost volume. If more than 20 percent of your compost is made up of coffee grounds, it might inhibit the beneficial microbes from breaking down organic matter effectively.
Another way to make sure the balance of your compost pile isn’t thrown off by adding coffee grounds is to add four parts shredded leaves to every one part coffee grounds that you add to the pile by weight. Some composters also suggest adding wood ash or lime to the compost to offset the initial acidity of the grounds.
Though it is not really essential, you can add one cup of lime or wood ash for every 10 pounds of coffee grounds you add to the mix. Coffee grounds break down quickly as well, but be sure to avoid adding whole coffee beans to your compost, as they take much longer to decompose than grounds.