hi i using lm35 when it detect above 16 degree the fan will turn but it never turn on. icouldn't find any error for the code but when i use the signal pin from the fan connect to the 3.3v the fan turn
Compare to your code from December's posts, where you defined RELAY2 as a pin number. In today's you defined fan as a pin number, but then used RELAY1.
Fix that, get it to compile. then we can talk about why the fan isn't behaving as you had hoped.
It looks like you have a cut and paste error then.
Maybe try posting the code with code tags, and some idea of what the serial monitor output looks like.
Ok let's assume that you have a version that compiles, but that you're not sharing it with us. Put these serial prints in as shown below, and see if the logic is actually taking you to the right branch of the if. You could also replace the relay fan etc setup with an led and see if it lights.
You might also let us see the circuit diagram?
if (celsius>16)
{
digitalWrite (fan,HIGH);
Serial.println("in the >16 leg"); //<<<<<<<<<<<<<<<<<
}
else
{
digitalWrite (fan,LOW);
Serial.println("in else leg"); //<<<<<<<<<<<<<<<<<
}
This code compiles and runs and the logic is good. I commented out the fan stuff and just used Serial.print to see where the logic goes.
My actual LM35's temp is 25C here now so I ran the sketch twice, one looking for >16 which took me to the "if" and once looking for >30 which took me to the "else".
So the logic is good: must be your circuit which is wrong. Let's see it.
//define fan 9
float reading=A0;
int tempPin = 0;
void setup()
{
//pinMode(fan,OUTPUT);
Serial.begin(9600);
}
void loop()
{
reading = analogRead(tempPin);
int celsius = reading* 0.48828125;
Serial.print("TEMPRATURE = ");
Serial.print(celsius);
Serial.print("*C");
Serial.println();
if (celsius>30)
{
//digitalWrite (fan,HIGH);
Serial.println("in the if");
}
else
{
//digitalWrite (fan,LOW);
Serial.println("in the else");
}
delay(1000);
delay(1000);
delay(1000);
delay(1000);
delay(1000);
delay(1000);
}
yeah my serial monitor is working sorry i corrected my programming. is jus the usb cannot turn on when i connect the positive pin to pin 9 and negative pin to ground, when i test it on the pc fan it works . i not sure how to solve the as digital i/o pin from 0 to 13 does on 5v. i not sure how to solve the usb fan which can work on a 3.3v pin but not on a 5v pin
Can you please post a copy of your sketch, using code tags?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?
PLEASE read the link, then post using code tags, and PLEASE a copy of your circuit and PLEASE a picture of your project.
How are you powering your fan and what sort/model/make is it.