Hello. I`m trying to make my project with Aurdino. I want to make my servos work at +30° and turn off at +20°. For now i have no idea how to make it real. Could someone help me? I have termperature sensor LM35, resistor 4.7k.
What do you currently have hooked up?
What do you know how to hook up?
What code have you written?
Is this school work?
Also, do you want the servo movement to be proportional to the temperature or are you turning something on and off.
Perhaps you can say more about what it is you are building
Yes I need if t° is <30° servo motor is OFF if 30°>turn ON. Servo movement is not important for now, I want to make it just turn ON and OFF. Code, there is no such, because for now I have no any idea how to make it work. The biggest problem is with connecting pins on wish board.
Do you have the LM35 working? There are a number of LM35 tutorials you can follow to help you get this going. A good starting point would be to display the temperature on the serial monitor.
When that is working, you can add code to detect if the temperature is at the limits that you want to turn on or off.
Perhaps call a function like this at the appropriate temperatures:
void servoControl(boolean on)
{
if(on)
Serial.println("move servo to on position");
else
Serial.println("move servo to off position");
}
You can replace the serial code with servo code when you have the temperature sensing working
When properly connected, the thermistor voltage can be read using analogRead on the appropriate pin. The value returned will be in the range from 1 to 1023.
You will need to figure out what value corresponds to the 20 degree temperature, and what value corresponds to the 30 degree temperature.
Hint: Read the datasheet for the LM35.
Then, you can make the servo do something when the sensor value is between those two limits.
The servo is designed to be given values to rotate to. It sits at that position until given another move value.
Unless it's a continuous rotation servo which really isn't a servo.
OK. Enough help until you explain more.
Found code for thermist, it`s work very well. Show t° on serial monitor.
int pin = 0; // analog pin
int tempc = 0,tempf=0; // temperature variables
int samples[8]; // variables to make a better precision
int maxi = -100,mini = 100; // to start max/min temperature
int i;
void setup()
{
Serial.begin(9600); // start serial communication
}
void loop()
{
for(i = 0;i<=7;i++){ // gets 8 samples of temperature
samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
tempc = tempc + samples[i];
delay(1000);
}
tempc = tempc/8.0; // better precision
tempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit
if(tempc > maxi) {maxi = tempc;} // set max temperature
if(tempc < mini) {mini = tempc;} // set min temperature
Serial.print(tempc,DEC);
Serial.print(" Celsius, ");
Serial.print(tempf,DEC);
Serial.print(" fahrenheit -> ");
Serial.print(maxi,DEC);
Serial.print(" Max, ");
Serial.print(mini,DEC);
Serial.println(" Min");
tempc = 0;
delay(1000); // delay before loop
}
What I need to change on it, how to modify it to my servo, its attached to pin 9, turn ON if t° is >30° else it
s OFF?
What I need to change on it, how to modify to my servo which is attached to pin 9, turn ON if t° is >30°?
Well, first, when posting code, you have to use the Code (#) button on the posting editor.
Then you need to "attach" a servo (see the Servo library reference), and then you need to add a conditional statment to test your calculated temperature and do a "write" operation to the servo.
I suggest getting the conditional statement working before trying to attach the servo.
You can drop the servoControl function I posted in reply #4 into the bottom of your sketch and add a statement in loop that compares the tempc (or tempf) to your thresholds and calls the servoControl function with true (on) or false (off) as appropriate.
When you have confirmed that code is working you can replace the print statements with servo commands.
Big thx for help, special thx to you Mem made it, and it works
if(tempc>20){for(pos = 0; pos < 180; pos += 5)myservo.write(pos); delay(15);}
else {for(pos=180; pos>=1; pos-=5)myservo.write(pos); delay(15);}