0% encontró este documento útil (0 votos)
101 vistas8 páginas

Programas Arduino

El documento contiene código para varios proyectos electrónicos, incluyendo un control remoto infrarrojo, un puntero láser controlado por botón, un sensor de vibraciones que enciende un LED, un potenciómetro que controla la intensidad de un LED, y un detector de obstáculos con servo motor que gira dependiendo de la distancia detectada.

Cargado por

micha2mc
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
101 vistas8 páginas

Programas Arduino

El documento contiene código para varios proyectos electrónicos, incluyendo un control remoto infrarrojo, un puntero láser controlado por botón, un sensor de vibraciones que enciende un LED, un potenciómetro que controla la intensidad de un LED, y un detector de obstáculos con servo motor que gira dependiendo de la distancia detectada.

Cargado por

micha2mc
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 8

MANDO REMOTE

#include <IRLremote.h>

int INTERRUPCION = 0; //PIN 2

uint8_t protocolo = 0;
uint16_t direccion = 0;
uint32_t tecla = 0;

uint8_t oldSREG;

void setup(){
IRLbegin<IR_ALL>(INTERRUPCION);
Serial.begin(115200);
}

void IREvent (uint8_t protocol, uint16_t address, uint32_t command)


{
protocolo = protocol;
direccion = address;
tecla = command;
}

void loop(){
oldSREG = SREG;
cli();

if(protocolo!=0){
Serial.print("Protocolo: ");
Serial.print(protocolo);
Serial.print(" Direccion: ");
Serial.print(direccion, HEX);
Serial.print(" Tecla: ");
Serial.println(tecla, HEX);
protocolo=0;
}

SREG = oldSREG;

}
PUNTERO LASER
int PULSADOR=2;
int LASER=3;

void setup(){
pinMode(PULSADOR, INPUT);
pinMode(LASER, OUTPUT);
digitalWrite(LASER, LOW);
}

void loop(){
while(digitalRead(PULSADOR)==LOW);
digitalWrite(LASER, HIGH);
while(digitalRead(PULSADOR)==HIGH);
digitalWrite(LASER, LOW);

//digitalWrite(LASER, digitalRead(PULSADOR));
}

SENSOR DE VIBRACIONES
int LED=13;
int SENSOR=10;

void setup(){
pinMode(LED,OUTPUT);
pinMode(SENSOR, INPUT);
digitalWrite(LED, LOW);
}

void loop(){
digitalWrite(LED, !digitalRead(SENSOR));
/*if(digitalRead(SENSOR)==LOW){
digitalWrite(LED, HIGH);
}else{
digitalWrite(LED, LOW);
}*/
}

POTENCIOMETRO

int CLK=2;
int DT=3;
int LED=5;
int anteriorCLK;
int valorCLK;
int valorDT;
int cont;

void setup(){
pinMode(LED, OUTPUT);

pinMode(CLK, INPUT);
pinMode(DT, INPUT);
digitalWrite(LED, LOW);
anteriorCLK=digitalRead(CLK);
cont=0;
}

void loop(){
valorCLK=digitalRead(CLK);
if(valorCLK!=anteriorCLK){
valorDT=digitalRead(DT);
if(valorDT==valorCLK){ //derecha
cont++;
if(cont>255){
cont=0;
}
}else{ //izquierda
cont--;
if(cont<0){
cont=255;
}
}
analogWrite(LED,cont);
anteriorCLK=valorCLK;
}
}

DETECTOR DE OBSTACULO
#define trigPin 13
#define echoPin 12
#define led 11
#define led2 10
#include <Servo.h>
int pos = 0; // variable to store the servo position
int defPOS = 0;
Servo myservo;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
myservo.attach(9);
myservo.write(0);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
//0 Left
//1 Center
//2 Right
int buttonState1 = digitalRead(led); //red
int buttonState2 = digitalRead(led2); //green
if( (buttonState1 == 0 && buttonState2 == 1) && (defPOS != 1))
{
delay(2000);
if(defPOS == 2)
{
for(pos = 0; pos <= 90; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(2); // waits 15ms for the servo to reach the position
}
}
else if(defPOS == 0)
{
for(pos = 0; pos <= 90; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(2); // waits 15ms for the servo to reach the position
}
}
defPOS = 1;
}
if (distance < 30) { // This is where the LED On/Off happens
digitalWrite(led,HIGH); // When the Red condition is met, the Green LED
should turn off
digitalWrite(led2,LOW);
if(defPOS == 0)
{
for(pos = 90; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(2); // waits 15ms for the servo to reach the position
}
defPOS = 2;
}
else if(defPOS == 2)
{
for(pos = 0; pos <= 90; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(2); // waits 15ms for the servo to reach the position
}
defPOS = 1;
}
else if(defPOS == 1)
{
for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180
degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(2); // waits 15ms for the servo to reach the position
}
defPOS = 0;
}
//myservo.write(180);
// delay(1000);
//myservo.write(0);
}
else {
digitalWrite(led,LOW);
digitalWrite(led2,HIGH);
}
if (distance >= 400 || distance <= 0){
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}

También podría gustarte