The mitzvah of Tefilin is mentioned in this week's parsha, Parshat V'etchanan. In Perek ו, pasuk ח, the Torah says: וּקְשַׁרְתָּם לְאוֹת, עַל-יָדֶךָ; וְהָיוּ לְטֹטָפֹת, בֵּין עֵינֶיךָ And you should bind them for a sign upon your hand, and they should be for frontlets between your eyes.
Clearly, this is a mitzvah from the Torah. However, there were times when people did not necessarily consistently wear tefilin.
In Masekhet Shabbat, daf 49a, Tosfot quote a Midrash that r