INFRARED SWITCH

infrared switch

The code can be downloaded at : https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Infra_red%20switch.zip

int OUTPUT_PIN = 3;

void setup() {

Serial.begin(9600);
pinMode(OUTPUT_PIN, OUTPUT);
}
int on = 0;
unsigned long last = millis();
void loop() {
long start = millis();
int sensorValue = analogRead(A0);

if (sensorValue < 500) {//this value can be adjusted for get desired sensitivity
//==============================
if (millis() – last > 250) {
on = !on;
analogWrite(OUTPUT_PIN, on ? 255 : 0);
//digitalWrite(OUTPUT_PIN, on ? HIGH : LOW); if do not want adjustable speed
}
last = millis();
//===================================================
}
Serial.println(sensorValue);
//delay(100);
}

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