Electronic and Computer Resources - Parallel Port Interfacing and Programming using Turbo C

BACK           HOME

## Interfacing a Sensor

Most sensor systems provide analog voltage level. Before the computer can use the information, this must be converted to digital because computer can only understand digital signals. One electronic component that can convert analog signals to digital is an operational amplifier or op-amp.  Op-amp circuit does not only help in converting analog to digital signals but also provide filtering, amplification and corrections of non-linearities of the signals from the sensor.

The figure below shows an op-amp circuit interfacing a phototransistor to the computer port.

In this circuit, the op-amp acts as a comparator. It will compare the two input voltages between its inverting(-) and non-inverting(+) input pins. If the non-inverting input voltage is greater than the inverting input voltage, the output of the op-amp will swing to a high voltage equal or near to the supply voltage. If the inverting input is lesser than or equal to the non-inverting input, the output will swing to low voltage equal or near to ground. Thus, the op-amp�s output is digital in nature since it has only two possible voltage levels.

In the interfaced circuit above, the voltage of the non-inverting input is usually higher than the inverting input if the phototransistor senses dark. This because the transistor is turn off or in cut-off operation when it does not sensed light. If the phototransistor senses light, it will let current to pass through. So the voltage that will be sensed to the non-inverting input of the op-amp will be getting smaller. Once this voltage will equal or be lesser than the voltage of the inverting input, the output will go low. And if the phototransistor will begin to sense darkness again, the voltage in the non-inverting will begin to rise. Once its magnitude will become higher than the inverting input, the output will swing back to high. The voltage in the inverting input of the op-amp acts as a reference voltage.

The following is a sensor programming and interfacing problem.

Problem:

A phototransistor is interfaced to the status port pin S3. Write a program such that if the phototransistor senses darkness, the LED that is also interfaced to D0 will light for one second. If the sensor senses light, the LED is off. If a key is pressed in the keyboard, the program will end.

Interfaced circuit diagram

Interfacing Circuit Diagram

Here is the link of the source code of the program: sensor.cpp

BACK            HOME

Contents

Parallel Printer Port

Electronic and Computer Resources - Parallel Port Interfacing and Programming using Turbo C

For questions, corrections and suggestions,

email to: [email protected]

Hosted by www.Geocities.ws