Why doesn't my pinhole camera work? We all know that light travels in straight a line, which can be proved by pinhole imaging as in the picture shown :

But when I'm doing this little experiment with an apple, no matter how I change the distance between the object and the pinhole, an image can never be observed on the cardboard behind. So what's going wrong? Please help!

 A: Take a look at this picture - and ask yourself why the operator of the camera has the cloth over his head (the cloth is black on the inside) as he is looking at the back of his camera - which has a piece of ground glass where the image from his pinhole camera is forming:

This used to be how photography was done:
Align the camera to the subject, focus (if you had a lens - pinholes don't need focusing). Cover the aperture. Insert photographic plate. Tell subject to stand still and stop breathing. Remove protection from photographic plate. Open aperture. Light magnesium to produce lots of light. Close aperture. Put protective cover back on photographic plate. Take plate to darkroom. Develop. Fix. Rinse. Dry. 
The pinhole is tiny - not a lot of light comes through. All the other light from the environment will drown out the image. You need to make sure that the only light you see is from the object.
The simplest "pinhole camera" is formed by the leaves on a tree. Did you ever notice how the sunlight coming through the leaves makes circles? Those are "pinhole camera images" of the sun. And when there is a partial eclipse of the sun, those circles turn into little crescent shapes:

Which only goes to show that a pinhole camera works really well when there is more light coming from the subject (in this case, the sun) than from any other object.
Incidentally, you can sometimes get a similar effect in a dark church when a single beam of (sun) light comes through a hole in a dark window: when clouds pass near the sun, you will see their image on the floor/wall of the church.
A: It actually is providing an image, you just cannot see it because of contrast.  The light you have in the picture is flooding the room with enough ambient light that the image that is actually formed has no contrast.


*

*Pinhole camera image quality heavily depends on the pinhole size. 
However, the smaller the pinhole, the "dimmer" the image will be,
this is the problem that you have.

*In order to be able to view the image you will need to make the
pinhole basically in a box.  The box could be an entire room (e.g.
cover all windows in a room with aluminum foil so it is very dark,
then prick a pinhole in the foil on one of the windows) or a smaller
box with a "viewing screen."  The key thing is that whatever "box"
you use needs to be relatively dark inside.


A viewing screen can be something clear but diffuse, like parchment paper or privacy glass.  Even with the viewing screen, you need to somehow make it dark enough so that your eyes can see it.
You could also make an enclosure large enough for you head to fit into, but still maintain a good level of darkness.
If you have an old webcam, this might work inside of an enclosed box, then you can view the image on your computer.
This is one of the things that makes using pinhole cameras in demonstrations difficult, you want the object being imaged to be well lit, but you need the viewing screen to be dark.
