Automatic balcony lighting on Arduino

About a couple of months ago I decided to captivate myself with electronics. In particular, I wanted to play with Arduino. But for pampering, it’s quite expensive to order the original one, so I climbed the well-known Chinese site on everything. There, at a discount, I found an Arduino Uno clone in the starter kit. He ordered it.

After about 3 weeks I received my “toy” and, probably, like everyone else, I began to indulge in blinking LEDs. This, of course, quickly tired, I wanted something more serious. There was an idea to automatically turn on / off the light on one of the balconies (I often smoke). Since uno is too “bold” for such a task, on the same site I ordered nano, motion sensors, textolite layouts, a power supply from 220V to 5V and a relay at a discount.

Another month passed ...

Parcels received




Need to try. At first, as it should, he assembled a scheme on a delirium board. Everything works, added a potentiometer to adjust the photosensitivity, fine.

I decided to collect the whole thing already on the board. As it turned out, the relay was made on a large board and did not fit on my breadboard, sawed it from the sides (there were no contacts / tracks there, fortunately). And also, to solder the relay unit directly to the board, it was necessary to solder the contacts to the other side. It turned out somehow like this:

File-modified relays
image

On the right it turned out a little uneven, as there was a path.

The most difficult, in my opinion, was to make tracks on the board. A thin copper wire, flux and tin helped me with this. It turned out pretty "clumsy", but, I repeat, this is my first experience, and I wanted to finish and try it out as soon as possible.

Tracks


Fortunately, everything fit on a 5x7 cm board, which is also good because the board has mounting holes, which I will use after making the case from plexiglass.

Work summary


The motion sensor deliberately did not make it fixed, since there is an idea to make it on the "horns" so that it would be possible to change its direction. Because I have not yet decided where the finished device will be attached.

I collected the program a little from any tutorials on sensors. In the instructions for the motion sensor, it was said that he should be allowed to tune in at the first start, from 10 to 30 seconds. I missed this moment, because I did not see its meaning at all. The device works exactly the same with and without it. The only difference is the time spent on calibration until initial readiness.

Sketch
int const Pot = A5;
int const Light = A7;
int const Relay = 3;
int const Move = 4;
int const pause = 180000; // 3 минуты мне как правило достаточно для перекура :)
long unsigned int lowIn;
boolean lockLow = true;
boolean takeLowTime;
void setup() {
  pinMode(Move, INPUT);
  pinMode(Relay, OUTPUT);
  digitalWrite(Relay, HIGH);
}
void loop() {
  int moveVal = digitalRead(Move);
  int lightVal = analogRead(Light);
  int potVal = analogRead(Pot);
  int lightLimit = map(potVal, 0, 1023, 500, 1000);
  if (moveVal == HIGH && lightVal < lightLimit) {
    if (lockLow) {
      lockLow = false;
      digitalWrite(Relay, LOW);
    }
    takeLowTime = true;
  } else {
    if (takeLowTime) {
      lowIn = millis();
      takeLowTime = false;
    }
    if (!lockLow && millis() - lowIn > pause) { 
      lockLow = true;               
      digitalWrite(Relay, HIGH);
    }
  }
}


The principle of operation is as follows: when motion is detected by the sensor, the reading of the photoresistor is compared with a threshold (necessary for the relay to operate), which is regulated by a potentiometer. If everything is satisfied, then the relay turns on for 3 minutes, after which, if the movement is not fixed, the relay is turned off.

I photographed the threshold values ​​by closing it with my finger and directing a flashlight at 2000 lumens at it.

Considering the New Year holidays, the daily arrivals of the guests, as well as the “overwhelming contribution” to the work of my colleague, it took 12-15 hours to complete the production.

Colleague


Please do not judge strictly. This is my first article and the first more or less serious experience with an arduino and a soldering iron. A constructive criticism is very welcome. Even, I would say, necessary.

Thank you for your time. I hope in the near future I will supplement the article with the final version of my device, in the case and with a demonstration of work.

PS
I would like to note my enthusiasm for the ordered power supply, with a power of 4 W it has dimensions of only 22x30x18 mm, and the price is only about 200 rubles.

PPS
All the work done is certainly much more expensive than the finished version from our Asian friends. But with their own hands - much more interesting.

Also popular now: