TOUCHLESS LAMP SWITCH

Transmitter

touchless trans

//this device utilise IR proximity sensor module for trigger switching

#include <SPI.h>

#include “nRF24L01.h”

#include “RF24.h”

int DataMsg[1];

RF24 radio(8,7);

const uint64_t pipe = 0xE14BC8F483LL;

void setup()

{

Serial.begin(9600);

Serial.println(“NRF24L01 Transmitter”);

radio.begin();

radio.openWritingPipe(pipe);

}

void loop()

{

int sensorValue0 = analogRead(A1);

if (sensorValue0 < 100)

{

DataMsg[0] = 1;

radio.write(DataMsg, 1);

}

else

{

DataMsg[0] = 2;

radio.write(DataMsg, 1);

}

}

Receiver

touchless recv

Sket 1 : without memory

//This sket mean light status will reset to ON or OFF when power arduino be reset.

#include <SPI.h>

#include “nRF24L01.h”

#include “RF24.h”

int DataMgs[1];

RF24 radio(8,7);

const uint64_t pipe = 0xE14BC8F483LL;

int led = 3;

void setup()

{

pinMode(led, OUTPUT);

Serial.begin(9600);

radio.begin();

radio.openReadingPipe(1,pipe);

radio.startListening();

}

int on = 0;

unsigned long last = millis();

void loop()

{

if (radio.available())

{

bool done = false;

while (!done)

{

done = radio.read(DataMgs, 1);

//Serial.print(“NRF24L01 Receiver: “);

//Serial.println(DataMgs[0]);

if (DataMgs[0] == 1)

{

if (millis() – last > 250) {

on = !on;

digitalWrite(led, on ? HIGH : LOW);

}

last = millis();

}

if (DataMgs[0] == 2)

{

}

//delay(100);

}

}

else

{

//Serial.println(“Waiting for signal…”);

}

}

———————————————

Sket 2 : with memory

//This sket mean light status will follow the last status of light when arduino be reset

#include <SPI.h>

#include “nRF24L01.h”

#include “RF24.h”

#include <EEPROM.h>

int DataMgs[1];

RF24 radio(8,7);

const uint64_t pipe = 0xE14BC8F483LL;

int led = 3;

byte laju;

void setup()

{

pinMode(led, OUTPUT);

Serial.begin(9600);

radio.begin();

radio.openReadingPipe(1,pipe);

radio.startListening();

}

int on = 0;

unsigned long last = millis();

void loop()

{

if (radio.available())

{

bool done = false;

while (!done)

{

done = radio.read(DataMgs, 1);

//Serial.print(“NRF24L01 Receiver: “);

//Serial.println(DataMgs[0]);

if (DataMgs[0] == 1)

{

if (millis() – last > 250) {

on = !on;

//digitalWrite(led, on ? HIGH : LOW);

EEPROM.write(1, on ? 1 : 0);

}

last = millis();

}

if (DataMgs[0] == 2)

{

//——————————

laju = EEPROM.read(1);

if (laju==1){

digitalWrite(led, HIGH);

}

if (laju==0){

digitalWrite(led, LOW);

}

//——————————-

}

//delay(100);

}

}

else

{

//———————————–

laju = EEPROM.read(1);

if (laju==1){

digitalWrite(led, HIGH);

}

if (laju==0){

digitalWrite(led, LOW);

}

//———————————-

//Serial.println(“Waiting for signal…”);

}

}

 

 

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