Hi guys.
I am trying to send data from slave to master on request for the first time and im kinda stuck at the finish line (or so i think )
I am trying to send PPM value from TDS sensor and temperature value from waterproof temp sensor from the slave to the master.
Slave: arduino UNO R3
Master: Mega 2560
CODE:
#include <Wire.h>
#include <EEPROM.h>
#include "GravityTDS.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 7
#define TdsSensorPin A1
OneWire oneWire(ONE_WIRE_BUS);
GravityTDS gravityTds;
DallasTemperature sensors(&oneWire);
float tdsValue = 0;
void setup() {
Serial.begin(9600);
sensors.begin();
gravityTds.setPin(TdsSensorPin);
gravityTds.setAref(5.0); //reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds.setAdcRange(1024); //1024 for 10bit ADC;4096 for 12bit ADC
gravityTds.begin(); //initialization
Wire.begin(8); // join I2C bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
sensors.requestTemperatures();
gravityTds.setTemperature(sensors.getTempCByIndex(0)); // set the temperature and execute temperature compensation
gravityTds.update(); //sample and calculate
tdsValue = gravityTds.getTdsValue(); // then get the value
Serial.print(tdsValue,0);
Serial.println("ppm");
Serial.print("Temperature is: ");
Serial.println(sensors.getTempCByIndex(0));
delay(6000);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
Wire.write("PPM: ");
......help needed here
}
How do i send data other than plain text or numbers?
Your 'tdsValue' is already a global variable.
Then you can send those 4 bytes with:
Wire.write((byte *) &tdsValue, 4);
Can you do everything with a single Arduino board ?
Projects fail that use the I2C bus to communicate between Arduino boards.
How long is the distance between the boards ?
the distance is minimal..
The problem is that i would like to combine EC and PH sensors. But if i connect them to 1 board the PH readings are way off..I found a solution via some transistors that turn TDS meter off while the board is recieving PH values but i hoped this would be an easier solution since i am still new to this. I get a bit lost with those transistors and some other stuff but it seems there will be no other way as this seems a bit "unstable"
Solving a problem by creating a bigger problem is never easy
Can you buy a galvanic isolated PH module ?
Can you give us a broader view of your project ? What do you want to do ? Which sensors do you want to use (with links to where you bought them).
Does the EC sensor measure the conductivity of water ? I suppose that so many sensors is not just for an aquarium ?
Yes i see now that this will be a more complicated system and i will not use 2 boards, just a MEGA 2560
I am making a hydroponics system for growing plants.
My TDS sensor measures conductivity and reports the EC back to me. I also use water temp sensor and a PH sensor.
Then for example if PH >6 ---->turn on pump 1 (ph- solution), if PH<5,6 ---> turn on pump 2 (PH+ solution)
With the EC its a bit more tricky since the required level changes...here i hope i will find some kind of a "user input" solution so it would go something like for example( user sets EC value to 2.1) if EC>2.1 --->all pumps off and if EC<2 ---->turn on pumps (from 3-6 depending on which type of nutrient i need)
This will be done through ESP guided relay modules..
I hope i have written it clear enough...
Stuff used: PH TDS Relay
The TDS sensor puts electricity in the water ? That will mess up the PH sensor for sure.
The TDS sensor has to be turned off. Perhaps with a transistor or mosfet or even a relay. I think that only turning off the 5V power to the module is enough.
Can the module be powered with a output pin of the Arduino ? The Mega board can output 20mA with a output pin.
I will be growing industrial hemp for oils and tinctures, i will also try to mix hemp with honey since i am a beekeeper.
I will power the circuit from an exterior power supply so the power will not be an issue..
For starters i will try using a mosfet, and just switch them on and off for the readings, it could work yes..
And the isolated PH module is also a good idea, havent thought about that, thanks.