Go Down

Topic: unable to use ds18b20 temperature sensor with GSM shield (Read 934 times) previous topic - next topic


Hi guys... I'm trying every solution but no way....

I have the official Antenova gsm shield and the sensor ds18b20.

If I connect only the GSM shield without the sensor I get -127 from the sensor and the shield is able to do the http post to my server successfully. If the sensor is connected It return the right temperature but the client.connect(server, port) never return. I set the sensor pin to 12 instead of 2 to avoid problems, but seem like they are in conflict. I'm already using the external power supply.

Code: [Select]

// libraries
#include <GSM.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// PIN Number
#define PINNUMBER "1218"

// APN data
#define GPRS_APN       "web.omnitel.it" // replace your GPRS APN
#define GPRS_LOGIN     ""    // replace with your GPRS login
#define GPRS_PASSWORD  "" // replace with your GPRS password

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 12
// 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);

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;

// URL, path & port (for example: arduino.cc)
char server[] = "mancioboxblog.altervista.org";
char path[] = "/add.php";
int port = 80; // port 80 is the default for HTTP

// check the connection status
int con = 0;

// string to save the temp
String data = "";

// temp random
long temp;

void setup() {

  //file version
  Serial.println("Version: 1.6");
  // initialize serial communications and wait for port to open:


  /* only for old USB usually not required
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

  Serial.println("Starting Arduino web client.");
  // connection state
  boolean notConnected = true;

  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
  while (notConnected) {

    Serial.println("I'm trying to connect");
    if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
      notConnected = false;
    } else {
      Serial.println("Not connected");

  Serial.println("I'm connected");


  // this operation is faster than connect to sim card
  // Start up the temperature sensor library
  Serial.println("initialize sensors");

  // wait the the gsm shield is initialized



void loop() {

  // 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.print("Temperature for Device 1 is: ");

  temp = sensors.getTempCByIndex(0);
  Serial.print(temp); // Why "byIndex"?
  // You can have more than one IC on the same bus.
  // 0 refers to the first IC on the wire

  //only for test
  //temp = random(33);
  data = "temp=" + (String)temp;

  Serial.println("temp stored = " + data);

  con = client.connect(server, port);

  // wait connection engaged
  // if you get a connection, report back via serial:
  if (con == 1) {
    // Make a HTTP request:
    client.print("POST ");
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
    client.println("Connection: close");
    client.print("Content-Length: ");

    //what I'm sending
    Serial.print("POST ");
    Serial.println(" HTTP/1.1");
    Serial.print("Host: ");
    Serial.println("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
    Serial.println("Connection: close");
    Serial.print("Content-Length: ");
  // if you didn't get a connection to the server:
  } else if(con == -1){
    Serial.println("connection failed: TIMED_OUT -1");
  } else if(con == -2){
    Serial.println("connection failed: INVALID_SERVER -2");
  } else if(con == -3){
    Serial.println("connection failed: TRUNCATED -3");
  } else if(con == -4){
    Serial.println("connection failed: INVALID_RESPONSE -4");

    client.stop();  // DISCONNECT FROM THE SERVER
    Serial.println("enter in the if and stop the client");
    Serial.println("the client is not connected");
  //keep over 2 second otherwise is not able to close and reopen connection

  Serial.println("code repeat");


I included in the attachment the pictures when I run the sketch with the sensor and without.

Is a problem with the code? maybe stop sensor reading before client connect?


Go Up