The reasons for joining either the Union or Confederate Army were complex and often personal. Union soldiers, for the most part, did not join the army with the expectation that they were fighting to free currently-enslaved individuals. Likewise, few average Confederate soldiers joined the army with the expectation that they were fighting to spread the institution of slavery or even maintain the institution of slavery. Union soldiers may have joined the army hoping to preserve the Union, while Confederate soldiers may have joined the army hoping to create the Confederacy.
There are two important things to keep in mind when discussing the reasons for joining either army. The first thing to remember is that, at the time, war and battle were described in terms of glory and adventure. Sentiments about battle and war were instilled by poems such as "The Charge of the Light Brigade" and popular literature focused on the heroics of generals and soldiers. This, combined with the popular opinion that the war would be over in weeks or, at most, a few months, led many individuals to volunteer early on in order to avoid missing out. Early volunteers largely joined because they thought it would be an experience worth having. Later in the war, when the actual horror was more well-known, drafts in both the Confederacy and the Union forced new recruits into the armies. Many of these likely fought because they were afraid of the punishments of desertion or because they had no other options.
The second thing to remember is that individuals did not necessarily think of themselves as Americans at the time; they certainly did not think of themselves as Americans first. Instead, people thought of themselves as Virginians, Minnesotans, and so on—Pride in one's state was more important than pride in the nation, and state office was often viewed as more important than federal office. Virginians were not necessarily fighting for the Confederacy as much as they were fighting for Virginia.
Slavery may have been at the forefront of some individuals' reasoning, but without letter and diary excerpts, it is difficult to tell how widespread the cause of slavery or abolition was among rank-and-file soldiers.