Temperature Controlled Servo


hi all,

i new arduino. bought beginner kit arduino dfrobot (sku:dfr0100) , trying code servo rotate based on temperature. servo @ 179 degrees when under 25 celsius , @ 0 degrees when on 25 celsius. code sadly not working. don't have understanding of code, please explain as can!

#include <servo.h>         
servo myservo;               // create servo object control servo

unsigned long teptimer ;   
int threshold = 25; // threshold temperature
int servocold = 0; // angle in servo go to
int servohot = 179; // angle in servo go to
 

void setup(){       
    serial.begin(9600);
    myservo.attach(9);         // attaches servo on pin 9 servo object       
}

void loop(){
    int val;               
    double data;         
    val=analogread(0); 
    data = (double) val * (5/10.24);  // convert voltage temperture
     
    if(data < threshold){        // if temperture on 27 degree, buzzer alarm. 
         myservo.write(servocold);
                }   
if else (data > threshold); // if temperature above threshold, activate sequence
  {
      myservo.write(servohot);
    }
       if(millis() - teptimer > 500){     // output temperture value per 500ms
             teptimer = millis();
             serial.print("temperature: ");     
             serial.print(data);             
             serial.println("c");             
       }
}


i apologize in advance if it's complete mess need help!

your code not compile because of line:
code: [select]
if else (data > threshold); // if temperature above threshold, activate sequence
read if else syntax here.

in future, if code won't compile , post error message.  please read "how use forum" stickies see how format , post code , errors.



Arduino Forum > Using Arduino > Project Guidance > Temperature Controlled Servo


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts