Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to build a paint application using Arduino

By Nikhil Agnihotri March 10, 2024

In this project, we’ll build a paint application on Arduino UNO/Arduino Mega that runs on a 3.5-inch TFT touchscreen display based on the ILI9486 driver. The ILI9486 touchscreen has a display resolution of 320×480 pixels. Using a stylus, you can draw, paint, and write on it (even in your own handwriting ). 

Required components 

  1. Arduino UNO/Arduino Mega x1
  2. S 3.5-inch TFT touchscreen display (ILI9486 driver-based) x1

Circuit connections
There are no circuit connections required to build this project. Simply fit the TFT touchscreen shield on Arduino UNO or Arduino Mega, powering the board via a USB or power adapter. You’ll also need to connect Arduino to your computer using a USB cable to upload the sketch. 

The Arduino sketch
After placing the 3.5-inch TFT touchscreen module on Arduino, upload the following sketch.

How it works

The paint application is coded in Arduino’s firmware and is designed for the screen resolution of the 3.5-inch TFT touchscreen module (i.e., 320×480 pixel resolution). The application has a color palette on one side, with the rest of the screen free for painting, drawing, coloring, or writing with the stylus. This space is white, with seven colors available in the palette: black, red, green, blue, cyan, magenta, and yellow. 

It’s possible to choose additional colors by defining constants with their respective color codes in the Arduino sketch. 

When the user touches the stylus on the screen, the application “reads” the contacted pixels. If the pixels correspond to one of the color boxes from the palette, that color is selected for use. If the pixels correspond to the touchscreen’s drawing space, the pixels on the screen are filled in with the color chosen. 

The brush radius for the seven colors is set to ‘3’ pixels. You can change this in the sketch to any value, such as ‘1’ or ‘5’ pixels. The brush radius for white is set to ‘10’ pixels and is used as an eraser in the drawing space. 

Results
The paint application lets users choose a color from the palette with the stylus and draw within the white drawing space, as demonstrated in the following video. 

You can make colorful drawings on this Arduino-hosted paint application like those below. 

You can sketch.

Or you can write in your own handwriting.

The code
The sketch is the basis of this Arduino project and transforms a basic touchscreen interfaced with Arduino into a creative paint or drawing application.

The sketch begins by importing the Adafruit_GFX.h, MCUFRIEND_kbv.h, and TouchScreen.h libraries. The Adafruit_GFX.h and MCUFRIEND_kbv.h libraries enable the TFT display module to work. The Touchscreen.h library is necessary for the “touch” functions to work on the screen via the stylus. This is followed by declaring the color constants and instantiating a TFT display object.

Next, the variables are declared for the touch function configuration, and an object of the touchscreen class is instantiated. The variable ‘BOXSIZE’ is defined to set the size of color boxes in the palette. The variables are declared for the pen radius (the brush size), the previous color, and the current color.

In the setup() function, the touchscreen is initialized, reset, and filled with a white background.

The following lines of code define and display the color palette on the touchscreen.

  tft.fillRect(0, 0, BOXSIZE, BOXSIZE, YELLOW);
  tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, MAGENTA);
  tft.fillRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, CYAN);
  tft.fillRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, GREEN);
  tft.fillRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, RED);
  tft.fillRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, BLUE);
  tft.fillRect(BOXSIZE * 6, 0, BOXSIZE, BOXSIZE, BLACK);
  tft.fillRect(BOXSIZE * 7, 0, BOXSIZE, BOXSIZE, WHITE);
  tft.drawRect(BOXSIZE * 7, 0, BOXSIZE, BOXSIZE, BLACK);

The current color is set to ‘Yellow’ and the GPIO13 connects with the touchscreen’s SCK pin and is set as a digital output. Next, the constants are declared for the minimum and maximum stylus pressure.

The current color is set to ‘Yellow’ and the GPIO13 connects with the touchscreen’s SCK pin and is set as a digital output. Next, the constants are declared for the minimum and maximum stylus pressure.

In the loop() function, the below code is used to “sense” the screen pixels that the stylus touches.

digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    if (p.y < (TS_MINY – 5)) {
      Serial.println(“erase”);
      tft.fillRect(0, BOXSIZE, tft.width(), tft.height() – BOXSIZE, WHITE);
    }
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
    p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);

