Why are there two Serial.begin() function calls? What does that signify? Here is the minimal code i am working on:

void setup() {
      Serial.println("Pressure Sensor Test"); Serial.println("");    

Here is the full Code:

#include <SimpleDHT.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>

int pinDHT11 = 2;
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

void displaySensorDetails(void)
  sensor_t sensor;
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" hPa");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" hPa");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" hPa");  
  Serial.println("----------SDNx real time scientific data---------------");

void setup() {
  Serial.println("Pressure Sensor Test"); Serial.println("");
    /* There was a problem detecting the BMP085 ... check your connections */
    Serial.print("  Ooops, no BMP085 detected ... Check your circuit some errors are there!");

  /* Display some basic information on this sensor */


void loop() {

  Serial.println("Sample DHT11...");

  byte temperature = 0;
  byte humidity = 0;
  byte data[40] = {0};
  if (simple_dht11_read(pinDHT11, &temperature, &humidity, data)) {
    Serial.print("Read DHT11 failed");

  Serial.print("Sample RAW Bits: ");

  Serial.print("SDNx says you are genius and every thing is OK: ");
  Serial.print((int)temperature); Serial.print(" *C, ");
  Serial.print((int)humidity); Serial.println(" %");

  // DHT11 sampling rate is 1HZ.

  sensors_event_t event;

  if (event.pressure)

    Serial.print("Pressure:    ");
    Serial.println(" hPa");

    float temperature;
    Serial.print("Temperature: ");
    Serial.println(" C");

    float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
    Serial.print("Altitude:    "); 
    Serial.println(" m");
    Serial.println("Sensor error");
  • 2
    It signifies that the author of this code has made a mistake of either implementation or understanding. – Chris Stratton Jan 17 '18 at 4:52
  • The first begin() is probably being ignored by the Arduino. – Fusseldieb Jan 18 '18 at 9:43
  • I thought it would be enacted upon and then overwritten by the second. I know that's the same result, but there might be some subtle difference. – Code Gorilla Jan 18 '18 at 14:22

It looks like a mistake, as Chris says. I can't tell you what will happen but my guess is it will work at 9600.

I would recommend that you delete one of the lines to avoid further confusion.

| improve this answer | |
  • when i asked the author of this code he said that they were for maximum and minimum value of baud rate. Is there anything like that? PS. Also the arduino was connected to BMP085, DHT11 and a HC06 – rimalonfire Jan 17 '18 at 13:32
  • 1
    I think he misunderstands the calls he has made, they aren't. Serial only refers to the serial communications over pin 0 and 1 on an Arduino. You can have other objects that refer to other serial ports, but in this case its the serial monitor. – Code Gorilla Jan 17 '18 at 13:56
  • Also the output was taken from a Bluetooth terminal in an Android app – rimalonfire Jan 17 '18 at 14:11
  • What do you mean by "You can have other objects that refer to other serial ports, but in this case its the serial monitor" – rimalonfire Jan 18 '18 at 13:38
  • On a Mega you have Serial1 and 2(?). You can create SoftwareSerial objects which create a serial connection out of any pins. You could even define you own and bitbang a serial port. Heck you could even have an object that create a virtual serial port over Ethernet, Wifi, Bluetooth, etc, which is what I think you are using. – Code Gorilla Jan 18 '18 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.