I'm trying to create a laser trip wire that activates a servo when the laser is broken. I'm using NRF24L01+ boards to communicate from the transmitter box to the receiver box with the servo. I'm new programing can someone please help and point me in the right direction. I'm using two Arduino Nano Every.
TRANSMITTER
#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define LEDS 1
#define PIN 10
const int ldrPin = A0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN ,NEO_GRB + NEO_KHZ800);
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
int ldrStatus;
void setup() {
Serial.begin(9600);
pinMode(12, OUTPUT);
radio.begin();
radio.openWritingPipe(addresses[1]); // 00001
radio.openReadingPipe(1, addresses[0]); // 00002
radio.setPALevel(RF24_PA_MAX);
strip.begin();
strip.show();
}
void loop() {
ldrStatus = analogRead(ldrPin);
delay(5);
radio.stopListening();
radio.write(&ldrStatus, sizeof(ldrStatus));
if(ldrStatus>940)
{
strip.setPixelColor(0, 0, 255, 0); //RED
strip.show();
}
else
{
strip.setPixelColor(0, 255, 0, 0); //GREEN
strip.show();
}
} // end of program
RECIEVER
#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#define LEDS 1
#define PIN 10
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN ,NEO_GRB + NEO_KHZ800);
RF24 radio(7, 8);
const byte addresses[][6] = {"00001", "00002"};
Servo servo1;
int ldrStatus;
void setup() {
Serial.begin(9600);
pinMode(button, INPUT);
servo1.attach(5);
radio.begin();
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1, addresses[1]);
radio.setPALevel(RF24_PA_MAX);
pinMode(button,INPUT_PULLUP);
strip.begin();
strip.show();
strip.setPixelColor(0, 0, 0, 0);
strip.show();
}
void loop() {
if(ldrStatus==0)
{
strip.setPixelColor(0, 0, 0, 255); //BLUE
strip.show();
}
if(ldrStatus>0)
{
strip.setPixelColor(0,0, 255, 0); //RED
strip.show();
}
delay(5);
radio.startListening();
radio.read(&ldrStatus, sizeof(ldrStatus));
servo1.write(100);
if((ldrStatus<940)&& (ldrStatus>10))
{
strip.setPixelColor(0, 255, 0, 0); //GREEN
strip.show();
servo1.write(30);
delay(100);
}
} // end of program


