2 sensors with 433mhz

hello everyone, i really need anyone’s help with this. First let me just say i have very very little knowledge in programming. I’ve been spending days trying to figure this out. I’m trying to send temperature and ph reading using 443Mhz tx and rx.

For temperature im using DS180sd
For Ph im using SKU:SEN0169(https://www.dfrobot.com/wiki/index.php/Analog_pH_Meter_Pro_SKU:SEN0169)
2 arduino boards for tx and rx

I’m following this program http://www.riyas.org/2014/06/cheap-remote-wireless-temperature-sensor-with-arduino-uno-433mhz-rfmodule.html

I dont need it to display into the lcd just the serial monitor is enough, this is what i got when i try editing it. I thought i could just take the ph program from the official website and combine them together but it still only senses and transmit the temperature and not the ph. I’ve tried a bunch of thing and to no avail. Could anyone please help. thank you ! Receiver_working and Transmitter_working is the 1 with only the temperature sensor. Receiverver2 and transmitterver2 is the 1 that i tried to add with ph sensor

I posted this in the project guidance section, i think thats the wrong section so i posted here instead. Not sure how delete the previous thread tho.

Receiver_Working.ino (1.53 KB)

Receiverver2.ino (1.75 KB)

Transmitter_Working_1.ino (1.99 KB)

Transmitterver2.ino (3.88 KB)

Would you care to point out, in Transmitter2.ino, where you send anything but the temperature? Just reading the data from the pH sensor is NOT enough.

PaulS:
Would you care to point out, in Transmitter2.ino, where you send anything but the temperature? Just reading the data from the pH sensor is NOT enough.

hi PaulS.

I did some editing for the transmitter. Able to sense the temp and PH but still unable to send PH data to receiver.

Transmitter Code

//simple wireless temperature tranmitter
// DS18S20 sensor is connected to pin 8
// Rf modules tranmit (data) pin is connected to pin 7 on the arduino
// More info: http://blog.riyas.org/2014/06/cheap-remote-wireless-temperature-sensor-with-arduino-uno-433mhz-rfmodule.html
#include <VirtualWire.h>
#include <OneWire.h>
#define SensorPin A0 //pH meter Analog output to Arduino Analog Input 0
#define Offset 0.00 //deviation compensate
#define LED 13
#define samplingInterval 20
#define printInterval 800
#define ArrayLenth 40 //times of collection
int pHArray[ArrayLenth]; //Store the average value of the sensor feedback
int pHArrayIndex=0;
int DS18S20_Pin = 8; //DS18S20 Signal pin on digital 2
OneWire ds(DS18S20_Pin); // on digital pin 2
char *controller;
char msg[6], msg2[6];

void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
vw_set_ptt_inverted(true); //
vw_set_tx_pin(7);
vw_setup(4000);// speed of data transfer Kbps

}
void loop()
{
float temperature = getTemp();
Serial.print("Temperature value: ");
Serial.println(temperature);
dtostrf(temperature, 6, 2, msg);
digitalWrite(13,0);
vw_send((uint8_t *)msg, strlen(msg)); // Send temperature.
vw_wait_tx();
delay(500);
digitalWrite(13,1); // blink the led on pin13
delay(500);
float pHValue = getph ();
Serial.println(pHValue);
dtostrf(pHValue, 6, 2, msg2);
digitalWrite(13,0);
vw_send((uint8_t *)msg, strlen(msg2)); // Send ph.
vw_wait_tx();
delay(500);
digitalWrite(13,1); // blink the led on pin13
delay(500);

}
float getph()
{ static unsigned long samplingTime = millis();
static unsigned long printTime = millis();
static float pHValue,voltage;
byte data[12];
byte addr[8];
if(millis()-samplingTime > samplingInterval)
{
pHArray[pHArrayIndex++]=analogRead(SensorPin);
if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;
voltage = avergearray(pHArray, ArrayLenth)5.0/1024;
pHValue = 3.5
voltage+Offset;
samplingTime=millis();
}
if(millis() - printTime > printInterval) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
{
Serial.print("pH value: ");
Serial.println(pHValue,2);
digitalWrite(LED,digitalRead(LED)^1);
printTime=millis();

}
}
double avergearray(int* arr, int number){
int i;
int max,min;
double avg;
long amount=0;
if(number<=0){
Serial.println(“Error number for the array to avraging!/n”);
return 0;
}
if(number<5){ //less than 5, calculated directly statistics
for(i=0;i<number;i++){
amount+=arr*;*

  • }*
  • avg = amount/number;*
  • return avg;*
  • }else{*
  • if(arr[0]<arr[1]){*
  • min = arr[0];max=arr[1];*
  • }*
  • else{*
  • min=arr[1];max=arr[0];*
  • }*
  • for(i=2;i<number;i++){*
    _ if(arr*<min){_
    _
    amount+=min; //arr<min*_
    _ min=arr*;
    }else {
    if(arr>max){
    amount+=max; //arr>max*

    max=arr*;
    }else{
    amount+=arr; //min<=arr<=max*

    * }
    }//if*

    * }//for*
    * byte data[12];
    byte addr[8];
    byte MSB = data[1];
    byte LSB = data[0];
    float pHValue = ((MSB << 8) | LSB);*_

* avg = (double)amount/(number-2);*
* }//if*
* return avg;*
}
*float getTemp() *
*{ *
* //returns the temperature from one DS18S20 in DEG Celsius *
* byte data[12]; *
* byte addr[8]; *
* if ( !ds.search(addr)) { *
* //no more sensors on chain, reset search *
* ds.reset_search();
_ return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println(“CRC is not valid!”);
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print(“Device is not recognized”);
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes *

data = ds.read();
} _

ds.reset_search();
_ byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB); //using two’s compliment
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
[/quote]_

And what do you think this does?

      vw_send((uint8_t *)msg, strlen(msg2)); // Send ph.

Please figure out how to post code using the </> button - its the very first icon even.

Suppose you create a function, getAndSendTemperature(). Which of your code should be in that function?

Suppose you create a function, getAndSendPH(). Which of your code should be in that function? Which of THAT code actually sends the data?

I suggest to write a program that measures pH and temperature, and outputs those values to the serial monitor.

When that is working perfectly, it won't be too hard to have the program send the values over the radio instead.

Instead of this:

vw_send((uint8_t *)msg, strlen(msg2)); // Send ph.

Try this:

vw_send((uint8_t *)msg2, strlen(msg2)); // Send ph.

Or, better yet, send the sensor values as integers and send them both at the same time:

typedef struct {
  int32_t intTemp;
  int32_t intpH;
} sensorRecord;

float temperature, pHvalue;
sensorRecord sensors;

void loop() {
  // put your main code here, to run repeatedly:
  temperature = getTemp();
  sensors.intTemp = (int32_t) temperature * 10.0;
  pHvalue = getpH();
  sensors.intpH = (int32_t) pHvalue * 100.0;
  vw_send((uint8_t *)&sensors, sizeof(sensors));
}

jremington:
I suggest to write a program that measures pH and temperature, and outputs those values to the serial monitor.

When that is working perfectly, it won’t be too hard to have the program send the values over the radio instead.

i got that done with this transmitter program

Transmitter

//simple wireless temperature tranmitter   
 // DS18S20 sensor is connected to pin 8  
 // Rf modules tranmit (data) pin is connected to pin 7 on the arduino 
 // More info: http://blog.riyas.org/2014/06/cheap-remote-wireless-temperature-sensor-with-arduino-uno-433mhz-rfmodule.html 
 #include <VirtualWire.h>  
 #include <OneWire.h>   
 #define SensorPin A0            //pH meter Analog output to Arduino Analog Input 0
