This actually dates back to the day before the Declaration of Independence was signed!
According to slate.com:
Why do we commemorate Independence Day by setting off thousands of small explosions?
Because John Adams wanted us to. Before the Declaration of Independence was even signed, he envisioned fireworks as a part of the festivities. In a letter to Abigail Adams on July 3, 1776, he wrote that the occasion should be commemorated "with Pomp and Parade, with Shews, Games, Sports, Guns, Bells, Bonfires and Illuminations from one End of this Continent to the other from this Time forward forever more.” The first commemorative Independence Day fireworks were set off on July 4, 1777. The Pennsylvania Evening Post wrote that in Philadelphia, “The evening was closed with the ring of bells, and at night there was a grand exhibition of fireworks (which began and concluded with thirteen rockets) on the Commons, and the city was beautifully illuminated.”Not a bad thing to add to your great legacy, John Adams!