Relay / Arduino UNO / DallasTemperature

Hallo fellas.

I have an issue with my Arduino system DallasTemperature and relay.

My boss has been declared me on a project to automatize an arduino SIM900 on a nursery, for the reason of automatic it all, but that’s other story…

My primary problem is when I try to connect an Temperature Sensor the Monitor Serial sends me the next characters “€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€vv” doesn’t stop it.

I turn torward to you, because I don’t have many experence in Arduino… But whetever, this is my code:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 9
#define TEMPERATURE_PRECISION 9

// 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);

int numberOfDevices; // Number of temperature devices found

DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");
  pinMode(9, OUTPUT);
  // Start up the library
  sensors.begin();
  
  // Grab a count of devices on the wire
  numberOfDevices = sensors.getDeviceCount();
  
  // locate devices on the bus
  Serial.print("Locating devices...");
  
  Serial.print("Found ");
  Serial.print(numberOfDevices, DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  
  // Loop through each device, print out address
  for(int i=0;i<numberOfDevices; i++)
  {
    // Search the wire for address
    if(sensors.getAddress(tempDeviceAddress, i))
	{
		Serial.print("Found device ");
		Serial.print(i, DEC);
		Serial.print(" with address: ");
		printAddress(tempDeviceAddress);
		Serial.println();
		
		Serial.print("Setting resolution to ");
		Serial.println(TEMPERATURE_PRECISION, DEC);
		
		// set the resolution to TEMPERATURE_PRECISION bit (Each Dallas/Maxim device is capable of several different resolutions)
		sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);
		
		 Serial.print("Resolution actually set to: ");
		Serial.print(sensors.getResolution(tempDeviceAddress), DEC); 
		Serial.println();
	}else{
		Serial.print("Found ghost device at ");
		Serial.print(i, DEC);
		Serial.print(" but could not detect address. Check power and cabling");
	}
  }

}

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  // method 1 - slower
  //Serial.print("Temp C: ");
  //Serial.print(sensors.getTempC(deviceAddress));
  //Serial.print(" Temp F: ");
  //Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit

  // method 2 - faster
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print("Temp C: ");
  Serial.print(tempC);
  Serial.print(" Temp F: ");
  Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
}

void loop(void)
{ 
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  
  
  // Loop through each device, print out temperature data
  for(int i=0;i<numberOfDevices; i++)
  {
    // Search the wire for address
    if(sensors.getAddress(tempDeviceAddress, i))
	{
		// Output the device ID
		Serial.print("Temperature for device: ");
		Serial.println(i,DEC);
		
		// It responds almost immediately. Let's print out the data
		printTemperature(tempDeviceAddress); // Use a simple function to print out the data
	} 
	//else ghost device! Check your power requirements and cabling
	
  }
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}

in the next URL I’ll annex my diagram with Arduino, relay and temperature cauge

http://uploadpie.com/TPTER

Thank you so much for enter to this post.

Greetings, and I hope you can help me!

That looks like mismatched baud rate- do you have your arduino and serial monitor set to the same speed? From your code it needs to be 9600.

First:

change this: #define ONE_WIRE_BUS 9

to this: #define ONE_WIRE_BUS 2

Attach the wire from DS18B20 to pin 2 And try it.

Yes, yoyr script says pin 2 while the #define says that the Ds is on pin 9

The DS18B20 does not work without a 4.6 kOhm pull up resistor, that is a resistor of this value plugged between 5V and the pin where the data wire of the DS is connecte to.

By the way, you can read multiple DS probes on one pin providied that you have figured out the identity of each DS18B20.
here is a sketch with 10 (ten !) DS18B20s that works on a Nano with Serial monitor.
Success!

