I’ve got two techniques to motivate students during class. One is a bit touch-feely and the other is a little more “hard touch”.
First: learn the students names and use them. Students, like all people, want to be known. Using their names shows that I care about them as people and it seems to draw them into the class more and make them want to do their best.
Second: catch them succeeding. As a new trainer (one who was barely able to present the material and manage the class) I found that I only had time to respond to students who were having problems. So students only interacted with me when they were failing. As I got better at teaching, I had more time, so I used it to visit with students while they were not having problems. I asked permission to watch them code and I could almost always find something they were doing right that I could praise. I “caught” them succeeding and so we built a series of positive interactions together.
Not only did the students seem to feel better and be more motivated but it became my own best way of learning. By seeing what the students were doing I often discovered approaches and techniques that I had not known or considered. Sometime it seems that much of what I know about my course content was actually taught to me at some point by a student. And that is a real win-win.