Pages: [1]   Go Down
Author Topic: help for temp sensor and servo  (Read 594 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25770
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

* test_17_07.pde (3.48 KB - downloaded 3 times.)
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25770
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

with ping i mean the ping sensor.

en how do i look always at the temp?

thx.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

nobody?
Logged

Offline Offline
God Member
*****
Karma: 2
Posts: 711
a, b = b, a+b
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thx got it working.
Logged

Pages: [1]   Go Up
Jump to: