hi,
i creating project fan start @ temperature. if temperature below min temp want green led light , fan not run, between min temp , max temp want orange led light , fan start , reach 50% fan speed. when max temp reached want red led light , 100% fan speed reached.
when download code fan starts automatically though temp below temp min , red led lights up, not green led supposed alight.
i new arduino , know basics think simple causing happen have tried resolve many times still cant work out.
here code, if can see why not work great help.
thank you
i creating project fan start @ temperature. if temperature below min temp want green led light , fan not run, between min temp , max temp want orange led light , fan start , reach 50% fan speed. when max temp reached want red led light , 100% fan speed reached.
when download code fan starts automatically though temp below temp min , red led lights up, not green led supposed alight.
i new arduino , know basics think simple causing happen have tried resolve many times still cant work out.
here code, if can see why not work great help.
thank you
code: [select]
//code scratch
int pos = 0;
int sensorpin = a1; //temp sensor
int reading = 0; //read temp
int fan = 11; //fan
int ledgreen = 8; //green led
int ledorange = 7; //orange led
int ledred = 5; //red led
int tempmin = 10; //temp fan starts
int tempmax = 35; //temp fan reaches max speed
int fanspeed;
float voltage = 0; //convert temp
float temperaturec = 0; //convert temp
float temperaturef = 0; //convert temp
void setup() {
pinmode(sensorpin, input);
pinmode(fan, output);
pinmode(ledgreen, output);
pinmode(ledorange, output);
pinmode(ledred, output);
serial.begin(9600);
}
void loop() {
if(temperaturec<tempmin){ //if temp below temp min turn off green led
digitalwrite(fan, low);
digitalwrite(ledgreen, high);
digitalwrite(ledorange, low);
digitalwrite(ledred, low);
fanspeed = 0;}
if((temperaturec>=tempmin) && (temperaturec<tempmax)){ //if temp same or above temp min , under temp max turn on fan(50% speed), servo , orange led
digitalwrite(fan, high);
digitalwrite(ledgreen, low);
digitalwrite(ledorange, high);
digitalwrite(ledred, low);
fanspeed = 50;}
if(temperaturec>tempmax){ //if temp more temp max turn on fan(100% speed), servo , red led
digitalwrite(fan,high);
digitalwrite(ledgreen, low);
digitalwrite(ledorange, low);
digitalwrite(ledred, high);
fanspeed = 100;}
}
int readtemp(){ //to convert temperature's
reading = analogread(sensorpin);
voltage = ( reading * 5.0) / 1024.0;
temperaturec = (voltage - 0.5) * 100;
temperaturef = temperaturec * 9/5 + 32;
serial.print(temperaturec); //print text of temp , fan speed on serial monitor
delay(1000);
serial.println(fanspeed);
delay(1000);
}
hi,
i creating project fan start @ temperature. if temperature below min temp want green led light , fan not run, between min temp , max temp want orange led light , fan start , reach 50% fan speed. when max temp reached want red led light , 100% fan speed reached.
when download code fan starts automatically though temp below temp min , red led lights up, not green led supposed alight.
i new arduino , know basics think simple causing happen have tried resolve many times still cant work out.
here code , fritzing image, if can see why not work great help.
thank youcode: [select]
//code scratch
int pos = 0;
int sensorpin = a1; //temp sensor
int reading = 0; //read temp
int fan = 11; //fan
int ledgreen = 8; //green led
int ledorange = 7; //orange led
int ledred = 5; //red led
int tempmin = 10; //temp fan starts
int tempmax = 35; //temp fan reaches max speed
int fanspeed;
float voltage = 0; //convert temp
float temperaturec = 0; //convert temp
float temperaturef = 0; //convert temp
void setup() {
pinmode(sensorpin, input);
pinmode(fan, output);
pinmode(ledgreen, output);
pinmode(ledorange, output);
pinmode(ledred, output);
serial.begin(9600);
}
void loop() {
if(temperaturec<tempmin){ //if temp below temp min turn off green led
digitalwrite(fan, low);
digitalwrite(ledgreen, high);
digitalwrite(ledorange, low);
digitalwrite(ledred, low);
fanspeed = 0;}
if((temperaturec>=tempmin) && (temperaturec<tempmax)){ //if temp same or above temp min , under temp max turn on fan(50% speed), servo , orange led
digitalwrite(fan, high);
digitalwrite(ledgreen, low);
digitalwrite(ledorange, high);
digitalwrite(ledred, low);
fanspeed = 50;}
if(temperaturec>tempmax){ //if temp more temp max turn on fan(100% speed), servo , red led
digitalwrite(fan,high);
digitalwrite(ledgreen, low);
digitalwrite(ledorange, low);
digitalwrite(ledred, high);
fanspeed = 100;}
}
int readtemp(){ //to convert temperature's
reading = analogread(sensorpin);
voltage = ( reading * 5.0) / 1024.0;
temperaturec = (voltage - 0.5) * 100;
temperaturef = temperaturec * 9/5 + 32;
serial.print(temperaturec); //print text of temp , fan speed on serial monitor
delay(1000);
serial.println(fanspeed);
delay(1000);
}
Arduino Forum > Using Arduino > Project Guidance > fan controlled by temperature
arduino
Comments
Post a Comment