I wanted to build a circuit similar to one I made in the past weeks but with a slight modification. I reused the fan but opted for a different type of LEDs Additionally, incorporating a Bluetooth module introduced a new feature to the project.
Software: Tinker CAD, ARDUINO IDE, Arduino Bluetooth Control
Tools:
> Components:
- action components: fan, RGBs Light
- Breadboard
- Jumper wires
- Resistors 220 Ohm
- Arduino
Tinker CAD: to build and simulate the circuit
Arduino IDE: to install the codeblocks on the breadboard
Bluetooth module controller application
jumpers
Arduino UNO
(Brain+Power management)
Breadboard
Resistors (220 ohm)
DC fan (action component)
RGBs (action component)
Wiring explained:
Fan:
- I connected the positive terminal to the Arduino pin. 7
- Then connected the negative terminal to the -ve rail of the breadboard
RGBs:
- each terminal is connected to a resistor and then to the Arduino pins, however, the ground is connected to the -ve rail of the breadboard
- The first terminal of the RGB is connected to a resistor and then to the Arduino pin 2
- The third terminal of the RBG is connected to a resistor and then to the Arduino pin 3
- The third terminal of the RBG is connected to a resistor and then to the Arduino pin 4
Bluetooth module:
- The RX of the blu. module to the TX+1
- The power to the +ve of the rail
- The TX to the RX+0
- The GND to the -ve of the rail
The code
Arduino.ino file
The code explained
The Arduino that controls 3 LEDs (Red, Green, and Blue) and a Fan using serial communication. It waits for incoming data from the serial monitor (or another device) and responds by turning on/off the LEDs and the fan depending on the command it receives.
Variable Declarations:
int LEDR = 2; // Red LED on pin 2
int LEDG = 3; // Green LED on pin 3
int LEDB = 4; // Blue LED on pin 4
int Fan = 7; // Fan on pin 7
char incomingData = '0'; // Variable to store incoming data (initialized to '0')
Assigning digital pins on the Arduino to control the Red, Green, and Blue LEDs, and a Fan.
incomingData holds the value received from serial input.
Setup Function:
void setup() {
Serial.begin(9600); // Starts serial communication at 9600 baud rate
pinMode(LEDR, OUTPUT); // Set LEDR pin as output
pinMode(LEDG, OUTPUT); // Set LEDG pin as output
pinMode(LEDB, OUTPUT); // Set LEDB pin as output
pinMode(Fan, OUTPUT); // Set Fan pin as output
}
This runs once when the Arduino powers on or resets.
Serial.begin(9600) initializes communication, allowing you to send commands via serial monitor.
pinMode(..., OUTPUT) configures the connected devices to receive signals from the Arduino.
Loop Function:
void loop() {
while (Serial.available() == 0); // Wait until data is received
incomingData = Serial.read(); // Read the incoming data from the serial buffer
The while (Serial.available() == 0); keeps looping until data is sent from the serial monitor (or external device). It blocks everything else until something arrives.
incomingData = Serial.read(); reads the first available character from the serial input.
Control Logic:
if (incomingData == '1') {
digitalWrite(LEDR, HIGH); // Turn Red LED ON
digitalWrite(LEDG, LOW); // Turn Green LED OFF
digitalWrite(LEDB, LOW); // Turn Blue LED OFF
digitalWrite(Fan, LOW); // Turn Fan OFF
}
If i send '1' via serial, the Red LED turns ON, Green & Blue turn OFF, and the Fan is OFF.
cpp
CopyEdit
else if (incomingData == '2') {
digitalWrite(LEDR, LOW);
digitalWrite(LEDG, HIGH); // Green LED ON
digitalWrite(LEDB, LOW);
digitalWrite(Fan, LOW);
}
Sending '2' turns the Green LED ON, others OFF, and Fan OFF.
else if (incomingData == '3') {
digitalWrite(LEDR, LOW);
digitalWrite(LEDG, LOW);
digitalWrite(LEDB, HIGH); // Blue LED ON
digitalWrite(Fan, LOW);
}
Sending '3' turns the Blue LED ON, others OFF, and Fan OFF.
else if (incomingData == '4') {
digitalWrite(LEDR, HIGH);
digitalWrite(LEDG, HIGH);
digitalWrite(LEDB, HIGH); // All LEDs ON
digitalWrite(Fan, LOW);
}
Sending '4' turns all LEDs ON, and Fan OFF.
else {
digitalWrite(LEDR, LOW);
digitalWrite(LEDG, LOW);
digitalWrite(LEDB, LOW); // All LEDs OFF
digitalWrite(Fan, HIGH); // Fan ON
}
}
If i send anything else, it turns all LEDs OFF and turns the Fan ON.
I replicated the connection of the tinkercad circuit
FAN WIRING
- I connected the positive terminal to the Arduino pin. 7
- Then connected the negative terminal to the -ve rail of the breadboard
RGB WIRING
- each terminal is connected to a resistor and then to the Arduino pins, however, the ground is connected to the -ve rail of the breadboard
- The first terminal of the RGB is connected to a resistor and then to the Arduino pin 2
- The third terminal of the RBG is connected to a resistor and then to the Arduino pin 3
- The third terminal of the RBG is connected to a resistor and then to the Arduino pin 4
BUETOOTH MODULE WIRING
The RX of the Blu. module to the TX+
The power to the +ve of the rail
The TX to the RX+0
The GND to the -ve of the rail
Application: Arduino Bluetooth Control
Here I connected the Bluetooth module to send and receive data through the mobile app. So, I connected the mobile app to the Bluetooth module and controlled the Arduino with it
Power
The 5V of the Arduino is connected to the +ve rail of the breadboard
The Grd of the Arduino is connected to the -ve rail of the beadboard
The process was mainly trial and error. Also, my colleagues supported me in connecting the application through bluetooth/wifi.
When I transfer the wiring from Tinkercad to the physical components, it rarely works smoothly on the first attempt. I usually go through several rounds of trial and error, making adjustments until everything functions correctly.
Also, when uploading the code to the Arduino, I’ve learned that it’s better to disconnect the Tx and Rx wires first to ensure a more stable connection. Once the upload is complete, I reconnect them to their original positions.
I would add a nice-to-have feature in my project where the light is an indicator of the process progress.