Go Down

Topic: help for temp sensor and servo (Read 665 times) previous topic - next topic

xseto

hi i made a program that the servo sweeps and when it dedect a high temp the servo stops but it wont stop.
im new at programming.
this is a piece of the code.
// IF ELSE
 if (Temp3  < 30) {   // If the temp is too low it sweeps

   digitalWrite(ledPin, LOW);    // sets the LED off
   servo_sweep();
   
   
 }else{      // If the temp is too high the led turns on
 
digitalWrite(ledPin, HIGH);   // sets the LED on
   
 } //END OF IF STATEMENT

 delay(100);
}

void servo_sweep(){
 for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
 {                                  // in steps of 1 degree
   myservo.write(pos);              // tell servo to go to position in variable 'pos'
   delay(15);                       // waits 15ms for the servo to reach the position
 }
 for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
 {                                
   myservo.write(pos);              // tell servo to go to position in variable 'pos'
   delay(15);                       // waits 15ms for the servo to reach the position
 }
}



thx.

AWOL

Your servo sweep takes nearly five and  half seconds - how rapidly does the temperature change?
Please post ALL your code,and use the # icon on the editor's toolbar.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

xseto

the temp changes when the sweep is over but i dont know why its doing that.


dont mind the ping in the code thats for later.

thx.

AWOL

Quote
dont mind the ping in the code thats for later

There isn't a ping in the code, so how could I mind it.

Quote
the temp changes when the sweep is over but i dont know why its doing that

Because that's the only time you're looking at it?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

xseto

with ping i mean the ping sensor.

en how do i look always at the temp?

thx.


fkeel

try to loose your delay statements.

when you use "delay" you basically put your arduino to sleep. It simply does nothing (as in, it will not read temperature etc.)

take a look at the "blink without delay" tutorial (its also an example sketch in your arduino ide)

p

(only looked at your code snippet. have not seen the full code)

xseto


Go Up