Hi everybody! I'm working on a project which involves the use of two Arduino UNO boards.
It's a sort of chrono sensor. On both i installed an UltraSonic HC-04 Module and i have to connect it with the nRF24L01 Upgraded Version (the green one).
I'm still working on the two codes, here's the one of the "Start Sensor":
#include "RTClib.h"
#include <Wire.h>
RTC_DS1307 RTC;
int trigPin = 2;
int echoPin = 3;
int ledVerde = 12;
int ledRosso = 13;
int ct;
int s;
int m;
void setup() {
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running");
}
DateTime now = RTC.now();
DateTime compiled = DateTime(__DATE__, __TIME__);
if (now.unixtime() < compiled.unixtime()) {
Serial.println("RTC is older than compile time! UPDATING");
RTC.adjust(DateTime(__DATE__, __TIME__));
}
Serial.println("Cronometro pronto.");
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledVerde, OUTPUT);
pinMode(ledRosso, OUTPUT);
}
void loop() {
digitalWrite(ledRosso, HIGH);
digitalWrite(ledVerde, LOW);
int duration;
int distance;
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 100 && distance >= 0) {
digitalWrite(ledVerde, HIGH);
while (digitalRead(ledVerde) == HIGH) {
timer();
}
}
}
void timer() {
DateTime now = RTC.now();
Serial.print("Tempo: ");
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
}
And here's the one of the "Arrive Sensor":
#include <LiquidCrystal.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int trigPin = 6;
int echoPin = 7;
int ct;
int s;
int m;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
RF24 radio(7, 8);
const byte addresses[] [6] = {"00001"};
void setup() {
lcd.begin(16, 2);
radio.begin();
radio.openWritingPipe(addresses[1]);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
pinMode(LED_BUILTIN, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
int duration;
int distance;
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 100 && distance >= 0) {
digitalWrite(LED_BUILTIN, LOW);
while (digitalRead(LED_BUILTIN) == LOW) {
!timer();
}
radio.write(timer, sizeof(timer));
delay(1000);
}
}
void timer() {
ct = ct + 1;
lcd.print(m);
lcd.print(":");
lcd.print(s);
lcd.print(".");
lcd.print(ct);
delay(95.65);
lcd.clear();
if (ct == 10) {
ct = 0;
s = s + 1;
}
if (s == 60) {
s = 0;
m = m + 1;
}
}
Now, the problem.
Both have to work as a transmitter and as a receiver.
The first one has to transmit the void "timer()" to start on the second module when the bike pass in front of the "Start Sensor", where it should appear on an lcd screen.
When the bike pass in front of the "Arrive Sensor", it has to send a signal to the "Start Sensor" to stop the void "timer()".
I can't figure out how to send the signals and how to stop the void "timer()"!
Could you help me out?
Thanks in advance, best regards