I don't remember much about the cartoon or anime but there is a scene in which thunder falls on a small robot and from then (the hero is a boy) it's like the hero controls the robot and fights the evil. When I think of it I remember the Big Hero 6 robot in a smaller size. It was nearly 5 to 9 years I guess or in the middle of 5 to 9 years.
Orphaned American boy Joey lives with his grandmother, working at a restaurant in the West Coast city of Center City (センターシティ Sentā Shiti, based on Los Angeles), while going to school. Upon hearing of a new toy robot called the Heybo, Joey believes that getting one will make his life better, turning him into a hero to protect his friends and family. However, he cannot afford to buy it on his meager salary. His luck changes when he picks up a broken down Heybo abandoned by a school bully. He tries to fix it, naming it Heroman, but does not have any luck in getting it to work. However, when it gets struck by a bolt of strange lightning, it transforms into a giant robot, just in time to save his friend Lina from impending danger. Now, Joey and Heroman are Earth's only defense against the evil insectoid Skrugg (スクラッグ Sukuraggu) aliens, unknowingly summoned to Earth by Joey's science teacher.
Cover of first volume of Heroman manga
Originally found by searching for anime poor kid giant toy robot, and remembered by me as a case involving an anime with a toy robot turned defender.