Technically speaking, the D3100 is a better camera than the D40:
- Better color depth
- More focus points
- CMOS sensor (vs. CCD in D40)
- Higher light sensitivity
- 11 vs. 3 autofocus points
- and the list goes on...
There are 3 possible solutions to your problem:
1) And I think this is the most likely one...the D40 is a simple camera with very few options. For all intents and purposes, it's a point and shoot with a DSLR sticker on it. You're probably used to shooting a certain way, and the D3100 options need to be tweaked. Read up in the manual on how the autofocus is set up and change it if you need to.
2) You're not comparing apples to apples. Since you no longer have the D40, it's impossible to do some direct comparison shots. The samples you have posted don't really mean much of anything.
3) Your D3100 is defective. These things are mass produced. It happens.