Hola a todos.Ante todo saludar a los foreros y gracias anticipadas.Estoy intentando controlar el tiro de una estufa con arduino.Se trataría de abrir o cerrar la puerta del tiro mediante un servo controlado por una sonda de temperatura.La sonda es una dallas ds1820b y la placa arduino uno.La función parece sencilla pero mis conocimientos de programación están próximos a cero.Intento que el servo se mantenga a 0 grados(trampilla abierta) mientras la temperatura no llega a 70ºC y a esa temperatura gire a 90 grados(para cerrar la trampilla),en cuanto baje la temperatura a 50ºC se vuelva girar a 0ºC(para abrir) y asi sucesivamente.He buscado códigos pero no encuentro nada que me permita hacer algo aproximado.Saludos y gracias.
El código que tengo es este,pero no hace lo que necesito y no se exactamente lo que tengo que incluir para que funcione.
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos; // variable to store the servo position
const byte factor = 3; // keep temp below 180/3 = 60 degr. C or change factor to 2 or 1
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
sensors.begin();
sensors.requestTemperatures(); // Send the command to get temperatures
int tempSens = sensors.getTempCByIndex(0);
for(pos = 0; pos < tempSens* factor; pos ++) // guess you want servo to move from 0 to 'temp' at startup mulitply factor for bette view in this example
{
myservo.write(pos);
delay(20);
}
}
void loop()
{
sensors.requestTemperatures(); // Send the command to get temperatures
int tempSens = sensors.getTempCByIndex(0);
delay(200);
Serial.print(tempSens);
myservo.write(tempSens*factor ); // tell servo to go to the current temperature plus the difference between the current and old temperature
delay(150);
}
Hola @canabucho te acercaste bastante pero de tanto leer y copiar no dejaste que tu cerebro pensara y te atoraste.
Tienes dos elementos, el sensor y el servo.
Si el sensor lee bien la temperatura entonces el 50% esta resuelto.
Ahora veamos el servo.
El servo una una instrucción para moverse, y en tu caso es myservo.write(angulo);
Entonces si tu le dices al servo, quiero que vayas a 90 grados solo escribes
myservo.write(90);
y si quieres que vaya a 0
myservo.write(0);
esperas a que llegue y listo.
Ahora combinemos.
Tu sensor debe detectar temperatura >= 90.0
Pongo el punto decimal porque usas valores del tipo float
if (tempSens >= 90.0) {
myservo.write(90); // giro el servo a 90 grados y lo espero.
delay(algo); // determina ese algo como 1500 mseg
}
y por el otro lado
if (tempSens <= 50.0) {
myservo.write(0); // giro el servo a 0 grados y lo espero.
delay(algo); // determina ese algo como 1500 mseg
}
Entonces aca tienes todo
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos; // variable to store the servo position
const byte factor = 3; // keep temp below 180/3 = 60 degr. C or change factor to 2 or 1
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
sensors.begin();
sensors.requestTemperatures(); // Send the command to get temperatures
int tempSens = sensors.getTempCByIndex(0);
for(pos = 0; pos < tempSens* factor; pos ++) {// guess you want servo to move from 0 to 'temp' at startup mulitply factor for bette view in this example
myservo.write(pos);
delay(20);
}
}
void loop() {
sensors.requestTemperatures(); // Send the command to get temperatures
int tempSens = sensors.getTempCByIndex(0);
Serial.print(tempSens);
if (tempSens >= 90.0) {
myservo.write(90);
delay(1500); // ajusta este valor para que se alcance el ángulo
}
if (tempSens <= 50.0)
myservo.write(0);
delay(1500); // idem
}
Aclaro: no me gustan los delay pero aca es lo mas facil de usar.
Fenómeno!! Yo sabía que no debía ser demasiado complicado pero mis ínfimos conocimientos me limitan mucho.Gracias mil a ti y a todos los foreros por ayudar al que no sabe.Saludosss.