#define Offset 0.00            //deviation compensate
#define LED 13
#define samplingInterval 20
#define printInterval 800
#define ArrayLenth  40    //times of collection
int pHArray[ArrayLenth];   //Store the average value of the sensor feedback
int pHArrayIndex=0;    
 int DS18S20_Pin = 8; //DS18S20 Signal pin on digital 2  
 OneWire ds(DS18S20_Pin); // on digital pin 2  
 char *controller;  
 char msg[6], msg2[6];

 void setup()   
   {  
      Serial.begin(9600);  
      pinMode(13,OUTPUT); 
      vw_set_ptt_inverted(true); //  
      vw_set_tx_pin(7);  
      vw_setup(4000);// speed of data transfer Kbps

   }  
 void loop()  
   {   
      float temperature = getTemp(); 
      Serial.print("Temperature value: "); 
     Serial.println(temperature);  
      dtostrf(temperature, 6, 2, msg);  
      digitalWrite(13,0);  
      vw_send((uint8_t *)msg, strlen(msg)); // Send temperature.  
      vw_wait_tx();  
      delay(500);  
      digitalWrite(13,1); // blink the led on pin13  
      delay(500);  
      float pHValue = getph ();
         dtostrf(pHValue, 6, 2, msg2);  
      digitalWrite(13,0);  
      vw_send((uint8_t *)msg, strlen(msg2)); // Send ph.  
      vw_wait_tx();  
      delay(500);  
      digitalWrite(13,1); // blink the led on pin13  
      delay(500);  

}
 float getph()   
{   static unsigned long samplingTime = millis();
  static unsigned long printTime = millis();
  static float pHValue,voltage; 
   byte data[12];  
  byte addr[8]; 
  if(millis()-samplingTime > samplingInterval)
  {
      pHArray[pHArrayIndex++]=analogRead(SensorPin);
      if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;
      voltage = avergearray(pHArray, ArrayLenth)*5.0/1024;
      pHValue = 3.5*voltage+Offset;
      samplingTime=millis();
  }
  if(millis() - printTime > printInterval)   //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
  {
        Serial.print("pH value: ");
  Serial.println(pHValue,2);
        digitalWrite(LED,digitalRead(LED)^1);
        printTime=millis();
     
       
       
  }
   }  
 double avergearray(int* arr, int number){
  int i;
  int max,min;
  double avg;
  long amount=0;
  if(number<=0){
    Serial.println("Error number for the array to avraging!/n");
    return 0;
  }
  if(number<5){   //less than 5, calculated directly statistics
    for(i=0;i<number;i++){
      amount+=arr[i];
    }
    avg = amount/number;
    return avg;
  }else{
    if(arr[0]<arr[1]){
      min = arr[0];max=arr[1];
    }
    else{
      min=arr[1];max=arr[0];
    }
    for(i=2;i<number;i++){
      if(arr[i]<min){
        amount+=min;        //arr<min
        min=arr[i];
      }else {
        if(arr[i]>max){
          amount+=max;    //arr>max
          max=arr[i];
        }else{
          amount+=arr[i]; //min<=arr<=max
        }
      }//if
    }//for
      byte data[12];  
  byte addr[8]; 
    byte MSB = data[1];  
  byte LSB = data[0];
    float pHValue = ((MSB << 8) | LSB);
    
    avg = (double)amount/(number-2);
  }//if
  return avg; 
 }
 float getTemp()  
 {  
  //returns the temperature from one DS18S20 in DEG Celsius  
  byte data[12];  
  byte addr[8];  
  if ( !ds.search(addr)) {  
    //no more sensors on chain, reset search  
    ds.reset_search();  
    return -1000;  
  }  
  if ( OneWire::crc8( addr, 7) != addr[7]) {  
    Serial.println("CRC is not valid!");  
    return -1000;  
  }  
  if ( addr[0] != 0x10 && addr[0] != 0x28) {  
    Serial.print("Device is not recognized");  
    return -1000;  
  }  
  ds.reset();  
  ds.select(addr);  
  ds.write(0x44,1); // start conversion, with parasite power on at the end  
  byte present = ds.reset();  
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad  
  for (int i = 0; i < 9; i++) { // we need 9 bytes  
   data[i] = ds.read();  
  }  
  ds.reset_search();  
  byte MSB = data[1];  
  byte LSB = data[0];  
  float tempRead = ((MSB << 8) | LSB); //using two's compliment  
  float TemperatureSum = tempRead / 16;  
  return TemperatureSum;  
 }

