I'm currently trying to create a wireless pressure sensor system. This will utilise 6 transmitters and 1 receiver.
I've created my code by adapting something I found on the forum, however I'm now at the stage where I'm trying to integrate the NRF24 radios and I'm at a complete loss (though that isn't hard as I'm a copy/paste/tweak person rather than an actual coder).
My existing code works to take a reading from a pressure sensor (A1) and convert it into the units of PSI and Bar, then display these values on a screen (I2C)
My objective is to display the data on a receiver display from each of the transmitters. A future phase will be to display this in a live chart on an iPad but baby step first!
I've now got the hardware to add the radio element but don't understand how to combine example sketches I see.
#include "Wire.h" //allows communication over i2c devices
#include "LiquidCrystal_I2C.h" //allows interfacing with LCD screens
const int pressureInput = A1; //select the analog input pin for the pressure transducer
const int pressureZero = 101; //analog reading of pressure transducer at 0psi
const int pressureMax = 922; //analog reading of pressure transducer at 100psi
const int pressuretransducermaxPSI = 300; //psi value of transducer being used
const int baudRate = 9600; //constant integer to set the baud rate for serial monitor
const int sensorreadDelay = 1000; //constant integer to set the sensor read delay in milliseconds
float pressureValue = 0; //variable to store the value coming from the pressure transducer
float pressureValueBar = 0; //DS variable to store the value in BAR
LiquidCrystal_I2C lcd(0x27, 20, 4); //sets the LCD I2C communication address; format(address, columns, rows)
void setup() //setup routine, runs once when system turned on or reset
{
Serial.begin(baudRate); //initializes serial communication at set baud rate bits per second
lcd.begin(0x27,20,4); //initializes the LCD screen
}
void loop() //loop routine runs over and over again forever
{
pressureValue = analogRead(pressureInput); //reads value from input pin and assigns to variable
pressureValue = ((pressureValue-pressureZero)*pressuretransducermaxPSI)/(pressureMax-pressureZero); //conversion equation to convert analog reading to psi
pressureValueBar = (pressureValue/14.5038);
Serial.print(pressureValue, 1); //prints value from previous line to serial
Serial.println("psi"); //prints label to serial
Serial.print(pressureValueBar, 2);
Serial.println("BAR");
lcd.backlight();
lcd.setCursor(0,0); //sets cursor to column 0, row 0
lcd.print("Pressure:"); //prints label
lcd.print(pressureValue, 1); //prints pressure value to lcd screen, 1 digit on float
lcd.print("PSI"); //prints label after value
lcd.setCursor(0,2);
lcd.print("Pressure:");
lcd.print(pressureValueBar, 1);
lcd.print("BAR");
//lcd.print(" "); //to clear the display after large values or negatives
delay(sensorreadDelay); //delay in milliseconds between read values
lcd.clear();
}
My NRF24 are connected via pins D9-D13 and I'm using Arduino Nano's for this project.
Yes I've had it working using the basic TX / Basic RX script as given in the examples, so I know those work. The NRF24s have the power adapter board on them taking 5v from the Arduino.
if you have multiple transmitters you probably need to identify the specific transmitter - I would use a structure which carries a transmitter ID plus the data. e.g.
struct Data {
int NodeID; // ID of transmitting node
int seq; // sequence number
int x;
float y;
char z[10];
byte crc;
};
how often do the transmitters transmit data?
what happens if two transmitters transmit at the same instant and corrupt each other ? will missing the odd data packet matter?
What is the distance involved? Have you considered ESP-NOW or LORA?
I would also make the data packet more robust with length, start and end matching CRC.
I'd like once every 5 seconds if possible. We're measuring pressure differentials on a factory network so it doesn't really matter if there's an odd packet dropped.
Communication in factories can be tricky due to electrical noise from machines etc
in particular it can corrupt wireless communications
consider using ethernet
what distances are involved?
some time back I worked on a system in a factory monitoring knitting machines - the machines reported work flows, operator status, broken tools, etc using UDP datagrames over Ethernet to a central server
These are temporary problem solving tools used for when we go to sites to diagnose underperforming air supplies. We often find that whilst the pressure is sufficient at one end, the variances at the extreme ends of the networks can cause unsighted problems in machines dropping out, as a result of other machines lowering the pressure due to usage, so wireless systems are a key requirement.
Allow me to more than just HEART the post 10 reply, as a former industrial electrician and long-time systems analyst, that is not just great advice, it is the easiest to implement, possibly least expensive and quickest. You might even be able to use POE to solve some power issues.
However, if 200m, then I would add two repeaters, since the maximum distance is 100m. But do not be fooled into thinking that 200m/100m is equivalent to two segments; that is the best-case scenario. Therefore, three segments of 70ish will work better. See the attached chart for speed and distance trade-offs.
Remember, all routers, switches, and repeaters must be PoE capable if you plan on powering the remotes that way.
I have no idea how NRF24 modules would perform in such an environment
would the factories have local reliable WiFi?
could consider LoRa?
I think you will need to experiment in a factory - see what works
try a web search for wifi in factories - there are plenty of articles discussing problems and solutions
Issues of powering the NRF24 from the Arduino's 5V pin (generally a bad idea) and suitability of NRF24 for your target environment aside, the easiest way to implement multiple TX data senders with one RX data receiver is to use the NRF24's "ACK with payload" feature. In this scheme the data receiver acts as a master and polls each of the data transmitters (slaves) with a message one at a time.
The slaves have preloaded their sensor data into a NRF24 register area. When they receive the polling message, they automatically reply with an ACK packet containing the sensor data. After being polled, they take another sensor reading and load it into the NRF24 for the next time.