The amount of light at any given time influenced the speed of the shutter. Slow shutter speed = blurry pictures.
If you set the camera in P mode, when you look through the view finder you will see the camera meter is telling you what SS and what aperture is going to be used. Without taking pictures - point your camera to outdoor sceneries and indoor sceneries - and see how the meter will reacts to available light constantly. Than, change the ISO setting into higher ISO setting through the menu and see how the meter will react by using faster SS automaticaly.
With nikon d40, for indoor shot don't hesitate to use ISO 1600, good outcome still. Give it go with this setting and that setting. Don't forget it fun that you are after.
So have fun.