Color Sensing Made Smart: A Guide to Building a PIC Microcontroller IOT system.

Vinaykumar Pitla
Color Palette Charts [4]

Are you tired of manually matching colors or struggling to identify shades with the naked eye? If so, it's time to consider building a smart color sensing system that can do the work for you. In this blog post, we'll walk you through the process on how to building a color sensing system using a PIC microcontroller, an ESP8266 Wi-Fi module, and an Android app.

This mini-project is designed to detect the color of a surface and display its corresponding color code on an Android app.

Flow of contents:

1. Project Flow
2. Components Used
3. Working
3.1 PIC Microcontroller (PIC18F4520)
3.2 Color Sensor (TCS3200)
3.3 ESP8266 12-E / NODEMCU
3.4 Firebase Realtime Database
3.5 Android App
4. Source Code
5. Prototyping
6. Future Scope & Challenges
7. Conclusion
8. References

Project Flow

Project Block Diagram

The color sensor captures the RGB color of the object, which is then transmitted to the microcontroller for processing and preparation for transmission to the ESP8266 NodeMCU. The NodeMCU then sends the RGB data to a cloud database, where it is stored for later retrieval. Finally, the RGB data can be retrieved from the cloud database and displayed on an Android app. This process allows users to accurately capture the RGB value of an object and use it for various applications, such as color matching and product design.


Components Used

Here are the detailed list of all the components.


Working

In this section we will discuss the working of the project in depth to get more insights about it.

PIC Microcontroller

PIC18F4520 Pinout

This is an Industry graded microcontroller which has 40 pins and is mainly used in automation and embedded systems.
Main-Features:
● Consists of 40 pin out of which 36 pins are GPIO.
● 32kB of Flash Memory
● Inbuilt Oscillator
● 256 bytes of EEPROM memory
● Enhanced-USART port for serial communication along with provision for SPI & I2C.
● Dedicated 8bit,16 bit timers

We have used PIC18F4520 that will get the RGB value from the color sensor and send it to NodeMCU via UART Protocol.

PICkit-3

PICkit-3 Programmer

We require a programmer loader to load/burn code on the PIC microcontroller. PICkit-3 is a programmer which helps in burning/erasing the code into PIC18F4520. We have to connect as specified to the pins.

Color Sensor

Color Sensor Module [ TCS3200 ]

TCS3200 has a main photodiode array in center which is an 8 x 8 Matrix (i.e. total of 64 places) out of which Red, Green, Blue and Clear take up each 16 places. Also there are 4 LED’s to illuminate the surface.

When color sensor module is placed on surface with the help of RGB array filter it gets the individual colors and outputs PWM signal whose value varies with intensity of color.

Pin Description

We have interfaced color sensor to PIC microcontroller as given below

Color Sensor to PIC Microcontroller

Here, OUT pin will be input to PIC18F4520 which takes PWM signal of each color RGB and convert it to integer to get Individual RGB values.

Code explained further.

ESP8266 12E

ESP8266 12E / NodeMCU Pinout

ESP8266 is responsible for sending data to database for storing. We have interfaced PIC18F4520 with ESP8266 via UART protocol.

UART (Universal Asynchronous Receiver/Transmitter): In this protocol two devices are connected together where TX of one device connected to RX of other device and vice-versa.

ESP8266 NodeMCU will get the RGB value from PIC18F4520 which will then send these values to the Cloud (Firebase Realtime Database).

Code explained further.

PIC Microcontroller to ESP8266 NodeMCU [ UART Communication ]

Firebase Realtime Database

We have used firebase as cloud database for storing and retrieving the data. In firebase we used realtime database wherein data is updated in realtime which is helpful for the module.

Firebase Realtime Database View

Android Studio

We have implemented android app using android studio where we wrote frontend in XML and Backend with Java.


Code Explanation

Complete code with details is upload on GitHub here.

Software's Used

MPLAB X-IDE - For writing the code and generating hex file.
MPLAB X-IPE - For loading the generated hex onto the microcontroller.
Arduino IDE - For writing code to ESP8266 NodeMCU module.

Getting the Color Code

Code to get the color code from TCS3200

Sending Code to ESP8266 NodeMCU

We will have to initialize UART communication protocol by setting proper configuration bits in the PIC18F4520 more details on github here <gh link>.
We have used UART_Write() function which takes in string as an argument and send it serially to ESP8266.

UART Code to send Red Color Code

Sending to Firebase from ESP8266

We have to do two things in order to send RGB color to Firebase Realtime Database.
1. We have to receive the color code by initiating UART protocol in ESP8266 by using the function "Serial.begin(9600)" (where 9600 is the baud rate).
2. Now we have to send the data to Firebase.

Code to receive the RGB code and send it to Firebase.

Challenges

We have faced many challenges in making this project viable,

  1. When setting up the connection between PIC18F4520 and Computer via PICkit-3 so to burn code into it. We got errors regarding PICkit-3 not getting target voltage which we figured is due to fluctuating power supply so we switched to DC Adapter for constant voltage.
  2. This was a long running challenge where the microcontroller is sending broken color sensor data to ESP8266 via UART.

Conclusion

In conclusion, we have successfully implemented the minimum viable product (MVP) of our color sensing project. Throughout this journey, we encountered challenges, made adjustments, and arrived at an efficient solution.


Links

[4] Unsplash: Color Palette


Collaborators

  1. Pitla Vinaykumar - Linkedin
  2. Kadwe Prathmesh - Linkedin
  3. Ghangale Vaishnav - Linkedin
  4. Kasturi Mahesh - Linkedin

Thankyou