Theoretical Paper
- Computer Organization
- Data Structure
- Digital Electronics
- Object Oriented Programming
- Discrete Mathematics
- Graph Theory
- Operating Systems
- Software Engineering
- Computer Graphics
- Database Management System
- Operation Research
- Computer Networking
- Image Processing
- Internet Technologies
- Micro Processor
- E-Commerce & ERP
Practical Paper
Industrial Training
Arduino - Humidity Sensor
In this section, we will learn how to interface our Arduino board with different sensors. We will discuss the following sensors −
-
Humidity sensor (DHT22)
Temperature sensor (LM35)
Water detector sensor (Simple Water Trigger)
PIR SENSOR
ULTRASONIC SENSOR
GPS
Components Required
You will need the following components −
-
1 × Breadboard
1 × Arduino Leonardo, Micro, or Due board
1 × momentary pushbutton
1 × 10k ohm resistor
Procedure
Follow the circuit diagram and hook up the components on the breadboard as shown in the image given below.
Sketch
Open the Arduino IDE software on your computer. Coding in the Arduino language will control your circuit. Open a new sketch File by clicking New.
Note − You must include the keyboard library in your Arduino library file. Copy and paste the keypad library file inside the file with the name libraries (highlighted) as shown in the following screenshot.
Arduino Code
/* Keyboard Message test For the Arduino Leonardo and Micro, Sends a text string when a button is pressed. The circuit: * pushbutton attached from pin 4 to +5V * 10-kilohm resistor attached from pin 4 to ground */ #include "Keyboard.h" const int buttonPin = 4; // input pin for pushbutton int previousButtonState = HIGH; // for checking the state of a pushButton int counter = 0; // button push counter void setup() { pinMode(buttonPin, INPUT); // make the pushButton pin an input: Keyboard.begin(); // initialize control over the keyboard: } void loop() { int buttonState = digitalRead(buttonPin); // read the pushbutton: if ((buttonState != previousButtonState)&& (buttonState == HIGH)) // and it's currently pressed: { // increment the button counter counter++; // type out a message Keyboard.print("You pressed the button "); Keyboard.print(counter); Keyboard.println(" times."); } // save the current button state for comparison next time: previousButtonState = buttonState; }
Code to Note
Attach one terminal of the pushbutton to pin 4 on Arduino. Attach the other pin to 5V. Use the resistor as a pull-down, providing a reference to the ground, by attaching it from pin 4 to the ground.
Once you have programmed your board, unplug the USB cable, open a text editor and put the text cursor in the typing area. Connect the board to your computer through USB again and press the button to write in the document.
Result
By using any text editor, it will display the text sent via Arduino.