with this i am able to view the measurements of temp and ph but on the receiver side could still only see the temp, no ph :frowning:

Receiver

 // wireless temperature receiver using a simple 43mhz module and an lcs/keypad shield  
 // Arduino pin 15 (Analogue 1) is connected to a ds18220 for indoor temperature  
 // Arduino pin 16 (Analogue 2) is connected to the 433mhz receiver for outdoor temperature 
 // Arduino pin 17 (Analogue 3) is connected to an led via 330 ohm resistor  
 // credits to arduino.cc and owners of each libraries and online communities  
 // more details http://blog.riyas.org/2014/06/cheap-remote-wireless-temperature-sensor-with-arduino-uno-433mhz-rfmodule.html
 
#include <OneWire.h>   
 #include <VirtualWire.h>  
 // select the pins used on the LCD panel  

 int DS18S20_Pin = 15; //DS18S20 pin  
 //Temperature chip i/o  
 OneWire ds(DS18S20_Pin); // on pin 15  
 void setup()  
 {  

  Serial.begin(9600);  
  vw_set_ptt_inverted(true); // Required for DR3100  
  vw_set_rx_pin(2);  
  vw_setup(4000); // Bits per sec  
  vw_rx_start(); 
  pinMode(17,OUTPUT);  // for an led on pin 17 (Analogue 3)to blink with rf link
 
 }  
 void loop()  
 {  
  uint8_t buf[VW_MAX_MESSAGE_LEN];  
  uint8_t buflen = VW_MAX_MESSAGE_LEN;    
  if (vw_get_message(buf, &buflen)) // Non-blocking  
   {   
    char temp=0;//mod:tim:added a temporary character    
    for (int i = 0; i < buflen; i++)    
    {   
     temp=(char)buf[i];//mod:tim:convert uint to char  
     Serial.print(temp); //mod:tim:changed buff[i] to temp here  
  
    }  
     Serial.println("");      
    
   }  

 }

Receiver 2

#include <OneWire.h>   
 #include <VirtualWire.h>  
 // select the pins used on the LCD panel  

 int DS18S20_Pin = 15; //DS18S20 pin  
 //Temperature chip i/o  
 OneWire ds(DS18S20_Pin); // on pin 15  
 void setup()  
 {  

  Serial.begin(9600);  
  vw_set_ptt_inverted(true); // Required for DR3100  
  vw_set_rx_pin(2);  
  vw_setup(4000); // Bits per sec  
  vw_rx_start(); 
  pinMode(17,OUTPUT);  // for an led on pin 17 (Analogue 3)to blink with rf link
 
 }  
 void loop()  
 {  
  uint8_t buf[VW_MAX_MESSAGE_LEN];  
  uint8_t buflen = VW_MAX_MESSAGE_LEN;    
  if (vw_get_message(buf, &buflen)) // Non-blocking  
   {   
    char temp=0;//mod:tim:added a temporary character    
    for (int i = 0; i < buflen; i++)    
    {   
     temp=(char)buf[i];//mod:tim:convert uint to char  
     Serial.print(temp); //mod:tim:changed buff[i] to temp here  
  
    }  
     Serial.println("");      
    
   }  
    {   
    char ph=0;//mod:tim:added a temporary character    
    for (int i = 0; i < buflen; i++)    
    {   
     ph=(char)buf[i];//mod:tim:convert uint to char  
     Serial.print(ph); //mod:tim:changed buff[i] to temp here  
  
    }  
     Serial.println("");      
    
   }  

 }

i got some weird results using this ^ (shows the temp and some random square boxes)

This won't work:

 char msg[6], msg2[6];
...
dtostrf(temperature, 6, 2, msg);

Your message buffers must be declared [u]at least one character larger[/u] than the total message length, in order to store the zero terminator byte. In the above case, declare msg[7] or larger.

