Sunday 31 March 2013

FYP 2 Week 10

This week I still test the circuit on breadboard to achieve a much better results. For my project, it has 3 states. The first state is when the fan is not moving if the temperature sensor sense the temperature is below or equal 24°CThe second state is when the temperature is above 24°C, the fan then will move at the normal speed. The third state is when the temperature is above 37°C. If this occurred,  the fan will move at its maximum speed.

Here is the results from the serial monitor that you can see from the Arduino 1.0.3 software:
Fan started with the normal speed when it doesn't reach the certain temperature.

When the temperature sensor detected the temperature has risen to a certain degree, the fan will increase its speed to maximum.

If the temperature dropped from that certain degree, then the fan will return to its normal speed.




Below is videos of the results of this project on breadboard:
This is video for the first state to the second state (fan turn off -> fan turn on at normal speed)


And this is video for the second state to the third state (fan turn on at normal speed -> fan at maximum speed)

Sunday 24 March 2013

FYP 2 Week 9

Alhamdulillah, now I finally found the code that works for my circuit. It works beautifully as I have expected. Here is the code:

#include <LiquidCrystal.h>

int pin = 0;                // analog pin
int tempc = 0,tempf=0;      // temperature variables
int samples[8];             // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature
int i;
int TIP122pin = 9;
int fanspeed = 0;
int fanStemp = 0;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Customize for your connections.

void setup()
{
  Serial.begin(9600);       // start serial communication
  lcd.begin(16,2);          // set up the LCD's number of columns and rows
  pinMode(TIP122pin, OUTPUT); // Set pin for output to control TIP122 Base pin
  analogWrite(TIP122pin, 255); // control the fan speed by changing values from 0 to 255
  delay(200);
}

void loop()
{
  
tempc = 0;

for(i = 0;i<=7;i++){         // gets 8 samples of temperature
  samples[i] = ( 5.0 * analogRead(pin) * 100.0 ) / 1024.0;
  tempc = tempc + samples[i];
  delay(1000);
}


tempc = tempc/8;               // better precision
tempf = (tempc * 9)/ 5 + 32;     // converts to fahrenheit
if(tempc > maxi) {maxi = tempc;} // set max temperature
if(tempc < mini) {mini = tempc;} // set min temperature

 if ( tempc > 24 && tempc < 37 ) {
    fanStemp = tempc + 50;
    fanspeed = fanStemp + 100;
    analogWrite(9,fanspeed);
    Serial.print("Fan started at temp+50+100 speed\n");
    Serial.print(fanspeed,DEC);
    Serial.print("\n");
    delay(100);
  }
    else if ( tempc <= 24 ) {
    fanspeed = 0;
    analogWrite(9,fanspeed);
    Serial.print("Fan off\n");
    delay(100);
   }
   else{
     analogWrite(9,255);
     Serial.print("Fan started at full speed\n");
     delay(100);
   }
   
Serial.print(tempc,DEC); // serial print for debugging all serial.print commands
Serial.print(" Celsius, ");
Serial.print(tempf,DEC);
Serial.print(" fahrenheit -> ");
Serial.print(maxi,DEC);
Serial.print(" Max, ");
Serial.print(mini,DEC);
Serial.println(" Min");

lcd.setCursor(0, 0);  // set the cursor to (0,0)
lcd.print(tempc,DEC);  // print temp in C and F on the first row of the lcd
lcd.print(" C, ");
lcd.print(tempf,DEC);
lcd.print(" F");

lcd.setCursor(0, 1);  // set the cursor to (16,1)
lcd.print(maxi,DEC);   // Print max temp and min temp on the second row of lcd
lcd.print("  Max, ");
lcd.print(mini,DEC);
lcd.println(" Min.");

delay(1000);                   // delay before loop
}

These are the pictures of the constructed circuit on the breadboard:
The circuit before being plugged with power supply.

The circuit with the power supply, you can see the fan is moving and the LCD display is showing the temperature.









Sunday 17 March 2013

FYP 2 Week 8

I still cannot come up with the code that works for my project. I try to combine the circuits and the coding but the results always not as what I expected. Because of this, I done some researching of the limitation of this project.

This project, if modified to be a cooling system for human can only work effectively in a small room. This is because the temperature in one room could change easily and the heat sensor could not pick up the sudden change of temperature thus making the fan speed remain the same. The temperature change and the area of the room is the factors here in making the automatic temperature controlled fan speed working effectively. It is also work best for cooling the electrical equipment or machines since it has a more efficient power consumption compared to air conditioner.

Saturday 9 March 2013

FYP 2 Week 7

I still struggling to find functional code that works for my project. In the meantime, I was studying the PWM function with Arduino again.



Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of "on time" is called the pulse width. To get varying analog values, you change, or modulate, that pulse width. If you repeat this on-off pattern fast enough with an LED for example, the result is as if the signal is a steady voltage between 0 and 5v controlling the brightness of the LED.


In the graphic below, the green lines represent a regular time period. This duration or period is the inverse of the PWM frequency. In other words, with Arduino's PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each. A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.






