I am transmitting one digital and analog data from transmitter(arduino mini pro) to receiver (arduino uno).
digital data is when sensor gets activate it will send message to receiver and din4 pin at receiver will get high, In analog if A0 volatge is less that 2V it will send message to receiver and din3 will get high.
The problem is if remove power supply to transmitter and connects again it is not transmitting data then if i reset the transmitter device by removing analog input pin then it is working.
What will be the issue? i tried with another new board again the same issue.
please help me solve the issue.
Here is the code
transmitter
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
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(A0);
// read the value from the sensor
float volts = (val / 1023.0) * referenceVolts;
Serial.println(volts);
if ((volts) < (Volt)){
delay(3000);
msg[0] = 121;
radio.write(msg, 1);}
} delay(100);
if (digitalRead(SW1) == HIGH){
msg[0] = 222;
radio.write(msg, 1);}}
Also, your code is nearly unreadable. Assuming you're using the Arduino IDE, please autoformat it so you don't have multiple curly brackets on one line (among other things).
Also, your code is nearly unreadable. Assuming you're using the Arduino IDE, please autoformat it so you don't have multiple curly brackets on one line (among other things).
{
int val = analogRead(A0);
// read the value from the sensor
float volts = (val / 1023.0) * referenceVolts;
Serial.println(volts);
if (volts < Volt) {
delay(3000);
msg[0] = 121;
radio.write(msg, 2);
}
if i delete this part and try to send digital data it is working fine.
my task is to send digital dat when tilt sensor is activated and transmitter is working with battery if battery goes less than 2v it should send message to the receiver and make digital pin high at receiver.
i am stuck with analog part sending message when it goes less than 2v. when i unplug power supply an d plug in again i need make sensor active and reset device all the time.
can you please check the code to send message to transmitter when voltage goes less than 2
I don't think it matters - you're just wasting a couple of bytes.
I suggest that you make a much more minimal pair of programs that do nothing but send msg[0] every few seconds and see if you can receive and print the value. Something's broken and the rest of your code is just making it harder to see what.
Also in the transmitter part, you have a number of surplus and incorrectly placed brackets '}' and '{' that the logic is wrong in that msg[0] has no value assigned to it when SW1 is LOW. This could be the cause of the odd results in the serial monitor.
The indentation when you format the code should give you a clue.
6v6gt:
Also in the transmitter part, you have a number of surplus and incorrectly placed brackets '}' and '{' that the logic is wrong in that msg[0] has no value assigned to it when SW1 is LOW. This could be the cause of the odd results in the serial monitor.
The indentation when you format the code should give you a clue.