0% found this document useful (0 votes)
12 views3 pages

Diagrama y Codigo

The document contains an Arduino code that utilizes infrared sensors, servomotors, an LCD, and a solenoid. It initializes the components and continuously checks the sensor readings to control the servomotors and solenoid based on specific conditions. The LCD displays the sensor readings and their respective counts.

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)
12 views3 pages

Diagrama y Codigo

The document contains an Arduino code that utilizes infrared sensors, servomotors, an LCD, and a solenoid. It initializes the components and continuously checks the sensor readings to control the servomotors and solenoid based on specific conditions. The LCD displays the sensor readings and their respective counts.

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/ 3

//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