Personal Desk Fan
Your very own desk fan. Component List:- 1 x Arduino Uno R3
- 1 x SG90 Servo Motor
- 1 x Hobby Motor
- 1 x IR Remote and Receiver
- 1 x Fan Blade
- 1 x 1N4001 Diode
- 1 x 2N2222 Transistor
- 1 x Ceramic Capacitor (104)
- Jumper wires (male-to-male)
- Jumper wires (male-to-female)
1. Arduino Uno R3
- Power (5V):
- Connect the 5V pin on the Arduino to the positive rail of the breadboard.
- Ground (GND):
- Connect a GND pin on the Arduino to the ground rail of the breadboard.
2. SG90 Servo Motor
- Signal Pin (Yellow):
- Connect to Digital Pin 9 on the Arduino.
- Power Pin (Red):
- Connect to the 5V rail on the breadboard.
- Ground Pin (Brown):
- Connect to the GND rail on the breadboard.
3. Hobby Motor (DC Motor)
- Motor + Terminal:
- Connect to the Collector (C) pin of the 2N2222 transistor and + terminal of the Diode
- Motor - Terminal:
- Connect to the GND terminal of the diode
- The diode is used for flyback protection to prevent voltage spikes when the motor turns off.
- Place the capacitor on the motor leads itself + and -
- This stabilizes the whole circuit, the circuit will not work properly if this is not added for the motor.
4. 2N2222 Transistor
- Collector (C):
- Connect to the - terminal of the hobby motor and Diode
- Emitter (E):
- Connect to the GND rail on the breadboard
- Base (B):
- Connect to Digital Pin 6 on the Arduino through a 1kΩ resistor (if not mentioned but recommended for base current limiting).
5. IR Receiver
- VCC Pin:
- Connect to the 5V rail on the breadboard.
- GND Pin:
- Connect to the GND rail on the breadboard.
- Signal Pin:
- Connect to Digital Pin 8 on the Arduino.
6. Fan Blade
- Attach the fan blade to the shaft of the hobby motor. Ensure it is securely fastened.
7. Jumper Wires
- Male-to-Male Wires:
- Use these to make connections between the breadboard and Arduino or other components.
- Can be a 4xAA battery pack or even the HW-131 set to 5v with a power adapter
- VCC Pin:
- Connect to the 5V rail on the breadboard.
- GND Pin:
- Connect to the GND rail on the breadboard.
- Important: Connect the ground of the external power source to the ground of the Arduino (Common Ground)
- Connect the Servo motor and Hobby Motor to the ground and VCC of this external power supply. Your Arduino is unable to power these parts through the USB only.
- VCC Pin:
#include <IRremote.hpp>
#define RECV_PIN 8
#include <Servo.h>
Servo myServo; // Create a servo object
int pos = 90; // Variable to store the servo position
int increment = 4; // Variable to control the direction of movement
unsigned long previousMillis = 0; // Stores the last time the servo was updated
const long interval = 1; // Interval at which to update the servo position (in milliseconds)
int motor=6;
int powerFlag=0;
int speed=0;
int swing=0;
int remoteSpeed=5;
void setup()
{myServo.attach(9); // Attach the servo to pin 9
Serial.begin(115200); // Establish serial communication
IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK); // Start the receiver
pinMode(motor, OUTPUT); //Set pin 10 as an Output
}
void loop() {
if (IrReceiver.decode()) {
//Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); // Print "old" raw data
IrReceiver.printIRResultShort(&Serial); // Print complete received data in one line
IrReceiver.printIRSendUsage(&Serial); // Print the statement required to send this data
IrReceiver.resume(); // Enable receiving of the next value
Serial.println(IrReceiver.decodedIRData.decodedRawData);
switch(IrReceiver.decodedIRData.decodedRawData)
{case 0xE31CFF00: //Ok Button
if(powerFlag==1)
powerFlag=0;
else
powerFlag=1;
break;
case 0xBA45FF00: //1 Button
remoteSpeed=1;
break;
case 0xB946FF00: //2 Button
remoteSpeed=2;
break;
case 0xB847FF00: //3 Button
remoteSpeed=3;
break;
case 0xBB44FF00: //4 Button
remoteSpeed=4;
break;
case 0xBF40FF00: //5 Button
remoteSpeed=5;
break;
case 0xBC43FF00: //6 Button
remoteSpeed=6;
break;
case 0xF807FF00: //7 Button
remoteSpeed=7;
break;
case 0xEA15FF00: //8 Button
remoteSpeed=8;
break;
case 0xF609FF00: //9 Button
remoteSpeed=9;
break;
case 0xE916FF00: //* Button
if(swing==1)
swing=0;
else
swing=1;
break;
case 0xE718FF00:
if (increment>0 && increment<=11)
increment +=2;
else if(increment<0 && increment>=-11)
increment -=2;
break;
case 0xAD52FF00:
if (increment>2)
increment -=2;
else if(increment<0 && increment<=-11)
increment +=2;
break;
}
}
speed = map(remoteSpeed,1,9,50,150); //range goes up to 255, but your power source should be able to handle it. 4 x AA can do 250, 1A External Power supply can do 150.
if(powerFlag==1)
analogWrite(motor,speed);
else
analogWrite(motor,0);
Serial.println(speed);
unsigned long currentMillis = millis();
// Check if it's time to update the servo position
if(powerFlag==1 && swing==1)
{if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// Update the servo position
pos += increment;
myServo.write(pos);
// Reverse the direction at the ends of the sweep
if (pos <= 0 || pos >= 180) {
increment = -increment;
}}
}
delay(100);
}
Looking to build this project? Check out our custom, Bahraini Assembled, starter kit here!
[bitware_arabic_portfolio_content]
Project Details | |
| Level: | Novice (2/5) |
| Category: | Monitoring System |
| Platform: | Arduino |
| Creator: | BitWare Store |