Unwanted serial output

Hi all,
I have created a system but when viewing the serial out put I get "No more addresses" at the end of the serial output. I have had a look through my code but I cannot find the statement being put at the end only at front of the program where if the sensor is not found then this statement is displayed.

I will attach my program, just to clarify The highlighted text is what I do not want in the serial output (see capture.png).

Sorry if I've worded it awkwardly!

Here is my code as requested :slight_smile:

#include <U8glib.h>
#include <OneWire.h> //temperature lib
OneWire  ds(10); // declare on pin 10 with a 4.7 ohm resistor
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);	// I2C / TWI

void setup() 
{
  //start serial connection
  Serial.begin(9600);
  //configure pin2 as an input and enable the internal pull-up resistor
  pinMode(A5, INPUT); //Water Sensor
  pinMode(13, OUTPUT);

  pinMode(9, OUTPUT); //Buzzer
  beep(50);
  delay(1000);
  
    if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }

}

void loop() 
{
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  //read the sensor value into a variable
  int waterVal = analogRead(A5); //read the waterlevel and put it to an int
  Serial.print("The water value is "); //print out the value of the sensor
  Serial.print(waterVal);
  delay(1000);

  if (waterVal > 570) {  //if the water value is above 700 the led comes on and buzzer beeps
    highwater();
  }
  else
  {
    digitalWrite(13, LOW);
  }
  
  if ( !ds.search(addr)) 
  {
    Serial.println(F("No more addresses."));
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }
  
  if (OneWire::crc8(addr, 7) != addr[7]) 
  {
    Serial.println("CRC is not valid!");
    return;
  }
  Serial.println();

  // the first ROM byte indicates which chip
  switch (addr[0]) 
  {
    case 0x10:
      Serial.println(F("  Chip = DS18S20"));  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println(F("  Chip = DS18B20"));
      type_s = 0;
      break;
    case 0x22:
      Serial.println(F("  Chip = DS1822"));
      type_s = 0;
      break;
    default:
      Serial.println(F("Device is not a DS18x20 family device."));
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE);         // Read Scratchpad


  Serial.print(F("  Data = "));
  Serial.print(present, HEX);
  Serial.print(F(" "));
  for ( i = 0; i < 9; i++) 
  {                        // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(F(" "));
  }
  
  /*
  Serial.print(" CRC=");  
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();
  */

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  //  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print(F("  Temperature = "));
  Serial.print(celsius);
  Serial.print(F(" Celsius, "));
  //  Serial.print(fahrenheit);
  // Serial.println(" Fahrenheit");
}

void beep(unsigned char delayms) 
{
 tone(9,254,2000);   
}
void highwater()
{
  digitalWrite(13, HIGH);
  beep(40000);
}

Here is the output:
The water value is 0
Chip = DS18B20
Data = 1 50 1 4B 46 7F FF 10 10 49 Temperature = 21.00 Celsius, The water value is 0No more addresses.

The water value is 0
Chip = DS18B20
Data = 1 50 1 4B 46 7F FF 10 10 49 Temperature = 21.00 Celsius, The water value is 0No more addresses.

Dementia_patient_Sensor.ino (3.88 KB)

Please edit your original post and paste both your code and output as text, rather than downloads. It makes it much easier for people to help you.

When you paste the text, make sure you put it inside ... tags so it looks like this:

code here...

Change line 44 of your code to println and it will hep you understand what is happening

  Serial.println(waterVal);

Delta_G:
There it is. IT's the very next thing you print after "The water values is " and waterVal. That's not a println so it should be on the same line with it. That's just exactly where it is showing up in th eserial monitor. I don't see the confusion.

 int waterVal = analogRead(A5); //read the waterlevel and put it to an int

Serial.print("The water value is "); //print out the value of the sensor
  Serial.print(waterVal);
  delay(1000);

if (waterVal > 570) {  //if the water value is above 700 the led comes on and buzzer beeps
    highwater();
  }
  else
  {
    digitalWrite(13, LOW);
  }
 
  if ( !ds.search(addr))
  {
    Serial.println(F("No more addresses."));
    Serial.println();
    ds.reset_search();

Ok fair enough I was being bone idle and didnt notice the next Println"No more ardresses" thanks for pointing it out :slight_smile: