Freelance, professional Arduino code writing.

For almost 3 years i have been working on a simple PIR led dimmer project. I have so many blue prints and electronic components bought with enthusiasm in the wardrobe...

Now I believe the dream is coming to reality!

If somebody could share his experience by writing a simple code for my need and asks for lets say 1 or 10 bucks( depending on the time consumption), i will be more than happy.

If we look from this professional person's view; there are millions of Arduino users. If 5 of them asks for this service it makes 25 bucks in a few hours.

in short it is ''win win'' situation.

is there such service in this world? If not can somebody do this?

Best Regards Sami

I'm sure there are people using this forum that is willing to 'get you started' State clearly your problem. make diagrams/drawings/sketches and tell what you wish for.

when PIR is high ==> led fade in via mosfet
when PIR is low ==> led fade out via mosfet
5 minutes will be operation time (if not triggered in 5 minutes)

sketch is attached. i just need the code…

i hope it is understandable

It this coorect understood: * When you enter the room, the light shall turn on (increasing..to 100% within 3 sec) * as long as there is movement detected.. stay lit

* when you leave (or fall asleep) the led shall turn off (decrease to 0 slowly.. for those outside to see)?

confirm?

Exactly!!!
i wish i had a code for this…

study this. there may be errors. test it…

/************************************************************
   Led dimmer using a logic lever MOSFET transitor
   Supply voltage is 12V / LED build for 12V, so no resistor is needed
   PIR-sensor power is fed from Arduino 5V / GND-pins. 
   PIR output to digital pin (D2) - polled
   PIR can be retriggable or non retriggable
   LED switches on when PIR detects movement
   LED output will stay 'ON' until 5 minutes of 'PIR silence'
   LED (Mosfet gate) MUST be connected to PWM pin. (D11)
   this code can be drastically redused on volume - made for readability
****************************************************************/   
// declare global constants 
const byte led = 11;         // connect to gate
const byte pir =  3;         // PIR signal out 
const byte turnOnTime = 5;   // turn on/off time in seconds !(will be forced:  50 > time > 0)
const byte minutesToOff = 5; // minutes of 'silence' before "lights out"
// declare global variables
boolean lightIsOn = false;   // remember LED-status 'now'
unsigned long timeToTurnOff; // time when led  will turn off
unsigned long timeNow;       // current time

// one time setup
void setup() 
{
  // set status og used I/O-pins
  pinMode(led,OUTPUT);
  pinMode(pir,INPUT);  
}
//********************************
// small functions and procedures - to make reading of main prog easier
boolean heWantsLightsOn()
{
  return (digitalRead(pir)==HIGH);  
}
//********************************
void turnLightsOn(byte period)
{
  // now the LED shall increase light intensity over "turnOnTime" seconds
  long delayTime = period * 5 ;
  for (byte i=40; i<255; i+=5) 
  {
    analogWrite(led,i);
    delay(delayTime);
  }
  digitalWrite(led,HIGH); // no PWM needed - turn on 100%
  lightIsOn=true;         // remember status
}
//**********************************
void turnLightsOff(byte period)
{
  // now the LED shall decrease light intensity - slowly to zero 
  long delayTime = period*5 ;
  for (byte i=250; i>40; i-=5) 
  {
    analogWrite(led,i);
    delay(delayTime);
  }
  digitalWrite(led,LOW); // no PWM needed - turn off
  lightIsOn=false;         // remember status
}
//**********************************

void loop() 
{
  timeNow=millis();  // note time now
  if (heWantsLightsOn()) // if movement -> be light! 
  {
    if (!lightIsOn) turnLightsOn(turnOnTime);   // if still dark - be light! (else light were on already)
    // set 'new' time for off -since you just told 'stay on for some mor minutes..)
    timeToTurnOff=timeNow + minutesToOff * 60000;  // set 'off-time' some minutes into the future (milliseconds used)
  }
  // now test for "Elvis  has left the building"
  if (timeNow > timeToTurnOff) // is it time to turn off ??
  {
    if (lightIsOn) turnLightsOff(turnOnTime);  // if light still are on: turn them off
  }
}
//***************END***********************

Be VERY sure your connections are correct! before applying 12V

Dear Knut,

Thank you very much for sharing this code.

i have tested it with a led on 11 pin and PIR on 3 however the led did not blink..

even if the ports switched from 11 to 13 and sensor on 2 there is no change. I will try with mosfet and share the result.

The output- pin MUST be a PWM-pin (to obtain incr/decr) Other pin will just turn ON /OFF (after a short delay)

Try connect 5V to the pir-input-pin. I'm sure this will work at last!

This code works but it does not fade in and out effect. it just blinks 2 seconds.
Pictures of connections are attached as photos.

const int ledPin= 11;
const int inputPin= 3;

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

void loop(){
int value= digitalRead(inputPin); if (value == HIGH)

{
digitalWrite(ledPin, HIGH);
delay(500); digitalWrite(ledPin, LOW);
}
}

