Flex Sensor Interfacing with AVR Microcontroller

In this tutorial we are going to interface FLEX sensor with ATMEGA8 microcontroller. In ATMEGA8, we are going use 10bit ADC (Analog to Digital Conversion) feature to do this job. Now the ADC in ATMEGA cannot take a input more than +5V.

Flex Sensor Interfacing with AVR Microcontroller
Flex sensor interfacing with AVR Microcontroller

What is a Flex Sensor?

A FLEX sensor is a transducer which changes its resistance when its shape is changed.  It is shown in below figure.

Now for converting this change in resistance to change in voltage, we are going to use a voltage divider circuit. In this resistive network we have one constant resistance and other variable resistance. As shown in below figure, R1 here is a constant resistance and R2 is FLEX sensor which acts as a resistance. The midpoint of branch is taken to measurement. When resistance R2 changes,  the Vout changes with it linearly. So with this we have a voltage which changes with linearity.

Now important thing to note here is, the input taken by the controller for ADC conversion is as low as 50µAmp. This loading effect of resistance based voltage divider is important as the current drawn from Vout of voltage divider increases the error percentage, for now we need not worry about loading effect.

We are going take two resistors and form a divider circuit so that for a 25Volts Vin, we get a 5Volt Vout. So all we have to do is multiply the Vout value with “5” in the program in order to get the real input voltage.

Components Required

HARDWARE: ATMEGA8, Power supply (5v), AVR-ISP PROGRAMMER, JHD_162ALCD (16x2LCD), 100uF capacitor, 100nF capacitor (5 pieces), 100KΩ resistor.

SOFTWARE: Atmel studio 6.1, progisp or flash magic.

Circuit Diagram and Working Explanation

In the circuit PORTD of ATMEGA8 is connected to data port LCD. In 16×2 LCD there are 16 pins over all if there is a back light, if there is no back light there will be 14 pins. One can power or leave the back light pins. Now in the 14 pins there are 8 data pins (7-14 or D0-D7), 2 power supply pins (1&2 or VSS&VDD or gnd&+5v), 3rd pin for contrast control (VEE-controls how thick the characters should be shown) and 3 control pins (RS&RW&E).

In the circuit, you can observe that I have only took two control pins. The contrast bit and READ/WRITE are not often used so they can be shorted to ground. This puts LCD in highest contrast and read mode. We just need to control ENABLE and RS pins to send characters and data accordingly.

The LCD connections with ATmega8 are as follows:

PIN1 or VSS to Ground

PIN2 or VDD or VCC to +5v power

PIN3 or VEE to Ground (gives maximum contrast best for a beginner)

PIN4 or RS (Register Selection) to PB0 of uC

PIN5 or RW (Read/Write) to Ground (puts LCD in read mode eases the communication for user)

PIN6 or E (Enable) to PB1 of uC

PIN7 or D0 to PD0 of uC

PIN8 or D1 to PD1 of uC

PIN9 or D2 to PD2 of uC

PIN10 or D3 to PD3 of uC

PIN11 or D4 to D4 of uC

PIN12 or D5 to PD5 of uC

PIN13 or D6 to PD6 of uC

PIN14 or D7 to PD7 of uC

In the circuit you can see we have used 8bit communication (D0-D7) however this is not a compulsory, we can use 4bit communication (D4-D7) but with 4 bit communication program becomes a bit complex so we just went with 8 bit communication. (Also check this tutorial: 16×2 LCD interfacing with AVR microcontroller)

So from mere observation from above table we are connecting 10 pins of LCD to controller in which 8 pins are data pins and 2 pins are for control.

Schematic Flex Sensor Interfacing with AVR MicrocontrollerThe voltage across R2 is not completely linear; it will be a noisy one. To filter out the noise capacitors are placed across each resistor in the divider circuit as shown in figure.

For more detail: Flex Sensor Interfacing with AVR Microcontroller


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top