Sensor de Luz con Arduino y Relays

Sensor de Luz con Arduino y Relays

Con ayuda de nuestro sensor de luz lograremos desarrollar un programa en Arduino que permitirá controlar un relay de acuerdo a la variación de luz detectada en el ambiente.


Software Arduino
Módulo Sensor de Luz
Módulo Relay de 5v

Preparando el programa

Para comenzar abrimos nuestro IDE Arduino y necesitaremos reconocer los pines que vamos a utilizar en mi caso usare para el sensor de luz el pin A0 y para el módulo relay el pin 2 digital.

Programando arduino sensor luz relay

En la función loop asignamos la lectura del pin del sensor de luz hacia la variable "sensorvalor" donde se almacenará el valor obtenido dependiendo de la luz del medio en que se encuentra.

Luego haremos un condicional if para comparar el valor obtenido del sensor de luz, este valor debe calibrarse según el lugar donde se encuentre el sensor. En mi caso lo he configurado con el valor de 440.

En caso de que se cumpla la condición de que el sensor detecte el valor de luz mayor a 440 el relay se apagará, en este caso indique el valor al ledpin2 de HIGH, esto es porque mi módulo relay funciona a la inversa. Cuando se le indica el valor HIGH se apaga y cuando se indica el valor LOW se enciende. Con esto hago que en una zona donde no haya luz el sensor automáticamente active el relay y este accione el switch para un foco dando luz al ambiente, en caso contrario se apaga.

Publicar un comentario

Guardar mi nombre, correo electrónico y sitio web en este navegador la próxima vez que comente

5 Comentarios

  1. These are in fact fantastic ideas in concerning blogging. You have touched some fastidious points here. Any way keep up wrinting. I have been browsing online more than three hours nowadays, yet I never found any fascinating article like yours. It’s beautiful value sufficient for me. In my view, if all website owners and bloggers made just right content material as you did, the internet will probably be much more useful than ever before. Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! By the way, how could we communicate?

  2. Greetings from California! I'm bored to tears at work so I decided to check out your website on my iphone during lunch break. I love the knowledge you provide here and can't wait to take a look when I get home. I'm shocked at how quick your blog loaded on my mobile .. I'm not even using WIFI, just 3G .. Anyhow, awesome site!

  3. I have been exploring for a little for any high-quality articles or blog posts in this sort of area . Exploring in Yahoo I ultimately stumbled upon this site. Reading this information So i’m glad to exhibit that I have a very just right uncanny feeling I came upon exactly what I needed. I most unquestionably will make sure to do not disregard this site and give it a look on a continuing basis.

  4. Way cool! Some very valid points! I appreciate you penning this write-up plus / the rest of the site is really good.

  5. Fantastic goods from you, man. I have understand your stuff previous to and you are just too wonderful. I actually like what you have acquired here, really like what you're stating and the way in which you say it. You make it entertaining and you still take care of to keep it smart. I can not wait to read far more from you. This is really a tremendous site.