Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
This has come up in the past on this forum. In any case, the simplest way is to buy a system that incorporates the optics, sensor, and then outputs some digital stream to represent the data. There are some very inexpensive hand-held CCD scanners that output serial data you could then interface to your micro.
If you have to build one, the easiest way is the "wand" variety where you swipe a pen-like device across the barcode and let a phototransistor read the reflection on the paper of a bright LED. As long as you scan with a fairly constant speed, the length of time across each bar gives you an idea of how wide it is, you then have a lookup table to convert width to 1/0 or whatever. I used the input capture interrupts on my micro when I built such a device. Then I would just subtract the time from the last measurement.