I have a DS18B20 temperature sensor and using Dallas Temperature Control Library to read the temperature. The sensor has 1-wire interface and Dallas library uses OneWire library. I also need to use Servo library in my project. But according to my testing, the Dallas Library or OneWire Library is interfering with the servos. The servos randomly move when temperature library is used.

Can you post your code AND schematic how all is connected?
robtillaart:
Can you post your code AND schematic how all is connected?
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Servo.h>
Servo servo[8];
// Data wire is plugged into port 4 on the Arduino
#define ONE_WIRE_BUS 4
// 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);
void setup(void)
{
// start serial port
Serial.begin(19200);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
servo[0].attach(3);
servo[1].attach(5);
servo[2].attach(6);
servo[3].attach(9);
servo[4].attach(10);
servo[5].attach(11);
servo[6].attach(7);
servo[7].attach(8);
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
if (Serial.available() > 0)
{
int val = Serial.parseInt();
for (int i = 0; i < 8; i++)
{
servo[i].write(val);
}
}
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.print("Temperature >>> ");
Serial.println(sensors.getTempCByIndex(0));
}
I attached the schematic in the original post.
I actually connected only two servos at pin 3 and 7. I tried connecting red wire of the sensor to 5V but the same problem occurred.
Edit: This post seems the same problem as mine. OneWire + Servo not possible? - Networking, Protocols, and Devices - Arduino Forum
what value are you sending to the Arduino?
The servo should only move when there is data send to the Arduino.
Can you post some sample input/output?
Can you test this variation?
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Servo.h>
Servo servo[8];
// Data wire is plugged into port 4 on the Arduino
#define ONE_WIRE_BUS 4
// 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);
void setup(void)
{
// Start serial port
Serial.begin(19200);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
servo[0].attach(3);
servo[1].attach(5);
servo[2].attach(6);
servo[3].attach(9);
servo[4].attach(10);
servo[5].attach(11);
servo[6].attach(7);
servo[7].attach(8);
}
void loop(void)
{
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.print("Temperature >>> ");
Serial.println(sensors.getTempCByIndex(0));
delay(1000);
}
If the servos do move now there is definitely a problem.
Are the servo's controlled directly or by means of a transistor and their own power supply?