Hi, I could do with some assistance with this issue that I'm having because I'm relatively new to coding and am trying to receive data from a DS18B20 temperature sensor and use this data to move a servo the appropriate amount and then receive the next piece of data from the sensor and then the servo move, giving me a live feed gauge of the current temperature.
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 180; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
{
sensors.requestTemperatures(); // Send the command to get temperatures
int tempSens = sensors.getTempCByIndex(0);
for(pos = 0; pos < tempSens; pos += 1); // goes from 0 degrees to Temp value
}
}
void loop()
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
int tempSens = sensors.getTempCByIndex(0);
delay(200);
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
// goes from 0 degrees to Temp value
{ // in steps of 1 degree
myservo.write(sensors.getTempCByIndex(0) + (sensors.getTempCByIndex(0) - tempSens) ); // tell servo to go to the current temperature plus the difference between the current and old temperature
delay(15); // waits 15ms for the servo to reach the position
}
delay(150);
}
This is the code I have so far that I've pieced together from my limited knowledge, but any help would be appreciated,
Hi, I could do with some assistance with this issue that I'm having because I'm relatively new to coding and am trying to receive data from a DS18B20 temperature sensor and use this data to move a servo the appropriate amount and then receive the next piece of data from the sensor and then the servo move, giving me a live feed gauge of the current temperature.
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 180; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
{
sensors.requestTemperatures(); // Send the command to get temperatures
int tempSens = sensors.getTempCByIndex(0);
for(pos = 0; pos < tempSens; pos += 1); // goes from 0 degrees to Temp value
}
}
void loop()
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
int tempSens = sensors.getTempCByIndex(0);
delay(200);
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
// goes from 0 degrees to Temp value
{ // in steps of 1 degree
myservo.write(sensors.getTempCByIndex(0) + (sensors.getTempCByIndex(0) - tempSens) ); // tell servo to go to the current temperature plus the difference between the current and old temperature
delay(15); // waits 15ms for the servo to reach the position
}
delay(150);
}
This is the code I have so far that I've pieced together from my limited knowledge, but any help would be appreciated,
code changed.
It makes servo goto position porportional to temp (0..60 deg C)
#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);
}
I've had each part of the program running independently it's just getting the servo to go to the current value of the temperature sensor that I'm struggling with
When 'reset': Servo runs to 0 deg then swing to approx 75 deg (assuming temp 25 deg C)
It will stay at that position until you heat it (cool it).
Try heating 10 degs. Servo shoud add another 30 degree angle.
To see 'more action' - increase factor to 5 or more.
If your temprange is 20..40, you can (20 deg. span) change factor to 9 and: