AUTO SWITCH LED STRIP LIGHT

stair desain

Sensor 1

sensor1

#include <SPI.h>

#include “nRF24L01.h”

#include “RF24.h”

int DataMgs[1];

RF24 radio(8,7);

const uint64_t pipe = 0xE14BC8F482LL;

#include <avr/interrupt.h>

#include <avr/eeprom.h>

int addr1 = 1;

int readValue1;

int a;

const int buttonPin1 = 9; //button for calibration

int buttonState1 = 0;

#include <SoftPWM.h>

int pirPin = 4;

int statePir = 0;

void setup()

{

pinMode(buttonPin1, INPUT);

digitalWrite(buttonPin1, HIGH);

SoftPWMBegin();

SoftPWMSet(3, 0);

SoftPWMSetFadeTime(3, 3000, 2000);

Serial.begin(9600);

pinMode(pirPin,INPUT);

radio.begin();

radio.openReadingPipe(1,pipe);

radio.startListening();

gelap();

}

void loop()

{

buttonState1 = digitalRead(buttonPin1);

if (buttonState1 == LOW) {

a = analogRead(A0);

while (!eeprom_is_ready());

cli();

if(eeprom_read_word((uint16_t*)addr1) != a) {

eeprom_write_word((uint16_t*)addr1, a);

}

sei();

}

else{

action();

}

}

void gelap(){

SoftPWMSet(3, 0);

}

void white(){

SoftPWMSet(3, 255);

}

void action(){

readValue1 = eeprom_read_word((uint16_t*)addr1);

if (radio.available())

{

bool done = false;

while (!done)

{

a = analogRead(A0);

readValue1 = eeprom_read_word((uint16_t*)addr1);

statePir = digitalRead(pirPin);

done = radio.read(DataMgs, 1);

if (((DataMgs[0] == 1)||(statePir == HIGH))&&(a < readValue1))

{

white();

delay(20000);

}

else

{

gelap();

Serial.println(readValue1);

}

//delay(100);

}

}

else{

}

}

Sensor 2

sensor2

#include <SPI.h>

#include “nRF24L01.h”

#include “RF24.h”

int pirPin = 2;

int statePir = 0;

int DataMsg[1];

RF24 radio(8,7);

const uint64_t pipe = 0xE14BC8F482LL;

void setup()

{

pinMode(pirPin,INPUT);

Serial.begin(9600);

Serial.println(“NRF24L01 Transmitter”);

radio.begin();

radio.openWritingPipe(pipe);

}

void loop()

{

statePir = digitalRead(pirPin);

if (statePir == HIGH)

{

DataMsg[0] = 1;

radio.write(DataMsg, 1);

}

if (statePir == LOW)

{

DataMsg[0] = 2;

radio.write(DataMsg, 1);

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s