Monday, December 2, 2013

We have slightly modified the design of our fan so that the LCD displays the current and desired temperature as well as the RPM of the fan.  The following is a basic bread board setup and code for our fan.

Schematic for fan controller

*/
#include <OneWire.h>
#include <DallasTemperature.h>
#include <PID_v1.h>
#include <LiquidCrystal.h>

//Definitions
#define FAN 9           // Output pin for fan
#define ONE_WIRE_BUS 8  // Temperature Input is on Pin 2
#define click 3        //Rotary Encoder Click
#define encoder0PinA  2 //Rotary Encoder Pin A
#define encoder0PinB  4 //Rotary Encoder Pin B
#define CRITICAL 50.00  //Critical temperature to ignore PID and turn on fans

volatile unsigned int encoder0Pos = 0;  //Encoder value for ISR

LiquidCrystal lcd(12, 11, 13, 5,6,7);  //set up LCD

//Setup Temperature Sensor
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

//Setup PID
double Setpoint, Input, Output;                                          //I/O for PID
double aggKp=40, aggKi=2, aggKd=10;                                     //original: aggKp=4, aggKi=0.2, aggKd=1, Aggressive Turning,50,20,20
double consKp=20, consKi=1, consKd=5;                                  //original consKp=1, consKi=0.05, consKd=0.25, Conservative Turning,20,10,10
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, REVERSE);  //Initialize PID

//interface
int timeCounter;
void setup()

  // start serial port for temperature readings
  Serial.begin(9600);
  Serial.println("Start");

  //Temperature Setup
  sensors.begin();                    //Start Library
  sensors.requestTemperatures();      // Send the command to get temperatures
  Input = sensors.getTempCByIndex(0); //Set Input to Current Temperature
  Setpoint = 28;                      //Inintialize desired Temperature in Deg C
  encoder0Pos=28;

  //PID Setup
  myPID.SetMode(AUTOMATIC);
  //TCCR2B = TCCR2B & 0b11111000 | 0x01; //adjust the PWM Frequency, note: this changes timing like delay()

  //Setup Pins
  pinMode(FAN, OUTPUT);                   // Output for fan speed, 0 to 255
  pinMode(click, INPUT);                  // Click button is an input
  pinMode(encoder0PinA, INPUT);
  digitalWrite(encoder0PinA, HIGH);       // Turn on pullup resistor
  pinMode(encoder0PinB, INPUT);
  digitalWrite(encoder0PinB, HIGH);       // Turn on pullup resistor

  //Set up Interupts
  attachInterrupt(1, clicked, RISING);    // Click button on interrupt 1 - pin 3
  attachInterrupt(0, doEncoder, CHANGE);  // Encoder pin on interrupt 0 - pin 2

  //interface

  timeCounter=0;

  //Setup LCD 16x2 and display startup message
  lcd.begin(16, 2);
  lcd.print(" Smart Fan");
  lcd.setCursor(0,1);
  lcd.print(" Starting Up");
  delay(1000);
  lcd.clear();
}
void loop()
{
   timeCounter++;

   //Get temperature and give it to the PID input
   sensors.requestTemperatures();
   Input=sensors.getTempCByIndex(0);

  //print out info to LCD
  lcd.setCursor(1,0);
  lcd.print("Temp:");
  lcd.print((int)Input);
  lcd.setCursor(9,0);
  lcd.print("RPM:");
  lcd.print((int)Output*4.7059);
  lcd.setCursor(1,1);
  lcd.print("Set:");
  lcd.print((int)Setpoint);

  //Compute PID value
  double gap = abs(Setpoint-Input); //distance away from setpoint
  if(gap<1)
  { 
    //Close to Setpoint, be conservative
    myPID.SetTunings(consKp, consKi, consKd);
  }
  else
  {
     //Far from Setpoint, be aggresive
     myPID.SetTunings(aggKp, aggKi, aggKd);
  }
  myPID.Compute();
  Serial.print(timeCounter);
  Serial.print(" ");
  Serial.print(Input);
  Serial.print(" ");
  Serial.println(Output);
  analogWrite(FAN,255);
  //Write PID output to fan if not critical
  if (Input<CRITICAL)
    analogWrite(FAN,Output);
  else
    analogWrite(FAN,255);
}

void doEncoder()
{
  //pinA and pinB are both high or both low, spinning forward, otherwise it's spinning backwards
  if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB))
  {
    encoder0Pos++;
  }
  else
  {
    encoder0Pos--;
  }
  Serial.println (encoder0Pos, DEC);  //Print out encoder value to Serial
  Setpoint=encoder0Pos;
}
void clicked()
{
  //For interface
  lcd.clear();
  lcd.print("clicked!");
  delay(1000);
}

Monday, November 25, 2013

Progress

The solid models have all been, for the most part, finalized.  We just need to create etching on the parts as identifiers.  The parts that were needed to make out fan work were received and testing was conducted on them.  The parts that were ordered were a piezo element, a stronger DC motor and female jumper wires to enable us to to parts away from the breadboard.  All of the parts will be held together with some sort of glue either hot glue or super glue but mostly likely a combination of both.  The DC motor will be controlled using the piezo knock sensor by using the PWM library to change the speed of the fan based upon how many knocks are sensed.  LEDs will be indication of the speed of the fan.  Also and LCD will read out the ambient temperature of the area around the fan.  The motor will be attached to the fan head with a wooden dowel or perhaps another 3D printed part pending the final volume of the parts (need to find out the support material volume). The model itself will be fairly light due to its primarily plastic and acrylic composition.

Also, there were two meeting during the past week.  One was during the lab time and the solid models were worked on during that time period.  Then another meeting of about 2 hours was arranged on friday to work on the code.  And various other hours were spent individually working on both parts of the project, the code and the solid models, outside of the meeting times.

Friday, November 15, 2013

The following is what we have so far for our projects code.  We attempted to post the code through github but were having issues:

//LCD display
#include  <LiquidCrystal.h>         // Include the library to use a LCD display
#define          sensor           0        // Define the A0 pin as “sensor”
int  Vin;           //  Variable to read the value from the Arduino’s pin
float  Temperature; //  Variable that receives the converted voltage value to temperature
float     TF; // Variable to receive the converted value from  ºC to ºF
LiquidCrystal  lcd    (12, 11, 5, 4, 3, 2);
/* The function above declares which Arduino’s pins will be used for controlling the LCD */
  //knock Sensor
int ledPin = 13;
int knockSensor = 0;              
byte val = 0;
int statePin = LOW;
int THRESHOLD = 100;
void  setup()
{
  lcd.begin(16, 2);                            //  It tells the Arduino that the display is a 16x2 type
  lcd.print("Temperature: ");           //  Send the text to the screen of the display.
 pinMode(ledPin, OUTPUT);
 Serial.begin(9600);
}
void  loop()
{{
  Vin = analogRead (sensor);  /*   Tells the Arduino to read the pin and stores the value in “Vin” */
  Temperature=(500*Vin)/1023;  /* Converts the voltage value into temperature and stores it into the “Temperature”  variable  (in  ºC)*/
TF = ((9*Temperature)/5)+32; // Converts  ºC to ºF
  lcd.setCursor(0, 1);           // Moves  the cursor of the display to the next line
  lcd.print(TF);    // Exhibits the value of the temperature on the display
  lcd.print(" F");         // Writes “F” to indicate that it is in Fahrenheit scale.
   delay(1000);  //  Waits for a second to read the pin again
}
  val = analogRead(knockSensor);    
  if (val >= THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    Serial.println("Knock!");
  }
  delay(100);  // we have to make a delay to avoid overloading the serial port
}

Below is an attached image of our tenative assembly, some dimensions will be updated peninding the dimensions of our DC motor as well as the LCD screen, LEDs, etc.  Our project will be made entirely of 3D printed material and acrylic that has been lasor cut.  All the parts were made on solidworks.

For our Arduino project we have decided to create a three speed fan powered by a DC motor.  The current design is such that a Piezo element will turn the fan on and then any consecutive knocks will cycle through the fans 3 speeds and then finally turn the fan off.  To distinguish which setting the fan is on  a single led light will turn on and an additional light will turn on for each consecutive speed.  Additionally, a heat sensor will be incorporated such that the temperature is displayed on an LCD.  A SolidWorks assembly of the various components we intend to have made by the 3d printer has been created.  Our two group meetings this week occurred on Tuesday 11-12-13 and Friday 11-15-13, during which both members attended.  The goal we set to accomplish was to update our blog with all of the appropriate information.