1

i tried to connect my arduino uno and ethernet shield with Mysql and everything works fine. Then I tried to connect the RF transmitter and receiver. I use a similar code, but i have problem with connection with database. For the project i use:2xArduino Uno,Rf transmitter and receiver ,DHT11 and BMP080,and Ethernet shield. This is my Code:

transmitter:

#include <VirtualWire.h>
  #include "LowPower.h"
  #include "DHT.h"
  #include "Adafruit_BMP085.h"
  #include "Wire.h"

  #define DHTPIN 8     // what pin we're connected to
  #define DHTTYPE DHT11   // DHT 11 
  DHT dht(DHTPIN, DHTTYPE);
  Adafruit_BMP085 bmp;
  int ledPin = 13;
  char Msg[30];// The string that we are going to send trought rf transmitter 
  void setup() 
  {
    Serial.begin(115200);
    dht.begin();  // initialing the DHT sensor
    bmp.begin();  
    pinMode(ledPin,OUTPUT);
    // VirtualWire setup
    vw_setup(2000); // Bits per sec
    vw_set_tx_pin(12);// Set the Tx pin. Default is 12
  }  
  void loop() 
  {
     Serial.print("Pressure = ");
     Serial.println(bmp.readPressure());
     Serial.print("Temperature = ");
     Serial.println(bmp.readTemperature()); 
     Serial.print("Humidity = "); 
     Serial.println(dht.readHumidity());

    // Read and store Sensor Data
    int humidity = dht.readHumidity();
    int temp = bmp.readTemperature();
    unsigned long pressure = bmp.readPressure()/100;
     Serial.print("Pressure = "); 
     Serial.println(pressure );

    sprintf(Msg, "%d,%d,%d", humidity,temp ,pressure);
   // Turn on a light to show transmitting
    digitalWrite(ledPin, HIGH); 
   //LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF);  
    delay(100); 
    vw_send((uint8_t *)Msg, strlen(Msg));
    vw_wait_tx(); // Wait until the whole message is gone
   // Turn off a light after transmission
    digitalWrite(ledPin, LOW); 
    // put 5 mins sleep mode
    // As lowpower library support maximam 8s ,we use for loop to take longer (5mins) sleep
    // 5x60=300
    //300/4=75
    for(int i=0;i<75;i++)
    {
    LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);    // Instead of delay(4000); 
   //delay(4000);
    }
  }

reciever:

#include <SPI.h>
#include <Ethernet.h>
#include "Wire.h"
#include <VirtualWire.h> // use Virtual library for decode signal from Rx module

 EthernetClient client;
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  char server[] = "192.168.0.101"; 

  int humidity=0;
  int temp=0;
  unsigned long pressure=0;
  char MsgReceived[21]; 


  void setup() 
  {
    Ethernet.begin(mac);
    Serial.begin(115200);

    // VirtualWire 
    // Bits per sec
    vw_setup(2000);
    // set pin for connect receiver module 
    vw_set_rx_pin(5);  
    // Start the receiver PLL running
    vw_rx_start();      

  }

  void loop()
  {    
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    //Taking the data from the control base
    if (vw_get_message(buf, &buflen)) 
    {

      delay(100);
      int i;
      // Message with a good checksum received, dump it. 
      for (i = 0; i < buflen; i++)
      {            
        // Fill Msg Char array with corresponding 
        // chars from buffer.   
        MsgReceived[i] = char(buf[i]);
        Serial.print(MsgReceived[i]);
      }
  connection();

    sscanf(MsgReceived, "%d,%d,%d",&humidity, &temp, &pressure); // Converts a string to an array


    memset( MsgReceived, 0, sizeof(MsgReceived));// This line is for reset the StringReceived

    Serial.print("Temperature = ");
    Serial.print(temp);
    Serial.println(" *C");

    Serial.print("Pressure = ");
    Serial.print(pressure);
    Serial.println(" hPa");

    Serial.print("humidity = ");
    Serial.print(humidity);
    Serial.println(" %");

    delay(10000);  
    }
}

  void connection()
  {
    if(client.connect(server, 80)) {

      client.print( "GET /diplomna/Arduino/add_data.php?");
      client.print("temperature=");
      client.print( temp );
      client.print("&&");
      client.print("humidity=");
      client.print( humidity );
      client.print("&&");
      client.print("pressure=");
      client.println( pressure );
      client.println( "HTTP/1.1");
      client.println( "Connection: close" );
      client.stop();
      Serial.println("CONNECTED");
    }
    else {
      // you didn’t get a connection to the server:
      Serial.println("-> connection failed");
    }

  }

Output receiver:

70,23,100-> connection failed 
Temperature = 23 *C 
Pressure = 1001 hPa    
Pahumidity = 70 %
  • without : #include <VirtualWire.h> and rf function I connect with the database and make a record :( – Supreme Jun 2 '15 at 13:50
  • Do you really want a 10 second delay in there? – Chris Stratton Jun 2 '15 at 16:46
  • it is not necessary, but without it does not work too :) – Supreme Jun 2 '15 at 17:30
  • I found where is the problem. It is function of virtualwire.h - rx_setup. It use a timer and there is conflict with any of the libraries. Can anybody tell me how то change the timer, that is used by the function. – Supreme Jun 9 '15 at 14:28

Your Answer

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

Browse other questions tagged or ask your own question.