Hi, I am building a greenhouse window opener for my small greenhouse. I have got the project working but the servo operates too fast. I have tried to combine a increment angle code but can't get the temp code and the able code to work together. can anyone help. Thank you.
This is the code I am using:
#include <Servo.h> //servo library
float tempC; //temperature sensor LM35
int tempPin = 0; //analog data output
int ledPin1 = 9; //servo on indicator LED
int ledPin2 = 8; //servo off indicator LED
Servo servo1; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup() {
Serial.begin (9600);
servo1.attach(3); // attaches the servo on arduino digital pin 3 to the servo object
pinMode (ledPin1, OUTPUT); //pin output mode for servo on
pinMode (ledPin2, OUTPUT); //pin output mode for servo off
}
void loop() {
tempC = analogRead (tempPin); //read the output of temperature sensor LM35
tempC = (5.0tempC100.0)/1024.0; //calculation to convert voltage to temperature reading
//tempC = (tempC/79.0)*5.0;
Serial.print ("Temperature "); //print the word temperature on the serial monitor
Serial.println (tempC); //print the temperature reading on the serial monitor
delay (3000); //delay 30 secondsbetween readings
if (tempC >25) //if temperature greater than
{
pos = 0; pos = 20; pos = 40; //position of the servo motor arm
delay (500);
digitalWrite (ledPin1, HIGH); //turn on the green LED to indicate the servo motor is in use
servo1.write (pos); //move the servo arm to the position indicated above
}
else //else statement
{
pos = 0; //position of the servo motor arm
digitalWrite (ledPin1, LOW); //turn off the green LED
servo1.write (pos); //move the servo arm to the position indicated above
//delay (100);
//digitalWrite (tranSwitch, LOW); //turn off the switch to break the circuit
}
if (tempC <25) //if temperature less than
{
digitalWrite (ledPin2, HIGH); //turn on white LED to indicate to indicate servo motor is not in use
}
else
digitalWrite (ledPin2, LOW); //turn off the white LED
}