Hello, im working a simple project.
to make relay controlled by lm35 temperature.
i make it with
- 3 push buttons as an up down, and start button to start the program
- lm35
- 5VDC relay - i connect it to DC heater (5v)
The sketch is ok, lm35 also good when i tested it with another sketch, as a thermometer only. But in this project the problem is, when i set temperature example 40 Celsius, relay on to make heater keep heating to reach the set level., but the output of lm35 is getting unstable, its changing so many level and then turn back to previous level and continue like that, it makes relay also turning off and on and off and off and so on because relay will turning off if the temperature reached the setting level.
when i disconnect the heater from relay, lm35 read is stable, but when i reconnect, its getting unstable.
i've checked the supply, its also unstable. maybe this caused the lm35 output fluctuate.
the question is why the supply is getting unstable when i connect the heater to relay?
where did i go wrong??
please help.
This is the sketch
#include <LiquidCrystal.h>
int reading = 0;
int sensorPin = A0;
int relay =12;
int buzzer =13;
int celsius = 0;
int suhu = 0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
pinMode(relay,OUTPUT);digitalWrite(12,HIGH);
pinMode(buzzer,OUTPUT);digitalWrite(13,HIGH);
pinMode(11, INPUT);digitalWrite(11,HIGH); // pin start
pinMode(9, INPUT);digitalWrite(9,HIGH); // pin up
pinMode(10, INPUT);digitalWrite(10,HIGH); // pin down
lcd.clear();
delay (200);
lcd.setCursor (0,0);
lcd.print(" Alat Terapi ");
lcd.setCursor(0,1);
lcd.print(" Sinusitis ");
delay(2000);
lcd.setCursor(0,0);
lcd.print(" Berbasis ");
lcd.setCursor(0,1);
lcd.print(" Arduino Uno ");
delay(2000);
lcd.setCursor (0,0);
lcd.print(" Oleh ");
lcd.setCursor(0,1);
lcd.print(" Albama ");
delay(2000);
lcd.setCursor(0,0);
lcd.print(" NIM ");
lcd.setCursor(0,1);
lcd.print(" 14.006 ");
delay(2000);
lcd.setCursor (0,0);
lcd.print(" Pembimbing I ");
lcd.setCursor(0,1);
lcd.print(" Syahir,ST.MT ");
delay(2000);
lcd.setCursor(0,0);
lcd.print(" Pembimbing II ");
lcd.setCursor(0,1);
lcd.print(" Muh. Nurman, BE");
delay(2000);
lcd.clear();
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.begin(16, 2);
lcd.print("Setting Suhu");
delay(2000);
// lcd.scrollDisplayLeft();
// wait a bit:
if(digitalRead(9)==LOW||digitalRead(10)==LOW)
{delay(200);
while(1)
{
if(digitalRead(9)==LOW){suhu++;}
if(digitalRead(10)==LOW){suhu--;}
if(digitalRead(11)==LOW){delay(200);break;}
lcd.begin(16, 2);lcd.print("Setting Suhu ");
lcd.setCursor(4, 2);lcd.print(suhu);
delay(200);
}
while(1)
{
program();
}
}
}
void program()
{
reading = analogAvg(sensorPin);
celsius= (5.0*reading)*100/1024;
if (celsius < suhu)
{
digitalWrite(12, LOW);
}
else
{digitalWrite(12,HIGH);
}
lcd.begin(16, 2);lcd.print("Suhu");
lcd.setCursor(12,2);
lcd.print(celsius);
lcd.print("C");
delay(1000);
}
int analogAvg (int sensorPin)
{
unsigned int total=0;
for(int n=0; n<suhu; n++ )
total += analogRead (sensorPin);
return total/suhu;
}