Author Topic: Arduino and LDR  (Read 1381 times)

0 Members and 1 Guest are viewing this topic.

Online mike_mikeTopic starter

  • Frequent Contributor
  • **
  • Posts: 900
  • Country: ro
Arduino and LDR
« on: April 27, 2018, 08:34:11 pm »
Hello,

I want to make a project using Arduino. The project will light up a few LEDs when the night will come.
The schematic and the code are attached.
1. Is the schematic correct ?
2. Is the code correct ?
3. If I want to use in the place of the led and the series resistor a 2A load, are there any modifications that I should make in the circuit ?
4. Is there any need to implement an hysterezis ?
I tested the circuit on a bread board and it works.
 

Offline Signal32

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: us
Re: Arduino and LDR
« Reply #1 on: April 28, 2018, 04:21:16 am »
Code & schematic seems that they would work.
Suggestions:
- You don't really need Q1 since the MOSFET has a VGS(TH) of max 4v - under the 5v of your arduino.
- You want to implement logic to avoid flickering - Imagine that the readings for the cell are 399 400 398 401 398 400 401 etc either because of noise or because your light is indirectly illuminating your sensor. So implement something like if < 350 turn_off if > 450 turn_on, etc ...
- Also code could be written nicer but you probably don't care :).

This would (probably) work for 2A too, but I would get a better MOSFTET for that - IRF630 will end up dissipating 2W because of the 0.5R RDS(ON).
The probably is because of hopefully the 2A load doesn't share ground with the 12V power supply.
« Last Edit: April 28, 2018, 04:23:14 am by Signal32 »
 

Offline JS

  • Frequent Contributor
  • **
  • Posts: 947
  • Country: ar
Re: Arduino and LDR
« Reply #2 on: April 28, 2018, 04:30:18 am »
You could use an IRF540 for this, I think the BJT is a good idea as the mosfet at 5ish volts might not be completly on at higher currents.

The thing here is that you don't need an arduino, just with a comparator you are good to go, still can implement the hysteresis Signal32 suggested, just one more resistor to it, and then you can miss the transistor with no problem and the entire 5V supply as you can run the comparator on the 12V directly.

Maybe you are just trying to get something useful done with the Arduino so go for it.

JS
If I don't know how it works, I prefer not to turn it on.
 

Online mike_mikeTopic starter

  • Frequent Contributor
  • **
  • Posts: 900
  • Country: ro
Re: Arduino and LDR
« Reply #3 on: May 01, 2018, 06:56:03 pm »
What will happen if the initial value read from the LDR will be between 400 and 500 ?

I made some tests and when the value read from the LDR is between 400 and 500 (I suppose) when I power up Arduino, the led_night (the led which will notify that the mosfet is ON) is off and the load (output_fet) is on, and the load is powered up. Can this problem be solved ? I used as load a 20W/12V light bulb, powered from an 12V 3A power supply.
If I power up Arduino with the LDR in direct light the load remains off and the led_night remains also off.
If I power up Arduino with the LDR in darkness, the load is powered and the led_night is lighting.
1. This problem will appear only when I power up Arduino ?

2. Is there any possibility to solve this problem ?
« Last Edit: May 01, 2018, 07:40:15 pm by mike_mike »
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: Arduino and LDR
« Reply #4 on: May 02, 2018, 07:53:26 pm »
Hi,

Try putting a 100nf capacitor across R2 and adding a 1 second delay in the Setup part of your code.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf