[Lab] PIR, IRF540, PN2222, LED Strip, Arduino

Bruce Harding bsharding at rogers.com
Sat Mar 17 15:10:15 EDT 2018


Hello,

I'm trying to get the pinning right for a project where a PIR triggers a
LED strip to turn on.  I'm having real trouble getting the pinning on the
breadboard right. If someone is willing to take a look at it I'd be
grateful. Beer or coffee on me.

I'm using:

12v 3A power supply
PIR
IRF540 Mosfet
PN2222 Transistor
1m Warm/White LED Strip
Arduino Uno


Code:

//constants
const int ledPin = 5;
const int sensorPin = 4;
const long stayOnPeriod = 900;   // length of time to stay on (in
milliseconds)

//variables
unsigned long turnOffTime = millis();  //Start with the led turned off

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
}

void loop() {
  // check if the sensor is detecting then increase the time to stay on.
  if (digitalRead(sensorPin) == HIGH)
  {
    turnOffTime = millis() + stayOnPeriod;
  }

  if (turnOffTime > millis())
  {
    digitalWrite(ledPin, HIGH);
  }
  else
  {
    digitalWrite(ledPin, LOW);
  }
}


-- 
====
bruce
faintfuzzies.ca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://artengine.ca/pipermail/lab/attachments/20180317/48e320c7/attachment.html>


More information about the Lab mailing list