In a rapidly evolving digital landscape, sensor-based systems that integrate environmental cues with instantaneous responses are increasingly pivotal across industries-from automated manufacturing and quality control to home security and interactive art installations. This project, a colour-triggered alarm, exemplifies such innovation by harnessing a modern optical sensor to identify a specific hue, in this case, red, and activate an audible alert when that colour is detected. The design capitalizes on the TCS3200 colour sensor's ability to convert light intensity into a measurable frequency output, which the Arduino microcontroller then interprets in real time. By merging precise sensor calibration with robust programming, this system offers a seamless and effective solution for environments where immediate visual cues are critical.
The core functionality of this project revolves around the continuous monitoring of ambient light conditions, where the TCS3200 differentiates between various colours based on their intensity levels. When the sensor identifies a predominant red signal, the Arduino processes the data and promptly triggers a buzzer, ensuring that the detection of the specified colour is unmistakably signalled. This method not only enhances safety and security measures but also demonstrates the practical applications of sensor-driven technology in real-world scenarios. Whether it's used to alert personnel in hazardous environments or to initiate specific actions within a larger automation system, the colour-triggered alarm serves as a versatile and reliable component.
Moreover, this project underscores the broader potential of integrating low-cost, readily available components to create intelligent systems capable of adaptive responses. By using the TCS3200 in tandem with the Arduino, the design remains both affordable and easily scalable, allowing for modifications that can tailor the system to a wide array of applications. The detailed documentation and step-by-step assembly instructions provided herein are designed to guide both hobbyists and professionals alike in constructing a functional and effective colour-triggered alarm.
Components Required
- Arduino Uno
- TCS3200 Colour Sensor
- Buzzer
- 9V Battery or USB Power Source
- Breadboard
- Jumper Wires
Circuit Diagram
Component Connections
1. Connecting the TCS3200 Colour Sensor to the Arduino
The TCS3200 sensor identifies colour by converting light intensity into a frequency output. It features several control pins that allow you to select different colour filters and adjust the sensor’s output frequency. The sensor communicates with the Arduino through digital I/O pins.
Wiring the TCS3200 to the Arduino:
- VCC (Power): Connect to the Arduino’s 5V pin.
- GND (Ground): Connect to the Arduino’s GND pin.
- S0 & S1 (Frequency Scaling Control): Connect to digital output pins (for example, D8 and D9). These pins set the scaling factor for the output frequency.
- S2 & S3 (Colour Filter Selection): Connect to digital output pins (for instance, D10 and D11). They determine which colour—red, green, or blue—the sensor will detect.
- OUT (Frequency Output): Connect to a digital input pin (e.g., D7) on the Arduino to read the sensor’s output.
Why use these pins?
They allow the Arduino to precisely control the sensor's settings and to capture the frequency corresponding to the detected colour intensity.
2. Connecting the Buzzer to the Arduino
The buzzer serves as the audible alert mechanism. It is activated by the Arduino when the sensor identifies the target colour.
Wiring the Buzzer to the Arduino:
- Positive Terminal (+): Connect to a digital output pin on the Arduino (e.g., D12).
- Negative Terminal (–): Connect to the common GND on the Arduino.
Why use a buzzer?
The buzzer provides immediate audible feedback, ensuring that any detection of the specified colour is promptly signalled.
3. Powering the System
To ensure reliable operation of both the sensor and the buzzer, follow these guidelines:
- Powering the Sensor and Buzzer:
Connect the TCS3200 sensor’s VCC to the Arduino’s 5V supply.
The buzzer is powered directly through the digital pin (via appropriate current-limiting if needed) and shares the Arduino’s ground. - Supplying Power to the Arduino:
Use a USB cable connected to a computer or a power bank. Alternatively, a 9V battery can power the Arduino through the VIN pin, which safely regulates the voltage.
Important:
Avoid connecting the 9V battery directly to the 5V pin to prevent damaging the board. Always route higher voltages through the VIN pin or a dedicated voltage regulator.
4. Installing the Components on the Project Platform
- Mounting the TCS3200 Sensor:
Secure the sensor onto your breadboard or chassis, ensuring it faces the area to be monitored. A stable and unobstructed placement is critical for accurate colour detection. - Setting Up the Buzzer:
Place the buzzer in a position where its sound can be heard clearly. Ensure its wiring is neat and securely connected to the Arduino. - Final Assembly:
Connect all components on a breadboard, verifying each connection against the schematic. This careful setup minimizes errors when uploading and running the code.
5. Uploading the Code to the Arduino
- Open the Arduino IDE on your computer.
- Copy and paste the provided code into a new sketch.
- Connect your Arduino via USB to your computer.
- Select the correct board type and port from the IDE settings.
- Click the Upload button to transfer the code.
Once the code is running, the Arduino will continuously monitor the TCS3200’s output. When the sensor detects a dominant red colour, it will activate the buzzer, signaling an alert.
CODE
// Define pins for the TCS3200 colour sensor
const int S0 = 8;
const int S1 = 9;
const int S2 = 10;
const int S3 = 11;
const int sensorOut = 7;
// Define pin for the buzzer
const int buzzerPin = 12;
// Variables to store the frequency values for each colour
int redFrequency = 0;
int greenFrequency = 0;
int blueFrequency = 0;
void setup() {
// Set sensor control pins as outputs
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
// Set sensor output and buzzer pins
pinMode(sensorOut, INPUT);
pinMode(buzzerPin, OUTPUT);
// Configure the frequency scaling to 20% (adjustable)
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
// Initialize serial communication for debugging
Serial.begin(9600);
}
void loop() {
// --- Reading Red Colour ---
// Set sensor to detect red
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
redFrequency = pulseIn(sensorOut, LOW);
// --- Reading Green Colour ---
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
greenFrequency = pulseIn(sensorOut, LOW);
// --- Reading Blue Colour ---
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
blueFrequency = pulseIn(sensorOut, LOW);
// Debug: Print the frequency values
Serial.print("Red: ");
Serial.print(redFrequency);
Serial.print(" Green: ");
Serial.print(greenFrequency);
Serial.print(" Blue: ");
Serial.println(blueFrequency);
// Define a threshold for red detection (calibration required)
int redThreshold = 25;
// Check if red is the dominant colour and below the threshold (indicating high intensity)
if (redFrequency < greenFrequency && redFrequency < blueFrequency && redFrequency < redThreshold) {
// Activate the buzzer to signal detection of red
digitalWrite(buzzerPin, HIGH);
} else {
// Turn off the buzzer if red is not detected
digitalWrite(buzzerPin, LOW);
}
// Short delay to stabilize readings
delay(100);
}
CODE EXPLANATION
1. Defining Pins and Variables
// Define pins for the TCS3200 colour sensor
const int S0 = 8;
const int S1 = 9;
const int S2 = 10;
const int S3 = 11;
const int sensorOut = 7;
// Define pin for the buzzer
const int buzzerPin = 12;
// Variables to store the frequency values for each colour
int redFrequency = 0;
int greenFrequency = 0;
int blueFrequency = 0;
- const int S0 = 8; This line creates a constant variable named S0 and assigns it the value 8. This tells the Arduino that the sensor’s S0 pin is connected to digital pin 8.
- const int S1 = 9; Similarly, S1 is set to digital pin 9.
- const int S2 = 10; This assigns digital pin 10 to the sensor’s S2 pin.
- const int S3 = 11; Here, S3 is assigned to digital pin 11.
- const int sensorOut = 7; The sensor’s output, which gives us the frequency (representing the colour intensity), is connected to digital pin 7.
- const int buzzerPin = 12; This sets the buzzer’s connection to digital pin 12. When we want the buzzer to sound, the Arduino will send a signal through this pin.
- int redFrequency = 0; This creates a variable to hold the measured frequency for the red colour. It starts at 0.
- int greenFrequency = 0; This variable will store the frequency value for the green colour.
- int blueFrequency = 0; This variable holds the frequency value for the blue colour.
2. Setup Function
The setup() function runs one time when the Arduino starts. It is used to initialize settings like pin modes and serial communication.
void setup() {
// Set sensor control pins as outputs
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
- pinMode(S0, OUTPUT); This tells the Arduino that pin S0 (pin 8) will be used to send signals (an output).
- pinMode(S1, OUTPUT); Sets pin S1 (pin 9) as an output.
- pinMode(S2, OUTPUT); Sets pin S2 (pin 10) as an output.
- pinMode(S3, OUTPUT); Sets pin S3 (pin 11) as an output.
All these pins control the sensor’s settings such as which colour to detect.
// Set sensor output and buzzer pins
pinMode(sensorOut, INPUT);
pinMode(buzzerPin, OUTPUT);
- pinMode(sensorOut, INPUT); This configures the sensor’s output pin (pin 7) as an input, because the Arduino will be reading data from it.
- pinMode(buzzerPin, OUTPUT); This configures the buzzer’s pin (pin 12) as an output, so the Arduino can send a signal to make the buzzer sound.
// Configure the frequency scaling to 20% (adjustable)
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
- digitalWrite(S0, HIGH); This sends a HIGH signal (5V) to S0.
- digitalWrite(S1, LOW); This sends a LOW signal (0V) to S1.
Together, these two lines set the sensor’s output frequency scaling. In this case, it is adjusted to 20% of the maximum frequency, which helps in managing the sensor’s signal for better readings.
// Initialize serial communication for debugging
Serial.begin(9600);
}
- Serial.begin(9600); This starts serial communication at 9600 baud (bits per second). It allows the Arduino to send text data to your computer, which is useful for debugging and checking sensor values on the Serial Monitor.
3.Loop Function
The loop() function runs continuously after the setup. It reads sensor data, processes it, and then acts based on the results.
void loop() {
// --- Reading Red Colour ---
// Set sensor to detect red
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
redFrequency = pulseIn(sensorOut, LOW);
- digitalWrite(S2, LOW); and digitalWrite(S3, LOW); These lines set the sensor to filter for red light by adjusting its internal configuration.
- redFrequency = pulseIn(sensorOut, LOW); This reads the duration of the pulse coming from the sensor’s output pin (pin 7) while it is LOW. The measured pulse width is stored in redFrequency and represents the intensity of the red colour.
// --- Reading Green Colour ---
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
greenFrequency = pulseIn(sensorOut, LOW);
- digitalWrite(S2, HIGH); and digitalWrite(S3, HIGH); These change the sensor’s settings to filter for green light.
- greenFrequency = pulseIn(sensorOut, LOW); This line measures and stores the frequency value for the green colour in the greenFrequency variable.
// --- Reading Blue Colour ---
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
blueFrequency = pulseIn(sensorOut, LOW);
- digitalWrite(S2, LOW); and digitalWrite(S3, HIGH); These lines set the sensor to filter for blue light.
- blueFrequency = pulseIn(sensorOut, LOW); This measures the pulse width corresponding to the blue light intensity and stores it in blueFrequency.
// Debug: Print the frequency values
Serial.print("Red: ");
Serial.print(redFrequency);
Serial.print(" Green: ");
Serial.print(greenFrequency);
Serial.print(" Blue: ");
Serial.println(blueFrequency);
- Serial.print("Red: "); Prints the text “Red: ” to the Serial Monitor.
- Serial.print(redFrequency); Prints the value of redFrequency next to the label.
- Serial.print(" Green: "); Prints the label for the green value.
- Serial.print(greenFrequency); Prints the measured green frequency.
- Serial.print(" Blue: "); Prints the label for the blue value.
- Serial.println(blueFrequency); Prints the blue frequency and moves to a new line.
These lines help you see the sensor’s readings in real time, which is helpful for calibration and debugging.
// Define a threshold for red detection (calibration required)
int redThreshold = 25;
- int redThreshold = 25; This creates a variable called redThreshold with a value of 25. This threshold is used to decide if the red colour intensity is strong enough to trigger the alarm. You might need to adjust this number depending on your environment and sensor calibration.
// Check if red is the dominant colour and below the threshold (indicating high intensity)
if (redFrequency < greenFrequency && redFrequency < blueFrequency && redFrequency < redThreshold) {
// Activate the buzzer to signal detection of red
digitalWrite(buzzerPin, HIGH);
} else {
// Turn off the buzzer if red is not detected
digitalWrite(buzzerPin, LOW);
}
- if (redFrequency < greenFrequency && redFrequency < blueFrequency && redFrequency < redThreshold)
This if statement checks three conditions:
- redFrequency is less than greenFrequency
- redFrequency is less than blueFrequency
- redFrequency is less than the defined threshold
Since a lower frequency means higher light intensity for the sensor, this condition confirms that red is the dominant and most intense colour detected.
- digitalWrite(buzzerPin, HIGH);
If all conditions are met, this line sends a HIGH signal to the buzzer pin (turning it on) to trigger the alarm.
- else { digitalWrite(buzzerPin, LOW); }
If the conditions aren’t met, the buzzer is turned off by sending a LOW signal.
// Short delay to stabilize readings
delay(100);
}
- delay(100); This pauses the program for 100 milliseconds (0.1 seconds) before the loop starts again. This short delay helps stabilize sensor readings and prevents the buzzer from toggling too quickly.
How It Works Together
The TCS3200 sensor continuously monitors ambient light and converts the detected colour intensity into a frequency signal. The Arduino processes this data in real time. When a strong red signal is identified—based on the calibrated threshold—the system immediately activates the buzzer. This responsive mechanism can be adapted for various applications, from safety alerts to automated monitoring systems.
OBSERVING FUNCTIONALITY
- Real-Time Sensor Data: When the system is running, you can open the Serial Monitor in the Arduino IDE to see continuous readings of the red, green, and blue frequency values. This live data stream lets you observe how the TCS3200 sensor responds to different lighting conditions and colour intensities.
- Audible Buzzer Alert: As soon as the sensor detects that the red colour is dominant (i.e., the red frequency is lower than the green and blue values and below the set threshold), the Arduino triggers the buzzer. This results in an audible alarm, which is a clear indication that the specified colour has been identified.
- Colour Detection Verification: By monitoring the printed sensor values, you can verify the sensor’s switching between different colour filters. Even though you may not see a visual display of the colours, the variation in frequency readings for red, green, and blue confirms that the sensor is correctly cycling through its detection modes.
- Threshold Calibration Feedback: The observable changes in the sensor values also provide immediate feedback during the calibration process. If the red frequency doesn't fall below the defined threshold when the target colour is present, you can adjust the redThreshold value in the code accordingly. This trial-and-error process is directly supported by the live data display.
COMMON PROBLEMS AND SOLUTIONS
- Alarm Not Activating:
- Cause: The sensor might be misaligned or the colour threshold is not correctly calibrated.
- Solution: Ensure the sensor is unobstructed and adjust the redThreshold value based on your environment.
- Erratic Buzzer Behavior:
- Cause: Unstable sensor readings or electrical noise.
- Solution: Check all wiring connections and consider adding filtering or debounce logic in the code.
- No Sensor Data on Serial Monitor:
- Cause: Incorrect pin assignments or loose connections.
- Solution: Recheck the wiring and verify that the correct pins are used in the code.
Conclusion
The colour-triggered alarm project illustrates a practical application of visual sensing in modern electronics. By integrating the TCS3200 sensor with an Arduino, this system efficiently monitors for a specific colour—red—and responds with an audible alert when detected. Whether for security, quality control, or interactive installations, this project demonstrates the power of real-time sensor integration and responsive design in automated systems.
Comments