Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help: Temperature controller with ATTINY85 and LM35

Status
Not open for further replies.

ozgur84

Member
Hello everybody,

I designed a circuit which reads a LM35 temperature sensor, blinks 2 LED and turns on and off a Fan over a MOSFET. However, it does not function as I want it to do. Here is the schematic and the code (LED colors are different in the original circuit but it does not matter)

circuit.png


#define analogPin 3 // Data cable connected to the analog pin
#define YelPin 1 // yellow LED pin for Temp>35
#define RedPin 0 //red LED pin for Temp>39
#define FanPin 2 //Fan connected to the MOSFET will be high Temp>35
int val=0; // variable to store the value of temperature reading

void setup(){
pinMode(YelPin, OUTPUT);
pinMode(RedPin, OUTPUT);
pinMode(FanPin, OUTPUT);
function0(); // for the temperatures out of the interested range
function1(); //for the temperatures lower than 39 and higher than 36
function2(); //for the temperatures higher than 39

}

void loop(){
val = analogRead(analogPin)*0.48828125; //conversation of the analog reading to the centigrade
if(val<35 && val>60){
function0();}
if(val>=35 && val<39){
function1();}
if(val>39 && val<60){
function2();
delay(5000);
}}

void function0(){ //function which should work only when the temperature is out of interested range
digitalWrite(YelPin, LOW);
digitalWrite(RedPin, LOW);
digitalWrite(FanPin,LOW);
delay (2000);
}

void function1(){ //function which should work only in 35-39 degrees
digitalWrite(YelPin, HIGH);
digitalWrite(RedPin,LOW);
digitalWrite(FanPin,HIGH);
delay (2000);
}

void function2(){ //funtion which should work only after 39 degrees
digitalWrite(RedPin,HIGH);
digitalWrite(YelPin, LOW);
digitalWrite(FanPin,HIGH);
delay(2000);
}


The circuit was programmed with an Arduino Uno as ISP and the clock frequency is 8MHz
When I power up the circuit, It waits for a while, then turns the Yellow LED on as well as the fan for half a second and turns off. If I heat the sensor further, it turns the red LED on as well as the fan and stays on half a second as the previous case and waits and does the same....

What I want to have
Read the temperature,
if temperature <36 and > 60 do nothing
if temperature >36 and < 39 turn the yellow LED as well as the fan on
if temperature > 39 and <60 turn the red LED as well as the fan on

What am I doing wrong here?

Regards,
Oz
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top