# Touch Screen interfacing with Arduino

Resistive touch screen displays are composed of multiple layers that are separated by thin spaces. Pressure applied to the surface of the display by a finger or stylus causes the layers to touch, which completes electrical circuits and tells the device where the user is touching.

In this chapter we are focusing only on 4-wire resistive touch screen interfacing.

#### Step 1: Components Required

1. Arduino Board
2. Touch Screen
3. Connecting Wires

#### Step 2: Connections to Arduino

1. Connect X1 of touch screen to A0 of arduino
2. Connect X2 to A1 of arduino
3. Connect Y1 to A2 of arduino
4. Connect Y2 to A3 of arduino

#### Step 3: Programming the arduinoHow it works?

##### Measure X axis Voltage

To measure X axis voltage

1.We are going to measure voltage on Y1

pinMode(Y1,INPUT);

2. Make Y2 Tristate

pinMode(Y2,INPUT);

digitalWrite(Y2,LOW);

3. Form a voltage divider in X1(+5V) and X2(GND)

pinMode(X1,OUTPUT);

digitalWrite(X1,HIGH);

pinMode(X2,OUTPUT);

digitalWrite(X2,LOW);

#### Measure Y axis Voltage

To measure Y axis voltage

1.We are going to measure voltage on X1

pinMode(X1,INPUT);

2. Make X2 Tristate

pinMode(X2,INPUT);

digitalWrite(X2,LOW);

3. Form a voltage divider in Y1(+5V) and Y2(GND)

pinMode(Y1,OUTPUT);

digitalWrite(Y1,HIGH);

pinMode(Y2,OUTPUT);

digitalWrite(Y2,LOW);

#### Arduino Code for Touch Screen Interface

```/*=================================
This code demostrates 4-Wire Touch screen
interfacing with Arduino

www.circuits4you.com

4- Wire Touchscreen Connections
A0=====X+
A1=====X-
A2=====Y+
A3=====Y-
=================================*/
#define A0 X1
#define A1 X2
#define A2 Y1
#define A3 Y2
#define Xresolution 320 //128
#define Yresolution 240 //64

void setup()
{
Serial.begin(9600);
}

void loop()
{
int X,Y; //Touch Coordinates are stored in X,Y variable
pinMode(Y1,INPUT);
pinMode(Y2,INPUT);
digitalWrite(Y2,LOW);
pinMode(X1,OUTPUT);
digitalWrite(X1,HIGH);
pinMode(X2,OUTPUT);
digitalWrite(X2,LOW);

pinMode(X1,INPUT);
pinMode(X2,INPUT);
digitalWrite(X2,LOW);
pinMode(Y1,OUTPUT);
digitalWrite(Y1,HIGH);
pinMode(Y2,OUTPUT);
digitalWrite(Y2,LOW);

//Display X and Y on Serial Monitor
Serial.print("X = ");
Serial.print(X);
Serial.print(" Y = ");
Serial.println(Y);
delay(100);
}
```

#### Result

Observe the result on serial monitor. It displays where you have touched on the screen.