I am making a wireless multi-function sensor that will use many sensors do gather environmental info when I am finished. I am using a pro-mini with a NRF24 that is sending the gathered data to a wemos D1 mini that is connecting to blynk server. As of now I have the code reading the built in VCC for the mini to monitor the battery, a analog value for the thermistor and a soil moisture sensor. The VCC and temp readings are perfect, but as soon as I add the sensor to the code everything goes haywire. I think the problem is in my code for the transmission?
Any suggestions would be great, thank you.
Here is the Transmitter code
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte addresses [][6] = {"00001", "00002"}; //Setting the two addresses. One for transmitting and one for receiving
int led = 3;
int moisture = A3;
int gTemp = A0;
int gTempON = 5;
void setup()
{
pinMode(led, OUTPUT);
pinMode(gTempON, OUTPUT);
Serial.begin(9600);
radio.begin(); //Starting the radio communication
radio.openWritingPipe(addresses[0]); //Setting the address at which we will send the data
radio.openReadingPipe(1, addresses[1]); //Setting the address at which we will receive the data
radio.setPALevel(RF24_PA_MAX); //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
}
void loop()
{
int V = readVcc();
digitalWrite(gTempON, HIGH);
int gTempRAW = analogRead(gTemp);
int gTempC = map(gTempRAW,266 ,591 ,0 ,36);
float gTempF = (gTempC * 1.8) +32;
digitalWrite(gTempON, LOW);
int value = analogRead(moisture);
int val = map(value, 460, 860, 100, 0);
radio.stopListening();
radio.write(&gTempF, sizeof(gTempF));
radio.write(&val, sizeof(val));
radio.write(&V,sizeof(V));
}
long readVcc()
{
long result; // Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}
Here is the reciever
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "";
char ssid[] = "";
char pass[] = "";
BlynkTimer timer; // Announcing the timer
#define PIN_UPTIME V5
RF24 radio(D2, D8); // CE, CSN
const byte addresses [][6] = {"00001", "00002"}; //Setting the two addresses. One for transmitting and one for receiving
int led_pin = D4;
int V ;
int val ;
float gTempF ;
// This function tells Arduino what to do if there is a Widget
// which is requesting data for Virtual Pin (5)
BLYNK_READ(PIN_UPTIME)
{
// This command writes Arduino's uptime in seconds to Virtual Pin (5)
Blynk.virtualWrite(PIN_UPTIME, millis() / 1000);
}
void setup()
{
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, TimerV);
Serial.begin(9600);
pinMode(led_pin, OUTPUT);
radio.begin(); //Starting the radio communication
radio.openWritingPipe(addresses[1]); //Setting the address at which we will send the data
radio.openReadingPipe(1, addresses[0]); //Setting the address at which we will receive the data
radio.setPALevel(RF24_PA_MAX); //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
}
void TimerV()
{
radio.startListening();
if(!radio.available());
{
radio.read(&val,sizeof(val));
radio.read(&gTempF,sizeof(gTempF));
radio.read(&V, sizeof(V));
}
Blynk.virtualWrite(V2, gTempF);
Blynk.virtualWrite(V0, val);
Blynk.virtualWrite(V1, V);
}
void loop()
{
Blynk.run();
timer.run();
}