This requirement is true of all character string arrays.

gfvalvo: Instead of this:

vw_send((uint8_t *)msg, strlen(msg2)); // Send ph.

Try this:

vw_send((uint8_t *)msg2, strlen(msg2)); // Send ph.

nothing really happened

gfvalvo: Or, better yet, send the sensor values as integers and send them both at the same time:

typedef struct {
  int32_t intTemp;
  int32_t intpH;
} sensorRecord;

float temperature, pHvalue; sensorRecord sensors;

void loop() {  // put your main code here, to run repeatedly:  temperature = getTemp();  sensors.intTemp = (int32_t) temperature * 10.0;  pHvalue = getpH();  sensors.intpH = (int32_t) pHvalue * 100.0;  vw_send((uint8_t *)&sensors, sizeof(sensors)); }

i dont have a clue how to integrate the whole thing into my program :(

PaulS: Suppose you create a function, getAndSendTemperature(). Which of your code should be in that function?

Suppose you create a function, getAndSendPH(). Which of your code should be in that function? Which of THAT code actually sends the data?

hmmm ?

jremington: This won't work:

 char msg[6], msg2[6];
...
dtostrf(temperature, 6, 2, msg);

Your message buffers must be declared [u]at least one character larger[/u] than the total message length, in order to store the zero terminator byte. In the above case, declare msg[7] or larger.

This requirement is true of all character string arrays.

oh ! im getting a second signal in the receiver but it's only an interval of 0s and the temp measurement.

image: https://postimg.org/image/6jzlwlm73/

so close

PaulS:
Suppose you create a function, getAndSendTemperature(). Which of your code should be in that function?

Suppose you create a function, getAndSendPH(). Which of your code should be in that function? Which of THAT code actually sends the data?

i think im seeing your point but i dont know which part of the program actually does that
when the Serial.println(pHValue); is placed here the value i get is 0 but when i moved it

 float pHValue = getph ();
      Serial.println(pHValue);
      dtostrf(pHValue, 6, 2, msg);

to

   float getph()   
{   static unsigned long samplingTime = millis();
  static unsigned long printTime = millis();
  static float pHValue,voltage; 
   byte data[12];  
  byte addr[8]; 
  if(millis()-samplingTime > samplingInterval)
  {
      pHArray[pHArrayIndex++]=analogRead(SensorPin);
      if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;
      voltage = avergearray(pHArray, ArrayLenth)*5.0/1024;
      pHValue = 3.5*voltage+Offset;
      samplingTime=millis();
  }
if(millis() - printTime > printInterval)   //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
  {
        Serial.print("pH value: ");
  Serial.println(pHValue,2);
        digitalWrite(LED,digitalRead(LED)^1);
        printTime=millis();

i get the correct value hmmmm

I think it has something to do with this code but this is for the DS temp sensor

 if ( !ds.search(addr)) {  
    //no more sensors on chain, reset search  
    ds.reset_search();  
    return -1000;  
  }  
  if ( OneWire::crc8( addr, 7) != addr[7]) {  
    Serial.println("CRC is not valid!");  
    return -1000;  
  }  
  if ( addr[0] != 0x10 && addr[0] != 0x28) {  
    Serial.print("Device is not recognized");  
    return -1000;  
  }  
  ds.reset();  
  ds.select(addr);  
  ds.write(0x44,1); // start conversion, with parasite power on at the end  
  byte present = ds.reset();  
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad  
  for (int i = 0; i < 9; i++) { // we need 9 bytes  
   data[i] = ds.read();  
  }  
  ds.reset_search();

If you send temperature in one message, and pH in the next message, how is the receiver supposed to know which message contains temperature, and which contains pH?

Now, if you were to receive “T: 27.4, P: 293.4”, could YOU tell which value was temperature and which was pH? Can you figure out how to send that single message? sprintf() or strcpy() and strcat() would be useful functions.

it seems i've gotten it to work somehow... thanks for your advice all !