¿Y donde esta practica de la lampara de mesa?
Bienvenida al curso
Enlaces del taller IoT
Qué aprenderás sobre el desarrollo de hardware con Arduino
Introducción al hardware libre
¿Qué es Arduino y qué placas hay?
¿Cómo se desarrolla el Hardware?
¿Cuál es el software para diseño mecánico?
Elección del software a utilizar
Limitaciones de Arduino y qué es el hardware libre
Reto 1: Para un proyecto de IoT, ¿Cuál tarjeta Arduino utilizarías?
¿Cómo funciona el Curso de Desarrollo de Hardware con Arduino?
Lista de Materiales o Componentes a Utilizar
Sensores, Actuadores y Procesadores
Sensores, actuadores y procesadores
Diferentes tipos de sensores según la salida
Diferentes tipos de sensores según la aplicación
Diferentes tipos de actuadores
Introducción a la electrónica
Diferencias entre electricidad y electrónica
Tipos de componentes electrónicos
Más tipos de componentes electrónicos
Limitando la corriente para evitar quemar un led
Manos a la obra
Puertos de un arduino y sus funciones
Qué es un protoboard
Estructura general de un programa en Arduino y hello world con un LED
Variables y Constantes Globales
Manejo de librerías y funciones
Manejo de valores analógicos: uso del potenciómetro
Uso del monitor serial
PWM y señales analógicas
Un control de color RGB e intensidad lumínica para una lampara de mesa
Uso de push buttons
Monitor de temperatura con Arduino (uso de LM35 y un lcd 16x2)
Continuando con el monitor de temperatura con Arduino
Finalizando con el monitor de temperatura con Arduino
Reto: Crea tu semáforo con Arduino
Automatización de procesos
Cómo generar movimiento y uso de motores
Cómo generar movimiento y servomotores
Agregando un potenciométro para controlar la posición del Servomotor
Robot evasor de obstáculos
Continuando con el Robot evasor de obstáculos
Terminando con el Robot evasor de obstáculos
Aún no tienes acceso a esta clase
Crea una cuenta y continúa viendo este curso
Aportes 35
Preguntas 7
¿Y donde esta practica de la lampara de mesa?
Hice el reto! Un boton cambia el color y un potenciómetro, la intensidad de la luz.
int led_rojo = 11;
int led_verde = 10;
int led_azul = 9;
int boton = 8;
int boton_value;
int pulsos = 0;
int boton_presionado = 0;
int pot_pin = A0;
int pot_value = 0;
int bright_value = 0;
void setup()
{
pinMode(boton, INPUT_PULLUP);
pinMode(led_azul,OUTPUT);
pinMode(led_verde,OUTPUT);
pinMode(led_rojo,OUTPUT);
}
void loop()
{
pot_value = analogRead(pot_pin);
bright_value = map(pot_value, 0, 1023, 0, 255);
boton_value = digitalRead(boton);
if(boton_presionado == LOW && boton_value == HIGH)
{
pulsos ++;
boton_presionado = HIGH; //Reconocer el boton presionado
}
if(boton_presionado == HIGH && boton_value == LOW)
boton_presionado = LOW;
if(pulsos > 7)
pulsos = 0;
color(pulsos);
}
//Cada vez que se pulsa el boton, se le suma 1 al contador. Cuando llega a 8 (cantidad de casos del switch) se reinicia todo
//nro_color refiere al caso, este refiere a color que varia segun el pulso
void color(int nro_color)
{
switch (nro_color)
{
case 0:
analogWrite(led_rojo, bright_value);
analogWrite(led_verde, 0);
analogWrite(led_azul, 0);
break;
case 1:
analogWrite(led_rojo, 0);
analogWrite(led_verde, bright_value);
analogWrite(led_azul, 0);
break;
case 2:
analogWrite(led_rojo, 0);
analogWrite(led_verde, 0);
analogWrite(led_azul, bright_value);
break;
case 3:
analogWrite(led_rojo, bright_value);
analogWrite(led_verde, bright_value);
analogWrite(led_azul, 0);
break;
case 4:
analogWrite(led_rojo, 0);
analogWrite(led_verde, bright_value);
analogWrite(led_azul, bright_value);
break;
case 5:
analogWrite(led_rojo, bright_value);
analogWrite(led_verde, 0);
analogWrite(led_azul, bright_value);
break;
case 6:
analogWrite(led_rojo, bright_value);
analogWrite(led_verde, bright_value);
analogWrite(led_azul, bright_value);
break;
case 7:
analogWrite(led_rojo, 0);
analogWrite(led_verde, 0);
analogWrite(led_azul, 0);
break;
return;
}
}
Les comparto mi solución del reto. Led RGB que cambia de colores giranto los potenciómetros
int ledRgbRojo = 3;
int ledRgbAzul = 5;
int ledRgbVerde = 6;
int potPin0 = A0;
int potPin1 = A1;
int potPin2 = A2;
int brighValue0 = 0;
int brighValue1 = 0;
int brighValue2 = 0;
int potValue0 = 0;
int potValue1 = 0;
int potValue2 = 0;
void setup()
{
// no se declara nanda
}
void loop()
{
potValue0 = analogRead(potPin0);
potValue1 = analogRead(potPin1);
potValue2 = analogRead(potPin2);
brighValue0 = map(potValue0, 0, 1023, 0, 255);
brighValue1 = map(potValue1, 0, 1023, 0, 255);
brighValue2 = map(potValue2, 0, 1023, 0, 255);
analogWrite(ledRgbRojo, brighValue0);
analogWrite(ledRgbAzul, brighValue1);
analogWrite(ledRgbVerde, brighValue2);
delay(10);
}```
SIIIIII Funciona !!!
solo se ven sus manos XD
Al codigo le hice una pequeña modificación para que vaya variando el color y se mezcle un poco
int led1 = 3;
int led2 = 5;
int led3 = 6;
int potPin = A0;
int potValue =0;
int brightValue = 0;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
potValue = analogRead(potPin);
brightValue = map(potValue, 0, 1023, 0, 255);
if (brightValue < 85)
{
analogWrite(led1, brightValue * 3);
analogWrite(led2, 0);
analogWrite(led3, 0);
delay(10);
}
else if ((brightValue > 85) && (brightValue < 170))
{
analogWrite(led1, brightValue);
analogWrite(led2, (brightValue - 85) * 3);
analogWrite(led3, 0);
delay(10);
}
else
{
analogWrite(led1, 0);
analogWrite(led2, brightValue);
analogWrite(led3, (brightValue - 170) * 3);
delay(10);
}
}
una consulta xq no usa una resitencía en cada led ???
reto cumplido convinar colores usando dos pots
int ledRed = 3;
int ledGreen = 5;
int ledBlue = 9;
int potPin1 = A0;
int potPin2 = A1;
int potValue1 = 0;
int potValue2 = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
potValue1 = analogRead(potPin1);
potValue1 = map(potValue1, 0, 1023, 0, 255);
Serial.print("potValue1: ");
Serial.print(potValue1);
delay(100);
potValue2 = analogRead(potPin2);
potValue2 = map(potValue2, 0, 1023, 0, 255);
Serial.print(" potValue2: ");
Serial.println(potValue2);
delay(100);
if(potValue1 < 63 && potValue2 > 250)
{
analogWrite(ledRed, 36); //color violeta
analogWrite(ledGreen, 0);
analogWrite(ledBlue, 54);
}
else
{
analogWrite(ledRed, 255);
analogWrite(ledGreen, 255);
analogWrite(ledBlue, 255);
}
if(potValue1 >= 63 && potValue1 < 126 && potValue2 < 63)
{
analogWrite(ledRed, 255); //color turquesa
analogWrite(ledGreen, 0);
analogWrite(ledBlue, 20);
}
else if(potValue1 >= 126 && potValue2 >=63 && potValue2 <=250)
{
analogWrite(ledRed, 255); // color naranja
analogWrite(ledGreen, 18);
analogWrite(ledBlue, 0);
}
}**
<code>
**```
diagrama de coneccion:
prototipo en video funcional :
https://www.youtube.com/shorts/JHWSeI5mwa4
codigo :
int r = 3; //pines del rgb
int g = 5; //pines del rgb
int b = 6; //pines del rgb
int potPin0 = A0; //potenciometro que controla el color rojo
int potPin1 = A1; //potenciometro que controla el color verde
int potPin2 = A2; // potenciometro que controla el color azul
int potValue = 0;
int brightValue = 0;
void setup() {
}
void loop() {
//rojo
potValue = analogRead(potPin0);
brightValue = map(potValue, 0, 1023, 0, 255);
analogWrite(r, brightValue);
//verde
potValue = analogRead(potPin1);
brightValue = map(potValue, 0, 1023, 0, 255);
analogWrite(g, brightValue);
//azul
potValue =analogRead(potPin2);
brightValue = map(potValue, 0, 1023, 0, 255);
analogWrite(b, brightValue);
}
int led1 = 3;
int led2 = 5;
int led3 = 6;
int led4 = 10;
int potpin = A0;
int potvalue = 0;
int brightvalue = 0;
void setup() {
// put your setup code here, to run once:
// =P
}
void loop() {
// put your main code here, to run repeatedly:
potvalue = analogRead(potpin);
brightvalue = map(potvalue, 0, 1023, 0, 255);
analogWrite(led1, brightvalue);
analogWrite(led2, brightvalue);
analogWrite(led3, brightvalue);
analogWrite(led4, brightvalue);
delay(10);
//Resulicion PWM 8bits osea 2^8=256
}
Probando el PWM en un LED
¿Qué frecuencia de señal genera la función analogWrite?
Cuanto es el valor de resistencia maximo que tiene el potenciometro ?
int ledR = 3;
int ledY = 5;
int ledA = 6;
int potPinA = A2;
int potPinY = A1;
int potPinR = A0;
int potValueA = 0;
int potValueY = 0;
int potValueR = 0;
int brightValueA =0;
int brightValueY =0;
int brightValueR =0;
void setup() {
// put your setup code here, to run once:
// =P
}
void loop() {
// put your main code here, to run repeatedly:
potValueA = analogRead(potPinA);
potValueY = analogRead(potPinY);
potValueR = analogRead(potPinR);
brightValueA = map(potValueA, 0, 1023, 0, 255);
brightValueY = map(potValueY, 0, 1023, 0, 255);
brightValueR = map(potValueR, 0, 1023, 0, 255);
analogWrite(ledR,brightValueR);
analogWrite(ledY,brightValueY);
analogWrite(ledA,brightValueA);
delay(10);
}
**Ver funcionando en Tinkercad: **
https://youtu.be/T9_uo5Yb_Bc
int ledR = 3;
int ledY = 5;
int ledA = 6;
int potPinA = A2;
int potPinY = A1;
int potPinR = A0;
int potValueA = 0;
int potValueY = 0;
int potValueR = 0;
int brightValueA =0;
int brightValueY =0;
int brightValueR =0;
void setup() {
// put your setup code here, to run once:
// =P
}
void loop() {
// put your main code here, to run repeatedly:
potValueA = analogRead(potPinA);
potValueY = analogRead(potPinY);
potValueR = analogRead(potPinR);
brightValueA = map(potValueA, 0, 1023, 0, 255);
brightValueY = map(potValueY, 0, 1023, 0, 255);
brightValueR = map(potValueR, 0, 1023, 0, 255);
analogWrite(ledR,brightValueR);
analogWrite(ledY,brightValueY);
analogWrite(ledA,brightValueA);
delay(10);
}
//Cambiar el color de un led RGB con un botón
int ledRojo= 3;
int ledVerde= 4;
int ledAzul= 5;
int boton= 8;
int contador= 0;
void setup() {
// put your setup code here, to run once:
pinMode(ledRojo, OUTPUT);
pinMode(ledVerde,OUTPUT);
pinMode(ledAzul, OUTPUT);
pinMode(boton, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(boton) == LOW)
{
contador = contador+1;
delay(300);
switch (contador){
case 1:
digitalWrite(ledRojo, HIGH);
break;
case 2:
digitalWrite(ledRojo, LOW);
digitalWrite(ledVerde, HIGH);
break;
case 3:
digitalWrite(ledVerde, LOW);
digitalWrite(ledAzul, HIGH);
break;
case 4:
digitalWrite(ledRojo, HIGH);
digitalWrite(ledVerde, HIGH);
digitalWrite(ledAzul, LOW);
break;
case 5:
digitalWrite(ledRojo, HIGH);
digitalWrite(ledVerde, LOW);
digitalWrite(ledAzul, HIGH);
break;
case 6:
digitalWrite(ledRojo, LOW);
digitalWrite(ledVerde, HIGH);
digitalWrite(ledAzul, HIGH);
break;
case 7:
digitalWrite(ledRojo, HIGH);
digitalWrite(ledVerde, HIGH);
digitalWrite(ledAzul, HIGH);
break;
case 8:
digitalWrite(ledRojo, LOW);
digitalWrite(ledVerde, LOW);
digitalWrite(ledAzul, LOW);
contador = 0;
break;
}
}
}
//Cambiar el color de un led RGB con un potenciómetro
int ledRojo= 3;
int ledVerde= 4;
int ledAzul= 5;
int potPin= A0;
int potValue= 0;
int color= 0;
void setup() {
// put your setup code here, to run once:
pinMode(ledRojo, OUTPUT);
pinMode(ledVerde,OUTPUT);
pinMode(ledAzul, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
potValue = analogRead(potPin);
color = map(potValue, 0,1023,0,7);
delay(100);
switch (color){
case 0:
digitalWrite(ledRojo, LOW);
digitalWrite(ledVerde, LOW);
digitalWrite(ledAzul, LOW);
break;
case 1:
digitalWrite(ledRojo, HIGH);
digitalWrite(ledVerde, LOW);
digitalWrite(ledAzul, LOW);
break;
case 2:
digitalWrite(ledRojo, LOW);
digitalWrite(ledVerde, HIGH);
digitalWrite(ledAzul, LOW);
break;
case 3:
digitalWrite(ledRojo, LOW);
digitalWrite(ledVerde, LOW);
digitalWrite(ledAzul, HIGH);
break;
case 4:
digitalWrite(ledRojo, HIGH);
digitalWrite(ledVerde, HIGH);
digitalWrite(ledAzul, LOW);
break;
case 5:
digitalWrite(ledRojo, HIGH);
digitalWrite(ledVerde, LOW);
digitalWrite(ledAzul, HIGH);
break;
case 6:
digitalWrite(ledRojo, LOW);
digitalWrite(ledVerde, HIGH);
digitalWrite(ledAzul, HIGH);
break;
case 7:
digitalWrite(ledRojo, HIGH);
digitalWrite(ledVerde, HIGH);
digitalWrite(ledAzul, HIGH);
break;
}
}
probando dos pwm y un boton.
Conectando una resistencia de ~1kOhm entre 5v y una fotoresistencia (y luego poniendo un jumper entre estos) se puede deducir que cuánto más oscuro está mayor es el valor que detecta. Por ende, mediante este código podemos hacer que el LED brille más. Por el contrario (cuando hay mucha luz ambiental) el brillo disminuye. Con el uso de transistores en vez de leds se puede implementar en el sistema de iluminación de una casa para ahorrar energía y que la iluminación sea relativamente constante dependiendo de la potencia de las luces empleadas.
const int led = 10;
const int ambiente = A0;
int luz;
int brillo;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop() {
luz = analogRead(ambiente);
brillo = map(luz, 0, 1023, 0, 255);
analogWrite(led, brillo);
delay(500);
Serial.println(luz);
}
Aqui el link de este proyecto con tinkercard,
comparto este “mini-proyecto” para independizar cada bombillo led a 3 potenciómetros
https://drive.google.com/drive/folders/1g9AMk4Cnq23T_IyqbpdkE_dEuzT0PepS
Recuerden conectar su potenciómetro a corriente y tierra, que si no no funciona, jejeje.
int led1 = 3;
int led2 = 5;
int led3 = 6;
int potPin = A0;
int brighValue = 0;
int potValue = 0;
void setup()
{
// no se declara nanda
}
void loop()
{
potValue = analogRead(potPin);
brighValue = map(potValue, 0, 1023, 0, 255);
analogWrite(led1, brighValue);
analogWrite(led2, brighValue);
analogWrite(led3, brighValue);
delay(10);
}
int led = 3;
int led2 = 5;
int led3 = 6;
int potPin = A0;
int potValue = 0;
int brightValue = 0;
void setup()
{
}
void loop()
{
potValue = analogRead(potPin);
brightValue = map(potValue, 0, 1023, 0, 255);
analogWrite(led, brightValue);
analogWrite(led2, brightValue);
analogWrite(led3, brightValue);
delay(10);
}
//VARIABLES GLOBALES
int ledrojo = 2;
int ledamarillo = 4;
int ledverde = 6;
int Potenciometro = A0;
int valpot = 0;
int valorluz= 0; //guardar ekl valor que tanto ilumine
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
valpot= analogRead(Potenciometro);
valorluz = map (valpot,0,1023,0,255); //regla de tres
analogWrite(ledrojo, valorluz);
analogWrite(ledamarillo, valorluz);
analogWrite(ledverde, valorluz);
delay (10);
}
Comparto el código para variar los colores de un led RGB. El principio es el mismo, se varia la intensidad del brillo de cada led que compone el RGB y estas variaciones afectan el color final
int rled = 11; // Pin PWN 11 para led rojo
int bled = 9; // Pin PWM 10 para led azul
int gled = 8; // Pin PWM 9 para led verde
int pot1 = A0; //Pin Analogico 0
int pot2 = A1; //Pin Analogico 1
int pot3 = A2; //Pin Analogico 0
int p1 = 0;
int p2 = 0;
int p3 = 0;
void setup() {
}
void loop() {
//Colores Aleatorios
p1=analogRead(pot1);
p2=analogRead(pot2);
p3=analogRead(pot3);
p1 = map(p1,0,1023,0,255);
p2 = map(p2,0,1023,0,255);
p3 = map(p3,0,1023,0,255);
analogWrite(rled, p1);
analogWrite(bled, p2);
analogWrite(gled, p3);
}
Adjunto el prototipo hecho en tinkercad
Y también comparto un pequeño juego; utilizando la función random() para generar valores “aleatorios” entre 0 y 255 para variar la intensidad de los led y así afectar el color del RGB, en conjunto utilizo un potenciometro para variar la el tiempo del delay (La frecuencia con la que cambian los colores)
int rled = 11; // Pin PWN 11 para led rojo
int bled = 9; // Pin PWM 10 para led azul
int gled = 8; // Pin PWM 9 para led verde
int potPin = A0;
int potValue = 0;
int randColor1 = 0;
int randColor2 = 0;
int randColor3 = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
randColor1 = random(0,256);
randColor2 = random(0,256); // Valores aleatorios de 0 a 255
randColor3 = random(0,256);
potValue = analogRead(potPin);
analogWrite(rled, randColor1);
analogWrite(bled, randColor2);
analogWrite(gled, randColor3);
delay(potValue);
}
int led1 = 3;
int led2 = 5;
int led3 = 6;
int potPin = A0;
int potValue = 0;
int brightValue = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);//Lee el puerto serial a 9600baudios
}
void loop() {
// put your main code here, to run repeatedly:
potValue = analogRead(potPin);
brightValue = map(potValue, 0,1023,0,255);
Serial.println(brightValue);
if (brightValue<100)
{
analogWrite(led1,brightValue);
analogWrite(led2,0);
analogWrite(led3,0);
delay(10);
}
if ((brightValue>=100) && (brightValue<200))
{
analogWrite(led2,brightValue);
analogWrite(led1,0);
analogWrite(led3,0);
delay(10);
}
else if (brightValue>=200)
{
analogWrite(led3,brightValue);
analogWrite(led2,0);
analogWrite(led1,0);
delay(10);
}
}```
alguién sabe como conectar el nodemcu con arduino uno (arduino tiene conectado un sensor de temperatura y el nodemcu subirá la información a la nube). De antemano gracias por sus amables respuestas
Interesante
![](
¿Quieres ver más aportes, preguntas y respuestas de la comunidad? Crea una cuenta o inicia sesión.