/* YourDuino Multiple DS18B20 Temperature Sensors on 1 wire
Connections:
DS18B20 Pinout (Left to Right, pins down, flat side toward you)

  • Left = Ground
  • Center = Signal (Pin 2): (with 3.3K to 4.7K resistor to +5 or 3.3 )
  • Right = +5 or +3.3 V

Questions: terry@yourduino.com
V1.01 01/17/2013 …based on examples from Rik Kretzinger

/-----( Import needed libraries )-----/
// Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>

//Get DallasTemperature Library here: http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>

/-----( Declare Constants and Pin Numbers )-----/
#define ONE_WIRE_BUS_PIN 2

/-----( Declare objects )-----/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

/-----( Declare Variables )-----/
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress Probe01 = { 0x28, 0xFF, 0xB0, 0x39, 0x92, 0x15, 0x03, 0x4A };
DeviceAddress Probe02 = { 0x28, 0xFF, 0x78, 0x1F, 0x92, 0x15, 0x03, 0x2F };
DeviceAddress Probe03 = { 0x28, 0xFF, 0x44, 0x32, 0x92, 0x15, 0x03, 0x67 };
DeviceAddress Probe04 = { 0x28, 0xFF, 0xE4, 0x27, 0x90, 0x15, 0x01, 0x1E };
DeviceAddress Probe05 = { 0x28, 0xFF, 0x11, 0x38, 0x92, 0x15, 0x03, 0x3B };
DeviceAddress Probe06 = { 0x28, 0xFF, 0x59, 0x2F, 0x92, 0x15, 0x04, 0xD1 };
DeviceAddress Probe07 = { 0x28, 0xFF, 0x63, 0x2E, 0x92, 0x15, 0x04, 0x67 };
DeviceAddress Probe08 = { 0x28, 0xFF, 0x33, 0x25, 0x90, 0x15, 0x01, 0x16 };
DeviceAddress Probe09 = { 0x28, 0xFF, 0x1B, 0x2E, 0x92, 0x15, 0x04, 0x34 };
DeviceAddress Probe10 = { 0x28, 0xFF, 0x37, 0x30, 0x92, 0x15, 0x03, 0x43 };

void setup() /****** SETUP: RUNS ONCE ******/
{
// pinmode for check led
pinMode (13, OUTPUT);

// start serial port to show results
Serial.begin(9600);
Serial.print("Initializing Temperature Control Library Version ");
Serial.println(DALLASTEMPLIBVERSION);

// Initialize the Temperature measurement library
sensors.begin();

// set the resolution to 10 bit (Can be 9 to 12 bits … lower is faster)
sensors.setResolution(Probe01, 10);
sensors.setResolution(Probe02, 10);
sensors.setResolution(Probe03, 10);
sensors.setResolution(Probe04, 10);
sensors.setResolution(Probe05, 10);
sensors.setResolution(Probe06, 10);
sensors.setResolution(Probe07, 10);
sensors.setResolution(Probe08, 10);
sensors.setResolution(Probe09, 10);
sensors.setResolution(Probe010, 10);

}//–(end setup )—

void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
delay(1000);
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
// wait for a second

Serial.println();
Serial.print("Number of Devices found on bus = ");
Serial.println(sensors.getDeviceCount());
Serial.print("Getting temperatures… ");
Serial.println();

// Command all devices on bus to read temperature
sensors.requestTemperatures();

Serial.print("Probe 01 temperature is: ");
printTemperature(Probe01);
Serial.println();

Serial.print("Probe 02 temperature is: ");
printTemperature(Probe02);
Serial.println();

Serial.print("Probe 03 temperature is: ");
printTemperature(Probe03);
Serial.println();

Serial.print("Probe 04 temperature is: ");
printTemperature(Probe04);
Serial.println();

Serial.print("Probe 05 temperature is: ");
printTemperature(Probe05);
Serial.println();

Serial.print("Probe 06 temperature is: ");
printTemperature(Probe06);
Serial.println();

Serial.print("Probe 07 temperature is: ");
printTemperature(Probe07);
Serial.println();

Serial.print("Probe 08 temperature is: ");
printTemperature(Probe08);
Serial.println();

Serial.print("Probe 09 temperature is: ");
printTemperature(Probe09);
Serial.println();

Serial.print("Probe 10 temperature is: ");
printTemperature(Probe10);
Serial.println();

delay(2000);
}//–(end main loop )—

/-----( Declare User-written Functions )-----/
void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

if (tempC == -127.00)
{
Serial.print("Error getting temperature ");
}
else
{
Serial.print("C: “);
Serial.print(tempC);
Serial.print(” F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}

}// End printTemperature
//( THE END )**

THE ISSUE IS LIKE THIS:

define ONE_WIRE_BUS 9 ??????? pinMode(9, OUTPUT);

u have connected ur dallas temp sensor to PIN 9 and in the same time u have declared this PIN as OUTPUT ???

u should just change the PIN 9 to INPUT mode and every thing will work normal as:

pinMode(9, INPUT);