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

Exámen Parcial de Arduino

The document outlines a partial exam for Arduino, including a complete circuit design and corresponding code. The code utilizes various components such as a DHT sensor for temperature and humidity readings, buttons for user interaction, and an LCD display for output. It also includes functions for controlling a servo motor and LED sequences based on sensor data and button presses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Exámen Parcial de Arduino

The document outlines a partial exam for Arduino, including a complete circuit design and corresponding code. The code utilizes various components such as a DHT sensor for temperature and humidity readings, buttons for user interaction, and an LCD display for output. It also includes functions for controlling a servo motor and LED sequences based on sensor data and button presses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

EXÁMEN PARCIAL DE ARDUINO

Nombre completo: Bleymar Quinteroz Laura

1. Diseño del circuito


Código en arduino

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include <Servo.h>

#include <DHT.h>

#define DHTPIN A0

#define DHTTYPE DHT11

#define BUTTON1 2

#define BUTTON2 3

#define MOTOR_PIN 9

#define LED1 4

#define LED2 5

#define LED3 6

#define LED4 7

#define POT A1

DHT dht(DHTPIN, DHTTYPE);

LiquidCrystal_I2C lcd(0x27, 16, 2);

Servo servo;

volatile bool button1Pressed = false;

volatile bool button2Pressed = false;

void IRAM_ATTR button1ISR() {

button1Pressed = !button1Pressed;

void IRAM_ATTR button2ISR() {

button2Pressed = !button2Pressed;

void setup() {
Serial.begin(9600);

lcd.begin();

lcd.backlight();

dht.begin();

servo.attach(10);

pinMode(BUTTON1, INPUT_PULLUP);

pinMode(BUTTON2, INPUT_PULLUP);

pinMode(LED1, OUTPUT);

pinMode(LED2, OUTPUT);

pinMode(LED3, OUTPUT);

pinMode(LED4, OUTPUT);

pinMode(MOTOR_PIN, OUTPUT);

attachInterrupt(digitalPinToInterrupt(BUTTON1), button1ISR, FALLING);

attachInterrupt(digitalPinToInterrupt(BUTTON2), button2ISR, FALLING);

void loop() {

float temp = dht.readTemperature();

float hum = dht.readHumidity();

int potValue = analogRead(POT);

int servoPos = map(potValue, 0, 1023, 0, 180);

servo.write(servoPos);

lcd.setCursor(0, 0);

lcd.print("Temp: ");

lcd.print(temp);

lcd.print("C ");
lcd.setCursor(0, 1);

lcd.print("Hum: ");

lcd.print(hum);

lcd.print("% ");

if (temp > 30) {

analogWrite(MOTOR_PIN, 127); // 50% PWM

} else {

analogWrite(MOTOR_PIN, 0);

if (button1Pressed) {

ledSequence();

if (button2Pressed) {

customCharAnimation();

void ledSequence() {

digitalWrite(LED1, HIGH);

delay(200);

digitalWrite(LED2, HIGH);

delay(200);

digitalWrite(LED3, HIGH);

delay(200);

digitalWrite(LED4, HIGH);

delay(200);

digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);

digitalWrite(LED3, LOW);

digitalWrite(LED4, LOW);

void customCharAnimation() {

byte customChar[8] = {

0b00000,

0b01010,

0b10101,

0b00000,

0b00000,

0b10101,

0b01010,

0b00000

};

lcd.createChar(0, customChar);

for (int i = 0; i < 16; i++) {

lcd.setCursor(i, 0);

lcd.write(byte(0));

delay(200);

lcd.clear();

You might also like