I also learned how to combine together the code for temperature sensor and the code for PWM. For example:






Code for temperature sensor:






#include <LiquidCrystal.h>

float tempC;

float tempF;

float voltage;

int reading;

int tempPin=0; //analog channel

int interval = 50; //in ms (how often screen reprints

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {

// set up the LCD’s number of rows and columns:

lcd.begin(20,4);

// Print a message to the LCD.

lcd.setCursor(0,1);

lcd.print("Cabinet Temperature:");

}

void loop() {

//TMP36 voltage at the output varies linearly with ambient temperature.

//As a result,it can be used as a thermometer according to the equation:

// ᵒC = (Vout(V) - .5)*100

//To find Vout in V, we use the following equation for a 5V input

// Vout(V) = AnalogReading*(5/1024)

reading = analogRead(tempPin); //read the value from the sensor

voltage = reading*(5.0/1024); //convert reading to voltage (in V), for 5V input

tempC = (voltage-0.5)*100; //convert voltage to temperature

tempF = ((tempC*9/5)+32); //convert C temperature to F

// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 2);// set the cursor to column 0, line 1

lcd.print(tempF); //Print Fahrenheit temperature to LCD

lcd.print((char)223); // degree symbol

lcd.print("F ");

lcd.setCursor(0,3); //print set temp to lcd

lcd.print("Set Temp: 80 ");

lcd.print((char)223);

lcd.print("F");


}






Code for PWM fan:






// Define which pin to be used to communicate with Base pin of TIP120 transistor

int TIP120pin = 3; //for this project, I pick Arduino's PMW pin 3

void setup()

{

pinMode(TIP120pin, OUTPUT); // Set pin for output to control TIP120 Base pin

analogWrite(TIP120pin, 255); // By changing values from 0 to 255 you can control motor speed

}


void loop()

{

}





Code for combined circuit:



#include <LiquidCrystal.h>

float tempC;

float tempF;

float voltage;

int reading;

const int tempPin = 0; //analog channel

const int TIP120pin = 3; //for this project, I pick Arduino's PMW pin 3

const int interval = 50; //in ms (how often screen reprints

const int setPointF = 80;


// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);


void setup() {

// set up the LCD’s number of rows and columns:

lcd.begin(20,4);

// Print a message to the LCD.

lcd.setCursor(0,1);

lcd.print("Cabinet Temperature:");

pinMode(TIP120pin, OUTPUT); // Set pin for output to control TIP120 Base pin

}

void loop() {

//TMP36 voltage at the output varies linearly with ambient temperature.

//As a result,it can be used as a thermometer according to the equation:

// ᵒC = (Vout(V) - .5)*100

//To find Vout in V, we use the following equation for a 5V input

// Vout(V) = AnalogReading*(5/1024)

reading = analogRead(tempPin); //read the value from the sensor

voltage = reading*(5.0/1024); //convert reading to voltage (in V), for 5V input

tempC = (voltage-0.5)*100; //convert voltage to temperature

tempF = ((tempC*9/5)+32); //convert C temperature to F

// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 2);// set the cursor to column 0, line 1

lcd.print(tempF); //Print Fahrenheit temperature to LCD

lcd.print((char)223); // degree symbol

lcd.print("F ");

lcd.setCursor(0,3); //print set temp to lcd

lcd.print("Set Temp: 80 ");

lcd.print((char)223);

lcd.print("F");


// If the temperature is highher than the set point, run the fans.

// Fans reach full speed then temperature is more than 10°F above setpoint.

analogWrite(TIP120pin, constrain( (tempF - setPointF) * 25, 0, 255));

}




With this examples I will try to come up with new code that can work for my project.

Sunday 3 March 2013

FYP 2 Week 6

This week I was attempting to combine the codes of temperature sensor and PWM so that the fan will move according to temperature. Unfortunately, I can't find the code that is functional for my project. Here is the example of the code I was using:


#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int inPin = 0;
int pwmPin = 9;      //digital pin 9
int pwmVal   = 10;

void setup()
{
  lcd.begin(16, 2);
  pinMode(pwmPin, OUTPUT);   // sets the pin as output
  Serial.begin(9600);
}

void loop()
{
  int value = analogRead(inPin);
  lcd.setCursor(0, 1);
  float milivolts = (value/1024.0)*5000;
  float celsius = milivolts/10;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(celsius);
  lcd.print("Celsius");
  lcd.setCursor(0, 1);
  lcd.print((celsius*9)/5 + 32);
  lcd.print("Fahrenheit");
  delay(10000);

  if (pwmVal != 255) {
         analogWrite(pwmPin, pwmVal);
         //pwmVal += 10;
         Serial.print(pwmVal);  // Print red value
         Serial.print("\n");    // Print a tab
  } else {
         Serial.print('at max high');  // Print red value
         Serial.print("\n");    // Print a tab
  }
  delay(1000);
}


When I used this code, only the temperature sensor part work, the fan doesn't move. I still need to understand how to code in Arduino better to make sure my project functions as I desired.