Controle de Luminosidade (LDR+LEDS)

ARDUINO –  Controle de Luminosidade (LDR+LEDS)

Através deste artigo estarei disponibilizando informações sobre como funciona o LDR e algumas técnicas de programação de como efetuar o controle de luminosidade.



Equipamento necessário:

  • 1 LDR de 10mm, 7mm ou 5mm.
  • 1 resistor de 10k de qualquer potência (1/16W,1/8W,1/4W).
  • 1 Arduino ou similar.
  • 1 cabo USB AB.

Funcionamento do LDR:

Figura 1: Foto do LDR.

O LDR é um resistor que varia sua resistência elétrica conforme a luminosidade. Ao aumentar a luminosidade incidente na superfície do LDR a resistência elétrica diminui, então quanto menor luminosidade maior a resistência. Tipicamente sem nenhuma luminosidade tem-se 4M enquanto com alta luminosidade tem-se 100.

 Figura 2: Esquema da Ligação do LDR com o Arduino. (R2 = 10k, R1 é o LDR)

Então, para o Arduino poder efetuar a leitura da luminosidade é utilizado um resistor em série para, na verdade, ler tensão pela entrada analógica.

Figura 3: Ligação do Arduino com o LDR.

Desta forma, quando houver variação de luminosidade a porta analógica irá ler a variação de tensão. Observando o desenho abaixo (com o programa Fritz) é feita a ligação como no esquema acima, o LDR se conecta ao 5V ao resistor e a porta analógica enquanto o resistor é conectado ao LDR, a porta analógica e ao terra.

Quando a luminosidade for alta, a tensão que vai para o pino analógico será muito próxima de 5V resultando em um número inteiro próximo de 1023 com a função analogRead(Pin). Quando estiver em baixa luminosidade será retornado um número próximo de 0 com a mesma função acima.


Como iremos ler o nível de tensão com a porta analógica, iremos utilizar a função analogRead(Pin), Além disso será utilizada a comunicação com o computador para ler o inteiro que representa a luminosidade.

Utilizando o código abaixo e fazendo o Upload:

/* Inovabots – Controle de Luminosidade */

int PinoLeitura = A0; // Escolhendo o pino analógico A0

int Luminosidade;

void setup()


//Não há necessidade de declarar o pino analógico



void loop()


//LeituraPot recebe o valor do pino A0.

Luminosidade = analogRead(PinoLeitura);

//Envia Leitura para PC.

Serial.println(“Leitura Luminosidade (0 a 1023):”);






Como no vídeo abaixo, quando incide luminosidade a leitura chega a valores altos (aprox. 970) e quando tampamos o sensor, chega-se a valores em torno de 90.

Com isso, podemos incluir condições para que de acordo com luminosidades se faça uma ação que pode ser acender LEDs.

OBS: Para observar uma passagem de valores mais rapidamente basta reduzir o delay para um número menor (lembrar que a função delay é em ms).



Após a realização da leitura de nível de luminosidade, é possível acrescentar condições (na programação) e montar alguns LEDs de forma a acender conforme a luminosidade.


  • Itens da Parte I
  • 4 LEDs.
  • 4 resistores de 220R 1/8W.   (Pode-se utilizar resistência maior, a potência também pode ser maior).
Então, fazendo a ligação do Arduino aos LEDs como na figura abaixo:
Figura 4: Ligação do Arduino ao LDR  e aos LEDs.
Assim, o circuito fica parecido com o abaixo (note que o Arduino utilizado na figura abaixo é o Arduino MEGA, porém a ligação e a programação são específicos para o Arduino UNO).
Figura 5: Foto da ligação do circuito real.

Depois de conectar corretamente os componentes pode-se iniciar a programação.


A programação da parte II é parecida com a parte I, a única diferença é que vai se existir condições para se ligar ou desligar o LED de acordo com a luminosidade.

Como a leitura da luminosidade varia entre 0 a 1023 as condições irão estar dentro desses valores possíveis, por exemplo:

  if ( Luminosidade < 840 )

Quando o valor lido for menor que 840 o LED 4 irá acender e quando for maior que esse valor, irá apagar.

Abaixo temos o código completo da ligação:

/* Inovabots - Controle de Luminosidade */
int PinoLeitura = A0;    // Escolhendo o pino analógico A0
int Luminosidade;

void setup() {
  //Não há necessidade de declarar o pino analógico 
  pinMode (4,OUTPUT);
  pinMode (5,OUTPUT);
  pinMode (6,OUTPUT);

void loop() {
  //LeituraPot recebe o valor do pino A0.
  Luminosidade = analogRead(PinoLeitura);
  //Envia Leitura para PC.  
  Serial.println("Leitura Luminosidade (0 a 1023):");
  if ( Luminosidade < 840 )
  if ( Luminosidade < 700 )
  if ( Luminosidade < 500 )

Ao compilar e dar upload no código, o resultado será como no vídeo abaixo:



O resultado é bem interessante, vários testes podem ser feitos com a luminosidade: com as cortinas do ambiente se fechando, apagando as luzes. Com certeza ao decorrer do dia os LEDs irão acendendo automaticamente.

*Nota, cuidado para a luz do LED não incidir no LDR, isso iria fazer o LED ficar piscando. O motivo é que quando existe diminuição de luminosidade o LED acende, e se o LED acender e incidir no LDR o Arduino vai mandar apagar o LED por conta que a luminosidade aumentou, quando o LED apagar o sistema vai detectar diminuição de luminosidade voltando ao estado inicial. Isto causa um ciclo indefinido e o LED fica oscilando.

Autor: Gabriel Liberalquino S. Lima

var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-26816794-1′]);

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript'; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl&#8217; : ‘http://www&#8217;) + ‘';
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);

