Last active
January 18, 2016 00:26
-
-
Save mandyRae/440bcdb96f0790269f7e to your computer and use it in GitHub Desktop.
This is software for an Arduino-controlled oscillating air-conditioning fan. A fan, two potentiometers, and a servo are wired up to the Arduino. The fan is mounted to the servo, and can move in a 90 degree sweep. One pot adjusts the fan's speed, and the other adjusts the oscillation speed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Oscillating Fan with Arduino Uno -- Software | |
| Find build instructions at www.electrothoughts.wordpress.com/2015/05/31/oscillating-fan-with-arduino-part-2/ | |
| Also see "Part 1" of this project for initial ideas at www.electrothoughts.wordpress.com/2015/05/21/oscillating-fan-with-arduino-part-1/ | |
| Amanda on Electrothoughts - 2015 | |
| Reuse this code to your heart's desire! | |
| Components Required: | |
| -5v micro-servo | |
| -computer cooling fan or motor with fan attachment | |
| -2 potentiometers (one adjusts fan speed, and one adjusts oscillation speed) | |
| -transistor (to drive fan) | |
| -4xAA batteries with holder OR 9V battery with clip | |
| The original project was built using pieces from an Erector set toy. This project | |
| could easily be expanded by adding a temperature sensor, wireless control, or an LCD. | |
| */ | |
| #include <Servo.h> | |
| //declare pin variables | |
| const int SERVO = 5; | |
| const int FAN = 6; | |
| const int POT1 = A0; | |
| const int POT2 = A1; | |
| //Declare a Servo object named servo | |
| Servo servo; | |
| //direction variable of the servo, it's either 1 or -1. | |
| //acts as in increment and decrement value to be added to the position variable (pos) | |
| int dir = 1; | |
| void setup(){ | |
| pinMode(FAN, OUTPUT); | |
| //attach the servo pin to the servo object | |
| servo.attach(SERVO); | |
| } | |
| //the main loop iterates very quickly | |
| void loop(){ | |
| //read the first pot, and map it to an output voltage of 0-5v | |
| int fanSpeed = map(analogRead(POT2), 0, 1023, 0, 255); | |
| //the fan is turned on | |
| analogWrite(FAN, fanSpeed); | |
| //pot 2 is read, and mapped to a time from 100 to 5ms | |
| //the rate will be used to set the speed of the servo | |
| int rate = map(analogRead(POT1), 0, 1023, 100, 5); | |
| //the position of the servo is checked | |
| int pos = servo.read(); | |
| //if the pos is at 45 or 135 degrees, then the direction variable flips its sign | |
| //this is the place to change the angle measurement of the fan's sweep | |
| if (pos <= 45 || pos >= 135) { | |
| dir = -dir; | |
| } | |
| //now the servo moves, the dir moves it one degree | |
| servo.write(pos + dir); | |
| //pause the program | |
| delay(rate); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment