<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Using a PIR with LED Effects - Arduino				            </title>
            <link>https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Tue, 21 Jul 2026 01:34:14 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: Using a PIR with LED Effects</title>
                        <link>https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-3293</link>
                        <pubDate>Fri, 26 Mar 2021 11:14:49 +0000</pubDate>
                        <description><![CDATA[Hi Sébastien!
Oh wow, that looks really good! Well done! (and: thank you for sharing the pictures of your project). 👍 
Glad I could be of some help 😊]]></description>
                        <content:encoded><![CDATA[<p>Hi Sébastien!</p>
<p>Oh wow, that looks really good! Well done! (and: thank you for sharing the pictures of your project). 👍 </p>
<p>Glad I could be of some help 😊 </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-3293</guid>
                    </item>
				                    <item>
                        <title>RE: Using a PIR with LED Effects</title>
                        <link>https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-3292</link>
                        <pubDate>Thu, 25 Mar 2021 21:45:23 +0000</pubDate>
                        <description><![CDATA[@hans
Hello Hans,
 
Finally I am done with this smart infinite mirror project. Here is the final result.

 

The 2 PIR sensors are hidden in the eyes of the skull.

 
And here is t...]]></description>
                        <content:encoded><![CDATA[<p>@hans</p>
<p>Hello Hans,</p>
<p> </p>
<p>Finally I am done with this smart infinite mirror project. Here is the final result.</p>
185
<p> </p>
188
<p>The 2 PIR sensors are hidden in the eyes of the skull.</p>
186
<p> </p>
<p>And here is the effect in video.</p>
<p><a title="Smart Infinite Mirror" href="https://youtu.be/_5rBd6ZD6o8" target="true">Smart Infinite Mirror</a></p>
<p>I have two Arduino Nanos, one for the LEDs of the infinite mirror and one for the LEDs on the sides of the frame, and I added also two tactile buttons to change the effects on the LEDs. The two Arduinos are connected to the same PIR sensor, the other PIR sensor is connected to the Raspberry Pi.</p>
<p>I let all the effect, but the Halloween Eyes effect which was not giving something good.</p>
<p> </p>
<p>Again, thanks a lot for your help. 👍</p>
<p> </p>
<p>Sébastien</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>deadman45</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-3292</guid>
                    </item>
				                    <item>
                        <title>RE: Using a PIR with LED Effects</title>
                        <link>https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2988</link>
                        <pubDate>Wed, 06 Jan 2021 20:57:59 +0000</pubDate>
                        <description><![CDATA[Posted by: @deadman45 
it is ok now

Awesome!! 
Glad it worked out!Please feel free to post your project code/pictures/video when done (if you&#039;d like to) 😊]]></description>
                        <content:encoded><![CDATA[<blockquote data-userid="4523" data-postid="2987" data-mention="deadman45">
<div class="wpforo-post-quote-author"><strong> Posted by: @deadman45 </strong></div>
<p>it is ok now</p>
</blockquote>
<p>Awesome!! </p>
<p>Glad it worked out!<br />Please feel free to post your project code/pictures/video when done (if you'd like to) 😊 </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2988</guid>
                    </item>
				                    <item>
                        <title>RE: Using a PIR with LED Effects</title>
                        <link>https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2987</link>
                        <pubDate>Wed, 06 Jan 2021 20:13:41 +0000</pubDate>
                        <description><![CDATA[@hans
Hi,
 
Thank you, it works fine now. I think it was an accolade issue. I did not figure out which one exactly, but it is ok now.
And the time code above is working fine too.
 
Now...]]></description>
                        <content:encoded><![CDATA[<p>@hans</p>
<p>Hi,</p>
<p> </p>
<p>Thank you, it works fine now. I think it was an accolade issue. I did not figure out which one exactly, but it is ok now.</p>
<p>And the time code above is working fine too.</p>
<p> </p>
<p>Now I "just" have to build the frame of the mirror...</p>
<p> </p>
<p>Again thanks a lot for everything. You save my project. 👍 </p>
<p> </p>
<p>Sébastien</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>deadman45</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2987</guid>
                    </item>
				                    <item>
                        <title>RE: Using a PIR with LED Effects</title>
                        <link>https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2986</link>
                        <pubDate>Wed, 06 Jan 2021 12:13:26 +0000</pubDate>
                        <description><![CDATA[Coming to your other question;

 Posted by: @hans 
Just another question, how can I manage the time that the LEDs are ON? I have two types of PIR sensor, one with the delay and sensitivit...]]></description>
                        <content:encoded><![CDATA[<p>Coming to your other question;</p>
<blockquote data-userid="1" data-postid="2984" data-mention="hans">
<div class="wpforo-post-quote-author"><strong> Posted by: @hans </strong></div>
<p>Just another question, how can I manage the time that the LEDs are ON? I have two types of PIR sensor, one with the delay and sensitivity screws <a href="https://www.conrad.ch/fr/p/makerfactory-mf-6402129-detecteur-de-mouvements-pir-2134043.html#productHighlights" target="_blank" rel="nofollow noopener ugc">like this</a> (but to find the right time is quite annoying) and one without those screws <a href="https://www.conrad.ch/fr/p/detecteur-de-mouvement-joy-it-sbc-pir-convient-pour-arduino-raspberry-pi-micro-bit-1-pc-s-2306360.html" target="_blank" rel="nofollow noopener ugc">like this</a> but it stays ON only some seconds. I tried to add a delay(), like when I had only one LED, but now the delay was acting on the effect itself (like turning one LED ON every 10 seconds, which is not making the fire effect as cool as before).</p>
</blockquote>
<p>Using delay is probably not the best option as it "locks" the code for that timeframe, and triggering an interrupt would break that as well.</p>
<p>I would actually use a method where we keep the effect going for a certain time after the PIR went to LOW.<br />So we set a variable to the time, each time when the PIR was last HIGH.<br />If the current time minus the stored time is less than x seconds, we keep the effect going.</p>
<p>Caution: when using interrupts the way I did in the LED Effects, the "reset" may actually reset the millis() value as well!<br />Unfortunately, an Arduino does not have a real time clock (RTC) build in. Just a timer that starts "ticking" when the Arduino starts.</p>
<p>Something like this:</p>
<pre><span style="color: #ff0000">#define PIRdelay 10000 // milliseconds, so 10000 = 10 seconds</span><br /><span style="color: #ff0000">unsigned long PIRtriggerTime = 0;</span><br /><br />...<br /><br />void loop() { <br />  pirStatus = digitalRead(pirPin);<br /><span style="color: #ff0000">  if( pirStatus == HIGH) </span><br /><span style="color: #ff0000">  {</span><br /><span style="color: #ff0000">    PIRtriggerTime = millis();</span><br /><span style="color: #ff0000">  }</span><br /><br /><span style="color: #ff0000">  if( millis() - PIRtriggerTime &lt; PIRdelay)</span><br />  {<br />    EEPROM.get(0,selectedEffect); <br />    if(selectedEffect&gt;18) <br />    {  <br />      selectedEffect=0;<br />      EEPROM.put(0,0); <br />    } // if selected<br /><br />  switch(selectedEffect) <br />  {<br />    ...</pre>
<p>So, whenever the PIR is HIGH, we set PIRtriggerTime to the current millis value (runtime since Arduino started).<br />If the current time, minus the time the PIR was last triggered, is smaller than the desired delay (PIRdelay) then show the effect.<br />Else (Current Time - PIR last triggered &gt; desired delay) show a black LED strip. </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2986</guid>
                    </item>
				                    <item>
                        <title>RE: Using a PIR with LED Effects</title>
                        <link>https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2985</link>
                        <pubDate>Wed, 06 Jan 2021 11:55:40 +0000</pubDate>
                        <description><![CDATA[Hi Sébastien!

 Posted by: @hans 
error messages like “changeEffect’ was not declared in this scope”

This error quite often indicates that you have either a big chunk of code missing, ...]]></description>
                        <content:encoded><![CDATA[<p>Hi Sébastien!</p>
<blockquote data-userid="1" data-postid="2984" data-mention="hans">
<div class="wpforo-post-quote-author"><strong> Posted by: @hans </strong></div>
<p>error messages like “changeEffect’ was not declared in this scope”</p>
</blockquote>
<p>This error quite often indicates that you have either a big chunk of code missing, or unbalanced accolades.<br />This can make a piece of code become invisible or in the wrong scope (missing a "}" would include this in the wrong function).</p>
<p>The unbalanced accolades can be easiest found by marking what the end-accolade ( } ) belongs to, something like the code below (example marked blue).<br />The unbalanced accolades can also be detected when formatting code, this is why I often place the opening accolade ( { ) on a new line, so that the closing accolade will be at a visually similar position (example marked red). </p>
<pre>void loop() { 
  pirStatus = digitalRead(pirPin);
  if(pirStatus == HIGH) <br />  {<br />
    EEPROM.get(0,selectedEffect); 
    if(selectedEffect&gt;18) <br />    <span style="color: #ff0000"><strong>{</strong></span> 
      selectedEffect=0;
      EEPROM.put(0,0); 
    <span style="color: #ff0000"><strong>}</strong></span> <span style="color: #0000ff">// if selected</span>

    switch(selectedEffect) <br />    {

    ...

    case 18 : {
                // meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay 
                meteorRain(0xff,0xff,0xff,10, 64, true, 30);
                break;
               } <span style="color: #0000ff">// case 18</span>
    } <span style="color: #0000ff">// switch</span>
<br />  } <span style="color: #0000ff">// if pirStatus</span>
  else
  {
    strip.clear();
    strip.show();
  } <span style="color: #0000ff">// else if pirStatus</span>
}</pre>
<p>From what I can see, the void loop() code seems OK. However since not all the code is listed here, it may still contain an accolade issue. </p>
<p>What could also be the case, is that the code after void loop() is missing. See if the changeEffect function exists in your code:</p>
<pre>void changeEffect() {
  if (digitalRead (BUTTON) == HIGH) {
    selectedEffect++;
    EEPROM.put(0, selectedEffect);
    asm volatile ("  jmp 0");
  }
}</pre>
<p> Feel free to post the full code here (ideally as an attachment since the forum seems to screw up code segments that have a "&lt;" in it, placing a space after all "&lt;" symbols will fix this).</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2985</guid>
                    </item>
				                    <item>
                        <title>RE: Using a PIR with LED Effects</title>
                        <link>https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2984</link>
                        <pubDate>Wed, 06 Jan 2021 11:44:24 +0000</pubDate>
                        <description><![CDATA[From Sébastien&#039;s post;
 
I tried the add the code above using the FastLED library and all the effect with the button, but I had some error messages like “changeEffect’ was not declared in ...]]></description>
                        <content:encoded><![CDATA[<p>From Sébastien's post;</p>
<p> </p>
<p>I tried the add the code above using the FastLED library and all the effect with the button, but I had some error messages like “changeEffect’ was not declared in this scope”, but it was working before I added the PIR code… <img class="t4a_smiley" src="https://www.tweaking4all.com/wp-content/themes/tweaking4all/css/images/emoticons/t4a_thinking.png" alt="" /></p>
<p>You said that FastLED was better than Adafruit_Neopixel, so I would like to have the Fast_LED working, but I found a way to add the PIR in the Neopixel code and it seems to work.</p>
<p>(Code moved to<span> </span><a href="https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/" target="_blank" rel="noopener">this forum post</a>)</p>
<p><span>At least with this method, it seems to works even if I don’t really know what I did. <img class="t4a_smiley" src="https://www.tweaking4all.com/wp-content/themes/tweaking4all/css/images/emoticons/t4a_wink.png" alt="" /></span></p>
<p><span>I will still dig to make the FastLED working.</span></p>
<p><span>Just another question, how can I manage the time that the LEDs are ON? I have two types of PIR sensor, one with the delay and sensitivity screws <a href="https://www.conrad.ch/fr/p/makerfactory-mf-6402129-detecteur-de-mouvements-pir-2134043.html#productHighlights" target="_blank" rel="nofollow noopener ugc">like this</a> (but to find the right time is quite annoying) and one without those screws <a href="https://www.conrad.ch/fr/p/detecteur-de-mouvement-joy-it-sbc-pir-convient-pour-arduino-raspberry-pi-micro-bit-1-pc-s-2306360.html" target="_blank" rel="nofollow noopener ugc">like this</a> but it stays ON only some seconds. I tried to add a delay(), like when I had only one LED, but now the delay was acting on the effect itself (like turning one LED ON every 10 seconds, which is not making the fire effect as cool as before).</span></p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2984</guid>
                    </item>
				                    <item>
                        <title>Using a PIR with LED Effects</title>
                        <link>https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2983</link>
                        <pubDate>Wed, 06 Jan 2021 11:42:36 +0000</pubDate>
                        <description><![CDATA[This is a continuation of the questions Sébastien had under the LED Effects article;
...
#define BUTTON 2
byte selectedEffect=0;

int pirPin = 4; //PIR Out pin
int pirStatus = 0; // PI...]]></description>
                        <content:encoded><![CDATA[<p>This is a continuation of the <a href="https://www.tweaking4all.com/hardware/arduino/arduino-all-ledstrip-effects-in-one/#comment-528546" target="true">questions </a><span><a href="https://www.tweaking4all.com/hardware/arduino/arduino-all-ledstrip-effects-in-one/#comment-528546" target="true">Sébastien</a> had under the LED Effects article;</span></p>
<pre>...
#define BUTTON 2
byte selectedEffect=0;

int pirPin = 4; //PIR Out pin
int pirStatus = 0; // PIR Status

void setup()
{
  pinMode(pirPin, INPUT);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  pinMode(2,INPUT_PULLUP);  // internal pull-up resistor
  attachInterrupt (digitalPinToInterrupt (BUTTON), changeEffect, CHANGE); // pressed
}
// *** REPLACE FROM HERE ***
void loop() { 
  pirStatus = digitalRead(pirPin);
  if(pirStatus == HIGH) {
  EEPROM.get(0,selectedEffect); 
 if(selectedEffect&gt;18) { 
    selectedEffect=0;
    EEPROM.put(0,0); 
    }

switch(selectedEffect) {

...

case 18 : {
                // meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay 
                meteorRain(0xff,0xff,0xff,10, 64, true, 30);
                break;
              }
  }
  }
  else
  {
   strip.clear();
   strip.show();
     }
}</pre>
<p> </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/using-a-pir-with-led-effects/#post-2983</guid>
                    </item>
							        </channel>
        </rss>
		