Tags: Controle – Luminosidade – Monitoramento – LDR – Arduino – LED – Interação

77 responses to “Controle de Luminosidade (LDR+LEDS)

  1. Hey, you used to write great, but the last several posts have been kinda boring… I miss your great writings. Past several posts are just a little bit out of track! come on!”To be content with what one has is the greatest and truest of riches.” by Cicero.

  2. You can certainly see your expertise within the work you write. The world hopes for more passionate writers such as you who aren’t afraid to say how they believe. At all times follow your heart. “We are near waking when we dream we are dreaming.” by Friedrich von Hardenberg Novalis.

  3. Thank you, I’ve recently been looking for info approximately this subject for ages and yours is the greatest I have found out till now. But, what about the conclusion? Are you sure about the supply?

  4. Hello, you used to write wonderful, but the last few posts have been kinda boring… I miss your tremendous writings. Past several posts are just a little bit out of track! come on!

  5. I was curious if you ever thought of changing the structure of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two pictures. Maybe you could space it out better?

  6. Excellent read, I just passed this onto a friend who was doing some research on that. And he just bought me lunch because I found it for him smile Thus let me rephrase that: Thank you for lunch! “Life is a continual upgrade.” by J. Mark Wallace.

  7. I’ll immediately seize your rss as I can not to find your email subscription hyperlink or newsletter service. Do you’ve any? Please permit me know in order that I may just subscribe. Thanks.

  8. Many thanks for an incredible publish, can study your others reviews. many thanks for your ideas on this, I experienced a bit thump by this article. Thanks again again! You commit an excellent time. Displays the beauty through fantastic facts here. I feel that when more individuals thought about it doing this, they’d possess a better time frame get the suspend ofing the situation. http://www.trbxjeur.nkd

  9. Very interesting details you have remarked, regards for posting . “Death is Nature’s expert advice to get plenty of Life.” by Johann Wolfgang von Goethe.

  10. Thanks for an incredible submit, can study your others content. thanks for your thinking within this, I experienced a bit strike by this text. Thanks again again! You make an excellent time. Portrays natures best by the fantastic data here. I think if a greater number thought of it like that, they’d have a very better time period have the suspend ofing the matter.

  11. Oh my goodness! an amazing article dude. Thank you However I am experiencing issue with ur rss . Don’t know why Unable to subscribe to it. Is there anyone getting identical rss problem? Anyone who knows kindly respond. Thanks

    • acctually it is happening, I’ll look for it, But if anyone knows I’ll be glad to have the information!

  12. Have you given any kind of thought at all with converting your current site into Chinese? I know a few of translaters right here that might help you do it for free if you want to get in touch with me personally.

  13. Hi there I am so happy I found your blog, I really found you by accident, while I was searching on Google for something else, Nonetheless I am here now and would just like to say many thanks for a marvelous post and a all round exciting blog (I also love the theme/design), I don’t have time to look over it all at the moment but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read more, Please do keep up the fantastic work.

  14. Today, I went to the beach with my kids. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is completely off topic but I had to tell someone!

  15. Thanks for the great post! I quite loved reading it, you are an amazing writer. I’m going to always take a note of your webpage and will eventually revisit in the foreseeable future.

  16. I just want to mention I am just very new to blogging and actually savored you’re website. Probably I’m likely to bookmark your blog . You surely have excellent writings. Thanks for revealing your web page.

  17. Good article and straight to the point. I don’t know if this is really the best place to ask but do you guys have any ideea where to hire some professional writers? Thank you :)

  18. I would like to consider the ability of thanking you for the expert advice I have often enjoyed going to your web site. I will probably be seeking forward to the actual commencement of my college research and the general prep would never have been complete without coming to your internet site. If I could be of any help to other people, I would be glad to assist by means of what I have gained from here. Kosova Airlines

  19. Simply want to say your article is as amazing. The clearness in your post is just excellent and i could assume you are an expert on this subject. Well with your permission allow me to grab your feed to keep updated with forthcoming post. Thanks a million and please continue the gratifying work.

  20. You are my breathing in, I possess few blogs and occasionally run out from brand :). “Follow your inclinations with due regard to the policeman round the corner.” by W. Somerset Maugham.

  21. I like this blog very much, Its a very nice berth to read and obtain info. “I ran the wrong kind of business, but I did it with integrity.” by Sydney Biddle Barrows.

  22. Hi there! This post could not be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this post to him. Pretty sure he will have a good read. Thank you for sharing!

  23. Pretty section of content. I just stumbled upon your site and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I’ll be subscribing to your feeds and even I achievement you access consistently fast.

  24. Excellent read, I just passed this onto a friend who was doing some research on that. And he actually bought me lunch as I found it for him smile So let me rephrase that: Thank you for lunch!

  25. Hello there! This is my 1st comment here so I just wanted to give a quick shout out and tell you I truly enjoy reading your articles. Can you recommend any other blogs/websites/forums that cover the same topics? Thank you so much!

  26. I have to express some thanks to the writer for rescuing me from this type of dilemma. Right after exploring through the internet and seeing basics which were not beneficial, I figured my entire life was well over. Being alive without the answers to the difficulties you have fixed by way of the blog post is a crucial case, and the kind which could have in a wrong way affected my entire career if I had not encountered your blog post. Your own personal know-how and kindness in playing with all the details was priceless. I’m not sure what I would have done if I hadn’t discovered such a stuff like this. I am able to at this point look forward to my future. Thank you so much for your professional and sensible help. I won’t hesitate to suggest your web blog to any individual who needs and wants tips on this subject.

  27. Thanks for the sensible critique. Me and my neighbor were just preparing to do some research about this. We got a grab a book from our local library but I think I learned more clear from this post. I’m very glad to see such wonderful information being shared freely out there.

  28. What i don’t understood is actually how you’re not actually much more neatly-favored than you may be right now. You’re so intelligent. You already know therefore significantly in the case of this matter, made me in my view believe it from so many numerous angles. Its like women and men don’t seem to be involved except it is something to accomplish with Woman gaga! Your individual stuffs outstanding. Always take care of it up!

  29. Aw, this was a very nice post. In concept I would like to put in writing like this additionally – taking time and actual effort to make an excellent article… but what can I say… I procrastinate alot and by no means seem to get something done.

  30. A person essentially help to make seriously articles I might state. This is the first time I frequented your website page and to this point? I amazed with the research you made to make this actual put up incredible. Great activity!

  31. I have been browsing online more than three hours today, yet I by no means discovered any interesting article like yours. It is pretty price sufficient for me. In my opinion, if all webmasters and bloggers made good content material as you probably did, the internet will be a lot more helpful than ever before.

  32. Hello! I’m at work browsing your blog from my new apple iphone! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the excellent work!

  33. Good site you have here.. It’s difficult to find high-quality writing like yours nowadays. I really appreciate individuals like you! Take care!!

  34. I truly wanted to compose a small note so as to thank you for those fabulous concepts you are showing at this website. My time intensive internet look up has at the end of the day been honored with incredibly good insight to go over with my classmates and friends. I ‘d state that that most of us site visitors are extremely lucky to exist in a superb place with so many perfect people with insightful techniques. I feel quite lucky to have discovered your website page and look forward to some more fabulous times reading here. Thanks a lot again for everything.

  35. I really enjoy looking through on this internet site , it holds great content . “I have a new philosophy. I’m only going to dread one day at a time.” by Charles M. Schulz.

  36. Pingback: realistik manken·

  37. Thanks for another fantastic article. Where else could anybody get that type of info in such a perfect way of writing? I’ve a presentation next week, and I am on the look for such information.

  38. I have read several just right stuff here. Certainly worth bookmarking for revisiting. I surprise how so much effort you set to create any such wonderful informative web site.

  39. I totally dig this idea, but . . . who writes the first letters you guys or us? (above says, you guys, however the email I got just said we write them.) What is the subject matter? Can we write about anything? I’m able to imagine this is usually a lot cheaper than therapy or medication for some persons. Can we include photographs of our cats? How about recipes for vegan cupcakes? There is actually a chance I might have interesting things to write about. What is the statistical probability that the reader will care? Wonderful idea! You are all magnificent. Please advise.

  40. There are some attention-grabbing points in time in this article however I don’t know if I see all of them middle to heart. There may be some validity however I will take hold opinion till I look into it further. Good article , thanks and we would like more! Added to FeedBurner as properly

  41. Thank you a bunch for sharing this with all people you actually realize what you are speaking approximately! Bookmarked. Kindly additionally talk over with my website =). We may have a link change arrangement between us!

  42. Aw, this was a really nice post. In thought I want to put in writing like this moreover – taking time and precise effort to make a very good article… however what can I say… I procrastinate alot and by no means seem to get one thing done.

  43. Fantastic web site. Plenty of useful information here. I’m sending it to several friends ans also sharing in delicious. And naturally, thank you for your effort!

  44. Attractive section of content. I just stumbled upon your website and in accession capital to assert that I get in fact enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently quickly.

  45. I’m usually to running a blog and i really recognize your content. The article has really peaks my interest. I am going to bookmark your site and maintain checking for brand new information.

  46. I was browsing the web looking for some cool stuff and came across your site. I just wanted to let you know that I think your site has some good pages and that I have already saved the page so I can visit again soon! Well done!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s