How to make an IR toggle switch

Hello, today I will show you how to make an IR toggle switch with Arduino and a Mosfet, it has far more detection range than capacitive touch device and easy to build. The circuit is easy to use and use minimal components to make a job done, now let's start

Components list:
R1 = 100 ohms resistor
R2 = 470 Kilo-ohms resistor
R3 = 10 Kilo-ohms resistor
R4 =1000 ohms or 1 kilo-ohms
IR1 = infrared led
IRR1 = infrared receiver
led = low forward voltage led, you can find it on any electronic part store
Tube1 =Shrink tubing
1 x irf9540n p-type Mosfet

If you have the components I list ready, it's time to upload this code to your Arduino UNO r3

/* switch
 * Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
 * press), the output pin is toggled from LOW to HIGH or HIGH to LOW.  There's
 * a minimum delay between toggles to debounce the circuit (i.e. to ignore
 * noise).  
 * David A. Mellis
 * 21 November 2006
* little edit by
*16 January 2018

int inPin = 2;         // the number of the input pin
int outPin = 13;       // the number of the output pin

int state = LOW;      // the current state of the output pin *change it from high to low because the circuit turn on when connecting to a power supply
int reading;           // the current reading from the input pin
int previous = HIGH;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup()
  pinMode(inPin, INPUT);
  pinMode(outPin, OUTPUT);

void loop()
  reading = digitalRead(inPin);

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
      state = HIGH;

    time = millis();    

  digitalWrite(outPin, state);

  previous = reading;

Now let's make the project done by watching it in my video


Popular posts from this blog

How to add power supply filter capacitor to amplifier board.

How to connect volume control to an amplifier

PAM 8403 board amp wiring diagram

5 watts amplifier TDA7056A wiring diagram

10 watts 8 ohms class d amplifier pam8610 sound test

tda 7052B full wiring diagram, easy to understand

15 watts stereo class T amplifier TA2024 sound test and review

Hall effect sensor wiring diagram and test video

simple bass booster circuit diagram