I am running the code in Proteus simulator since i havent bought the actual components to make it.
The temperature measurement part is working well.
The idea is that i want to control the servo based on temperature. For example, if temperature is below some set value, such as 30 in this case, i want the servo to rotate 10 degrees in one direction and to check if temperature is still below said 30 degrees Celsius, if it is below i want to increment said angle for another 10 degrees and this goes on for as long as the temperature is above 30 degrees Celsius.
If the temperature drops below said 30 degrees celsius, i want the servo to rotate in 10 degree increments in the opposite direction.
I am sorry for writing like this. This is my first project and i am at my wits end.
Do you mean something like:
"every time there is transition from 30 degrees C to *30.5 degrees C the servo should move 10 degrees (positive angle) and every time there is transition from 30 degrees C to *29.5 degrees C the servo should move 10 degrees (negative angle)"
*some Hysteresis included
No, i want to make it to check in every cycle what the temperature is, and if it is above 30 degrees, i want to increment the position of the servo by 10 degrees in one direction.
If temperature is below said 30 degrees, i want the position to get incremented in the negative direction.
The temperature is measured and compared to a value, and then the servos position gets incremented in either the positive or negative direction.
You appear to have a loop iteration of 1 second.
If the temperature is higher than 30 degrees C you want the servo to rotate in a positive direction at the rate of 1 revolution in 36 seconds.
If the temperature is lower than 30 degrees C you want the servo to rotate in a negative direction t the rate of 1 revolution in 36 seconds.
At exactly 30 degrees C it stops ?
The temperature sensor is "lm35". The arduino board is "Arduino UNO R3", the servo is "motor-pwmservo". I also dont know how can i give you the schematic. I tried uploading the screenshot but it got stuck on "processing".
Well, the system doesnt have to be defined in a clear cut way, the project is supposed to control heating in a solar collector, the servo i supposed to pull the curtain over the collector in case the temperature exceeds some maximum value, in the manual for the solar collector it says that the temperature shouldnt exceed 170 degrees celsius, but that doesnt matter, its just a value for the code.
Also, since it is a solar heating, the "exactly 30 degree point" doesnt matter since it will go above it and then the servo will kick in.
Also, i plan to make said code check once every 10 minutes. But i put a delay of 1 second so i can check quickly if the code is working the right way or not.
Also, i guess i can just put the "<=" to avoid said "exactly a value between two signs" problem.
Well, i actually dont know what that is. I saw a tutorial and it recommended the "motor-pwmservo" so i just picked it. I dont know what a "continuous servo" is. I only recently started learning.
If it is a regular servo that can be positioned by a servo signal, what is keeping it from hitting the end stops and stalling. Stalling the servo can kill it.
I wired up a real regular SG90 servo and real LM35 temperature sensor to my real Uno and using the modified version of your code tried it out. It works fine so I wonder if it is Proteus or the simulated servo. At any rate, this code works in the real world with real parts.
There are two main variants of servos. They look identical, but one isn't really a servo - you can't control it's position, only speed and direction. That isn't what you want, but it's what you have in your simulation.
Though if I were actually going to use the servo for anything but an unloaded demonstration, I would use an external power supply capable of over an Amp (per small servo) for it.