I tested with the onboard led (pin13), and it seems to work correct
I have altered to run incr/decr at a slower pace.
If you got a digital level MOSFET this whould work just fine.

Copy code - test run !

/************************************************************
   Led dimmer using a logic lever MOSFET transitor
   Supply voltage is 12V / LED build for 12V, so no resistor is needed
   PIR-sensor power is fed from Arduino 5V / GND-pins. 
   PIR output to digital pin (D2) - polled
   PIR can be retriggable or non retriggable
   LED switches on when PIR detects movement
   LED output will stay 'ON' until 5 minutes of 'PIR silence'
   LED (Mosfet gate) MUST be connected to PWM pin. (D11)
   this code can be drastically redused on volume - made for readability
****************************************************************/   
// declare global constants 
const byte led = 11;         // connect to gate
const byte pir =  3;         // PIR signal out 
const byte turnOnTime = 5;   // turn on/off time in seconds !(will be forced:  50 > time > 0)
const byte minutesToOff = 1; // minutes of 'silence' before "lights out" !! ALTER THIS VALUE
const boolean debug=false;
// declare global variables
boolean lightIsOn = false;   // remember LED-status 'now'
unsigned long timeToTurnOff; // time when led  will turn off
unsigned long timeNow;       // current time


// one time setup
void setup() 
{
  // set status og used I/O-pins
  pinMode(led,OUTPUT);
  pinMode(pir,INPUT);  
}
//********************************
// small functions and procedures - to make reading of main prog easier
boolean heWantsLightsOn()
{
  return (digitalRead(pir)==HIGH);  
}
//********************************
void turnLightsOn(byte period)
{
  // now the LED shall increase light intensity over "turnOnTime" seconds
  long delayTime = period * 5 ;
  for (byte i=40; i<255; i++) 
  {
    analogWrite(led,i);
    delay(delayTime);
  }
  digitalWrite(led,HIGH); // no PWM needed - turn on 100%
  lightIsOn=true;         // remember status
}
//**********************************
void turnLightsOff(byte period)
{
  // now the LED shall decrease light intensity - slowly to zero 
  long delayTime = period*5 ;
  for (byte i=254; i>40; i--) 
  {
    analogWrite(led,i);
    delay(delayTime);
  }
  digitalWrite(led,LOW); // no PWM needed - turn off
  lightIsOn=false;         // remember status
}
//**********************************

void loop() 
{
  timeNow=millis();  // note time now
  if (heWantsLightsOn()) // if movement -> be light! 
  {  
    if (!lightIsOn) turnLightsOn(turnOnTime);   // if still dark - be light! (else light were on already)
    // set 'new' time for off -since you just told 'stay on for some mor minutes..)
    timeToTurnOff=timeNow + minutesToOff * 60000;  // set 'off-time' some minutes into the future (milliseconds used)
    if (debug) Serial.println("renew for one minute");
  }
  // now test for "Elvis  has left the building"
  if (timeNow > timeToTurnOff) // is it time to turn off ??
  {
    if (lightIsOn) turnLightsOff(turnOnTime);  // if light still are on: turn them off
  }
}
//***************END***********************

..quiet... time to change title to "solved" ??

Dear Knut,

THANK YOU VERY MUCH!!!!!

you have solved the problem that i have been struggling for years...

I wish that i had a chance to return a favour to you...

Let me know from PM any time...

Best Regards Sami

There is still one thing to be done.. .> if your in the room, sitting still and the lights start dimming then they will turn off completle. You cannon stop this by moving.

Change to be made..(in the "turn.off" procedure): Test for movement and stop dimming -> increase to 100% You take the challange?

wow! you are a very good teacher.

let me give you status report before accepting new challenge. So far all fade in out time and speed trimmed.

when we enter in to the dark kitchen we need light immediately so fade in time shortened. and it is nice thing to see lights fade out. so fade out time lengthened.

new challenges that planed for this project are;

test for movement and stop dimming. I thing this is about callibrating sensors and adding new if conditions which i do not have any idea. there may be need to change sensors from modules to raw components.

second and less challenging plan is to control multiple leds with multiple fade in time. (pin, 11,13...)

in 1 year i plan to carry this project to a new platform by controlling RGB lighs as soon as there is enough experience gained.

.yes i take the challenge, please give me homeworks :)

P.S Another thing that keeps my mind occupied is how to thank you. If you could give me your post adress from PM i will send you some Turkish Delight and some souvenirs. Also you are very welcome if you visit Turkey....

Best Regards Sami

I guess the potensial problem of "no activity" may not apply to a kitchen, so maybe not needes to do changes. You already can see that you understand how the code works. Be creative! Almost anything is posible. Good luck!

THANK YOU :)

Give a big hug to your girlfriend from me! This is my hobby in addition to my profession as a teacher.

Hello you guys

I have a project like this, but light in a toolcabin. I have a bit of code going on but it needs to be debugged. I saw this and wanted to use this instead and some other features... Hope it's ok??

..its public! - give it away, dont sell it.