If a touched point on the screen correspond to a box from  the color palette, that respective color is selected.

    if (p.y < 0) {
      oldcolor = currentcolor;
      if (p.x < BOXSIZE) {
        currentcolor = YELLOW;
        tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
      } else if (p.x < BOXSIZE * 2) {
        currentcolor = MAGENTA;
        tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE);
      } else if (p.x < BOXSIZE * 3) {
        currentcolor = CYAN;
        tft.drawRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, WHITE);
      } else if (p.x < BOXSIZE * 4) {
      currentcolor = GREEN;
        tft.drawRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, WHITE);
      } else if (p.x < BOXSIZE * 5) {
        currentcolor = RED;

        tft.drawRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, WHITE);
      } else if (p.x < BOXSIZE * 6) {

        currentcolor = BLUE;
        tft.drawRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, WHITE);
      }else if (p.x < BOXSIZE * 7) {
        currentcolor = BLACK;
        tft.drawRect(BOXSIZE * 6, 0, BOXSIZE, BOXSIZE, WHITE);
      }else if (p.x < BOXSIZE * 8) {
        currentcolor = WHITE;
        tft.drawRect(BOXSIZE * 7, 0, BOXSIZE, BOXSIZE, BLACK);
      }

Whenever a user selects a different color, the white border around the previous color in the color palette is removed.

    if (oldcolor != currentcolor) {
        if (oldcolor == YELLOW) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, YELLOW);
        if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, MAGENTA);
        if (oldcolor == CYAN) tft.fillRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, CYAN);
        if (oldcolor == GREEN) tft.fillRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, GREEN);
        if (oldcolor == RED) tft.fillRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, RED);
        if (oldcolor == BLUE) tft.fillRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, BLUE);
        if (oldcolor == BLACK) tft.fillRect(BOXSIZE * 6, 0, BOXSIZE, BOXSIZE, BLACK);
        if (oldcolor == WHITE) tft.fillRect(BOXSIZE * 7, 0, BOXSIZE, BOXSIZE, WHITE);
      }

If a color other than white is selected and the stylus touches the drawing space, the pixel that was tapped changes to that same color. The brush radius for colors stays at ‘3’ pixels.

However, it can be set to any value — like ‘1’ or ‘5’ pixels as desired. The lower the pixel size of the brush, the more detailed the painting or drawing will be in the drawing space.

if ((p.y > 5) && (p.y < tft.height()) && currentcolor != WHITE) {
      PENRADIUS = 3;
      tft.fillCircle((p.x-PENRADIUS), (p.y+BOXSIZE) , PENRADIUS, currentcolor);
    }

If white is the chosen color, the brush radius is set to ’10’ pixels, and white is used to erase the current painting or drawing on the screen.

if ((p.y > 5) && (p.y < tft.height()) && currentcolor == WHITE) {
      PENRADIUS = 10;
      tft.fillCircle((p.x-PENRADIUS), (p.y+BOXSIZE) , PENRADIUS, currentcolor);
    }

For this Arduino-based application, you can use a stylus to paint, draw, sketch, and create with your own handwriting.

Wathc the demonstration video here: https://www.youtube.com/watch?v=mJPjSqNTFdI

You may also like:


  • How to use the TCS230/TCS3200 color-recognition sensor with Arduino

  • How to troubleshoot common ESP32-CAM problems

  • How to control LEDs using the MIT App Inventor and…

  • How to build a facial recognition system using ESP32-CAM

  • How to design an Arduino library for an 8-bit IO…

  • How to build a sign-to-speech converter

  • How to get started with MIT App Inventor

  • How computer vision works

Filed Under: Electronic Projects, Video
Tagged With: Arduino, arduinomega, arduinouno, draw, ILI9486, paint, tfttouchscreen, touchscreen, video
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • UART Basic Before Writing Code
  • No Output Voltage from Voltage Doubler Circuit in Ansys Nexxim (Harmonic Balance Simulation)
  • What is the reason for using the -allow_path option in set_clock_groups?
  • Mean offset increase in post-layout simulation of clocked comparator
  • LED driver using PWM

RSS Electro-Tech-Online.com Discussions

  • PIC KIT 3 not able to program dsPIC
  • Fun with AI and swordfish basic
  • Is AI making embedded software developers more productive?
  • Microinverters and storeage batteries?
  • FFC connector white

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How to design a weather station using ESP8266
  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe