Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

User Interaction with Arduino

Importance and Utility of User Interaction

User interaction is a crucial aspect of any electronic project. It allows users to interact with the system, providing input and receiving output, making the project more user-friendly and intuitive. With Arduino, user interaction can be achieved through various input devices such as buttons, switches, sensors, and output devices such as LEDs, displays, and actuators. By incorporating user interaction, projects can be customized to meet specific user needs and preferences, enhancing their overall functionality and usability.

Project: Interactive Temperature Display

In this example project, we will create an interactive temperature display using Arduino. The objective is to allow the user to input a desired temperature and have it displayed on an LCD screen. Additionally, the system will compare the desired temperature with the current temperature and indicate whether a heating or cooling action is required.

List of Components:

  • Arduino Uno (1x) - link
  • LCD Display (16x2) (1x) - link
  • Temperature Sensor (LM35) (1x) - link
  • Push Buttons (2x) - link
  • Resistors (220Ω) (3x) - link
  • Breadboard (1x) - link
  • Jumper Wires - link

Examples:

  1. Initializing the LCD Display:
    
    #include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() { lcd.begin(16, 2); lcd.print("Temperature:"); }

In this example, we include the LiquidCrystal library and initialize the LCD display with the necessary pins. The `begin()` function sets the number of columns and rows of the LCD and the `print()` function displays the text "Temperature:" on the first line of the LCD.

2. Reading Temperature Sensor:
```arduino
int temperaturePin = A0;

void setup() {
  // ... LCD initialization ...
  pinMode(temperaturePin, INPUT);
}

void loop() {
  int temperature = analogRead(temperaturePin);
  float celsius = (temperature * 0.48875);
  lcd.setCursor(0, 1);
  lcd.print("Temp: ");
  lcd.print(celsius);
  lcd.print(" C");
  delay(1000);
}

In this example, we read the analog value from the temperature sensor connected to pin A0. We convert the analog value to Celsius and display it on the second line of the LCD using the setCursor() and print() functions.

  1. User Input with Push Buttons:
    
    int upButtonPin = 7;
    int downButtonPin = 6;

void setup() { // ... LCD initialization ... pinMode(upButtonPin, INPUT_PULLUP); pinMode(downButtonPin, INPUT_PULLUP); }

void loop() { if (digitalRead(upButtonPin) == LOW) { // Increase desired temperature } if (digitalRead(downButtonPin) == LOW) { // Decrease desired temperature } // ... Display desired temperature ... delay(100); }


In this example, we define two push buttons connected to pins 7 and 6 as inputs with internal pull-up resistors. We continuously check the state of the buttons using `digitalRead()` and perform actions based on the button press. These actions can include increasing or decreasing the desired temperature.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.