/* Sweep by BARRAGAN This example code is in the public domain. modified 8 Nov 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/Sweep */ #include int sensorPin=A0; int temp=0; int randomTemp=0; int sensorValue=0; Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards int pos = 0; // variable to store the servo position int tempMap=0; void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop() { // read the temperature // randomTemp=random(0,45); // Serial.println(randomTemp); readSensor(); // map temp to srvo angle tempMap=map(temp,10,35,0,180); // write temperature to servo pos=tempMap; myservo.write(pos); delay(1000); // if (randomTemp < 18){ // pos=180; // myservo.write(pos); // tell servo to go to position in variable 'pos' // delay(15); // waits 15ms for the servo to reach the position // waits 15ms for the servo to reach the position // } else { // pos=90; // myservo.write(pos); // tell servo to go to position in variable 'pos' // delay(15); // } } void readSensor(){ //this is a way of cleaning the code, simplifying it sensorValue=analogRead(sensorPin); temp = (5.0 * sensorValue * 100.0) / 1024; }