Hello,
I have a temperature sensor and two LEDs connected to the arduino uno.
Ardunio reads the sensor via analog pin 3, and depends on the temperature reading, blinks on the LEDs. But it does not do the job even though everything is connected right.
What it does instead: (after pressing reset button) blinks the LED on pin 13 once then the LED on pin 12 once and prints the temperature values to the serial monitor without led action at around 25 degrees of temperature. When I heat the temperature sensor over 30 degrees, it starts to get the LED on pin 12 blinked as long as the temperature stays over 30. And the temperature falls down below 30, it only print the temperature to the serial monitor without LEDs
Here is the code
int LED1=13;
int LED2=12;
int analogPin = 3; //readings of tempereature sensor
float val = 0; //value of temperature sensore is stored here
void setup(){
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
Serial.begin(9600);
function1(); //for the temperatures lower than 30 and higher than 25
function2(); //for the temperatures higher than 30
Serial.begin(9600);
}
void loop(){
val = analogRead(analogPin)*0.48828125;
Serial.println(val);
if(30>val>=25){
function1();}
if(val>30){
function2();}
delay(2000);
}
void function1(){ //function which should work only in 25-30 degrees
digitalWrite(LED1,HIGH);
delay(1000);
digitalWrite(LED1,LOW);
delay(1000);
}
void function2(){ //funtion which should work only after 30 degrees
digitalWrite(LED2,HIGH);
delay(1000);
digitalWrite(LED2,LOW);
delay(1000);
What am I doing wrong here?
cheers