• Support
  • Cart
Warefab Warefab
  • Shop
    • Makers
      • Boards
      • Displays
      • Sensors
      • Prototyping
      • Actuators
      • Power Supply
    • Educators
    • IoT & Wireless
      • GSM
      • WiFi
      • Bluetooth
      • Radio
      • LoRa
      • Sensors
    • Parts Library
    • Tools
  • Fab Space
    • Laser Cutting & Engraving
    • 3D Printing
    • CNC Milling & Drilling
    • PCBA, CAD and Firmware
    • Co-Working Space
    • Training
  • IoT
  • STEM
  • Learn
    • Getting Started
      • Basics
      • Scratch-n-Sketch
    • Explore
      • Actuators
      • Arduino
      • Modules
      • Displays
      • Microcontrollers
      • Robotics
      • Sensors
    • Basic Electronics
      • Discrete Components
      • Intergrated Circuits
      • Power Supplies
  • Register
  • Login|
LoginRegister
­
Learn/Explore/Touch Sensor

Close

Touch Sensor

By Dennis

Share this project

Introduction

If you are interested in adding the ‘magic’ of touch to control your electronics project, a capacitive touch sensor module might be the way to go. Our touch sensor module makes it very easy to integrate capacitive touch sensing into you project. In this tutorial we a going to use a touch sensor module to toggle the status of an led.

Parts used

to follow along in this tutorial, you will need to have the following

hardware

  1. capacitive touch sensor
  2. Arduino uno rev3 (or any Arduino board)
  3. Warefab tft touchscreen
  4. Jumper wires
  5. Breadboard
  6. An led
  7. 220 Ohm resistor

Wiring

Once you have all the required components its time to wire our circuit.

Breadboard Layout
– Connect signal pin from the touch sensor to digital pin 7 on the Arduino
– Connect the positive lead of the LED to digital pin 8 on the Arduino
– Lastly, supply power to the circuit.

arduino touch sensor

Connecting the components

arduino touch sensor

Code

Arduino code to use in our project

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//macro definitions
#define sensor_pin 7  //sensor conencted to pin 7
#define led_pin 8 //sensor connected to
 
uint8_t state = false; //boolean to save button state
 
//setup
void setup()
 
{
 
  pinMode(led_pin, OUTPUT); //set led pin as output
  pinMode(sensor_pin, INPUT); //set sensor_pin as input
}
 
//loop
void loop()
{
  if (digitalRead(sensor_pin) == LOW) //check if the touch sensor has been touched
  {
    state = !state; //toggle the value of the boolean state
    
    while (!digitalRead(sensor_pin));
    //as long as the sensor is activated stay in the loop
  }
  digitalWrite(led_pin, state); //set led on/off when a touch event occurs
}

How the Code works

We set our signal pin as digital input pin on the Arduino board

1
pinMode(led_pin, OUTPUT);

Also we set our LED positive pin as digital output pin on the Arduino board

1
pinMode(sensor_pin, INPUT);

in our loop method we check if the sensor has been touched, if a touch event occurs, the ‘state’ variable toggles, which we have used to control our LED to either turn it ON or OFF.
You may note we have a ‘while’loop in our code, this is to make sure only one touch event occurs only when we touch and release.

1
2
3
4
5
6
if (digitalRead(sensor_pin) == LOW)
  {
    state = !state;
    while (!digitalRead(sensor_pin));
  }
  digitalWrite(led_pin, state);

Run the Code

Application

this project can be used as a simple smart switch in a project.

with the inclusion of the display you can get the status of multiple switches in a customised interface

Resources

Code and Circuit diagrams

Share this post

Like this project

Tags

accelerometer Arduino breadboard buzzer color sensor jumper jumpers jumper wires kit learn led PIR programming prototyping scratch-n-sketch Scratch_n_Sketch sensors tcs3200 touch

Feedback

You must be logged in to leave feedback.


Related Projects

  • MMA7361LC 3-Axis Accelerometer


    By Muchiri John

    This Module is a 3-axis Xyz accelerometer using Freescale MMA7361L micromachined ±1.5g or ±6g sensitivity. It's great for a motion sensing or stab...

  • tcs3200_cl_02

    Color Sensor TCS3200


    By Muchiri John

    This module is based on TCS3200 programmable color light-to-frequency converters that combine configurable silicon photodiodes and a current-to-fre...

  • mk04

    PIR Motion Sensor


    By Muchiri John

    A PIR motion sensor, is a small, low power and inexpensive sensor that is used to sense objects emitting low level radiation e.g humans, cats, dogs...

  • ard_piezo_image

    Piezo Buzzer


    By Dennis

    This tutorial shows how to hook up a piezo buzzer and an Arduino Uno board to make a simple sound alarm whose volume can be adjusted . The buzzer i...

  • Arduino_Logo

    Arduino : Getting Started


    By Mercy Ngoiri

    In this lesson we will learn how to set up the computer to get started with Arduino, that is, downloading and installing the software and then open...

  • Arduino_Logo

    Arduino : Introduction


    By Muchiri John

    Arduino is an open-source prototyping platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sens...

Sections

  • Introduction
  • Parts used
  • Wiring
  • Code
  • Application
  • Resources
Paginate View
PDF / Print
Feedback

Get Updates

Customer Service

  • Contact Page
  • Support
  • Distributors
  • FAQ Page

Terms of Use

  • Shipping & Returns
  • Terms of Service

About Us

Electronics Kits, Modules, PCBA, CNC milling, 3D Printing, Coding, Laser Cutting, Training, Fun and many more