0% found this document useful (0 votes)
5 views

codigo

The document is an Arduino sketch that controls two infrared sensors, two servos, an LCD display, and a solenoid. It reads the state of the sensors to trigger actions such as moving the servos and activating the solenoid while updating the LCD with sensor readings and counters. The setup initializes the components, and the loop continuously checks sensor states to execute the corresponding actions.

Uploaded by

ernestotmp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

codigo

The document is an Arduino sketch that controls two infrared sensors, two servos, an LCD display, and a solenoid. It reads the state of the sensors to trigger actions such as moving the servos and activating the solenoid while updating the LCD with sensor readings and counters. The setup initializes the components, and the loop continuously checks sensor states to execute the corresponding actions.

Uploaded by

ernestotmp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

//para sensores IR

byte pinSensor1 = 4;
byte pinSensor2 = 2;
bool lecturaSensor1 = true;
bool lecturaSensor2 = true;
bool bandera1 = true;
bool bandera2 = true;
int contador1 = 0;
int contador2 = 0;

//PARA SERVOMOTOR
#include <Servo.h>
Servo miServo1;
int angulo1 = 0;
Servo miServo2;
int angulo2 = 0;

//PARA LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);

//PARA SOLENOIDE
byte pinSolenoide = 7;

void setup()
{
Serial.begin(9600);
pinMode(pinSensor1, INPUT);
pinMode(pinSensor2, INPUT);
pinMode(pinSolenoide, OUTPUT);
miServo1.attach(3);
miServo2.attach(5);
lcd.init();
}

void loop()
{
lecturaSensor1 = !digitalRead(pinSensor1);
lecturaSensor2 = !digitalRead(pinSensor2);

if(lecturaSensor1 == true && bandera1 == true)


{
miServo1.write(180);
delay(500);
digitalWrite(pinSolenoide, HIGH);
contador1 ++;

if(lecturaSensor2 == true && bandera2 == true)


{
bandera2 == false;
contador2 ++;
miServo2.write(180);
}
if(lecturaSensor2 == false && bandera2 == false)
{
bandera2 = true;
miServo2.write(0);
}
bandera1 = false;
}

if(lecturaSensor1 == false && bandera1 == false)


{
bandera1 = true;
miServo1.write(0);
digitalWrite(pinSolenoide, LOW);
delay(500);
}
lcd.backlight();

lcd.setCursor(2,0);
lcd.print("LectOpt1:");
lcd.setCursor(13,0);
lcd.print(lecturaSensor1);
lcd.setCursor(15,0);
lcd.print(contador1);

lcd.setCursor(2,1);
lcd.print("LectOpt2:");
lcd.setCursor(13,1);
lcd.print(lecturaSensor2);
lcd.setCursor(15,1);
lcd.print(contador2);
}

You might also like