I need help with code.
Project is wirelss tranmsiiter using NRF24L01.
Tranmitter conditions.
Here we are using arduino mini pro and wokring with 3.3v battery. Conditions are 1. when battery is getting low it should send message to receiver.
2. There will be one tilt sensor when it is active it should send message to receiver.
Receiver.
when receiver gets message from transmitter that battery is getting low then any one digital pin should get high and also if message received as tilt sensor is active another digital pin should get high.
Tranmitter main condtion are battery should work minimum for 1 year.
your formatting is a mess. Do an autoformat (ctrl-T in the IDE) and it's going to be a lto more readable,
you're generously using delay() calls.
Other than that - without a clear description of what the code does and how that's different from what you want it to do, nothing more to say at this point.
Ok let me share another code which is working fine.
But the problem is transmitter always sends message due to this battery might die soon. so i need help to make transmitter device to send message only when there is input the device should go complete sleep.
My battery should work minimum for 1 year.
// transmitter
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[2]; // msg[0] is volts , msg[1] is tilt
const float referenceVolts = 5;
RF24 radio(7, 8);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 3;
const float Volt = 2;
void setup(void) {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
}
void loop(void) {
int val = analogRead(A2);
// read the value from the sensor
float volts = (val / 1023.0) * referenceVolts;
Serial.println(volts);
if (volts < Volt) msg[0] = 1;
else msg[0] = 0 ;
if (digitalRead(SW1) == HIGH) msg[1] = 1;
else msg[1] = 0;
radio.write(msg, 4);
delay(3000);
}
receiver
// receiver
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[2]; // msg[0] is volts , msg[1] is tilt
RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;
int LED2 = 4;
void setup(void) {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, pipe);
radio.startListening();
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
}
void loop(void) {
if (radio.available()) {
bool done = radio.read(msg, 4);
Serial.print(msg[0]);
Serial.print(" ");
Serial.println(msg[1]);
if (msg[0] == 1) digitalWrite(LED1, HIGH);
else digitalWrite(LED1, LOW);
if (msg[1] == 1) digitalWrite(LED2, HIGH);
else digitalWrite(LED2, LOW);
}
// could put code here to switch leds off if
// no radio activity detected in last X seconds
}
For reading the battery value: the easiest is to have the Arduino measure its own Vcc as explained here (this assuming your battery directly powers the Arduino).
Then the sleep part.
When do you want it to go to sleep?
At least as important: when/how do you want it to wake up?
wvmarle:
Then the sleep part.
When do you want it to go to sleep?
At least as important: when/how do you want it to wake up?
If there is no input data at transmitter that is if battery is good and tilt sensor is not active device should be in sleep mode. if there any either of the data it should wakeup and send message.
You can have it wake on interrupt by the sleep sensor, and then check the battery status.
When in deep sleep mode an ATmega328p MCU draws so little power a pair of AA batteries can last for 5-10 years. The Pro Mini needs at least the LED removed to make it low power.
Hi, I have a very similar set up in my home automation project. Some arduinos transmitting door sensor or PIR status, battery level and temperature to a central receiver using nrf24l01. First prototype was an arduino pro mini, now I have designed a specific PCB. If you want to save power with a mini you should remove the LED and the voltage regulator.
Mine runs on a LifePO4 battery, goes to deep sleep and reports data either on sensor state change or periodically if no change occurs. I also added a calibration value for the voltage measurement that is stored in EEPROM.
The code is here