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.

No comments:

Post a Comment