Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore CU-BCA- Sem VI-IOT Based Applications Practical

CU-BCA- Sem VI-IOT Based Applications Practical

Published by Teamlease Edtech Ltd (Amita Chitroda), 2022-11-12 07:06:28

Description: CU-BCA- Sem VI-IOT Based Applications Practical

Search

Read the Text Version

CHANDIGARH UNIVERSITY Institute of Distance and Online Learning SLM Development Committee Prof. (Dr.) H.B. Raghvendra Vice- Chancellor, Chandigarh University, Gharuan, Punjab:Chairperson Prof. (Dr.) S.S. Sehgal Registrar Prof. (Dr.) B. Priestly Shan Dean of Academic Affairs Dr. Nitya Prakash Director – IDOL Dr. Gurpreet Singh Associate Director –IDOL Advisors& Members of CIQA –IDOL Prof. (Dr.) Bharat Bhushan, Director – IGNOU Prof. (Dr.) Majulika Srivastava, Director – CIQA, IGNOU Editorial Committee Prof. (Dr) Nilesh Arora Dr. Ashita Chadha University School of Business University Institute of Liberal Arts Dr. Inderpreet Kaur Prof. Manish University Institute of Teacher Training & University Institute of Tourism & Hotel Management Research Dr. Manisha Malhotra Dr. Nitin Pathak University Institute of Computing University School of Business © No part of this publication should be reproduced, stored in a retrieval system, or transmitted in any formor by any means, electronic, mechanical, photocopying, recording and/or otherwise without the prior written permission of the authors and the publisher. SLM SPECIALLY PREPARED FOR CU IDOL STUDENTS


IOT Based Applications Practical Course code- Credit-1 BCA165 Course Objectives: · Understand basics of programming and use of Arduino. · Become familiar different peripheral devices and sensors. · Learn techniques interfacing of Arduino with sensors and peripheral devices PRACTICAL 1. Interfacing of LEDs with Arduino and design different random patterns. Most of us tried Blinking LED using Arduino as a Beginner. Let’s do something cool using LEDs with Arduino. In this project, we will make LEDs blink in different patterns in a random manner. The program has totally 6 different patterns and the Arduino chooses the patterns randomly by itself. You can include more patterns if you like. Components Required: Arduino Pro Mini (or) Arduino Uno/Nano/Micro – Any One Breadboard – 1 LEDs – 18 Nos (Blue) 100 Ohm Resistor – 18 Jumper Wires Note: For other LEDs than Blue use 220 Ohm Resistors


Circuit diagram: There are totally 18 LEDs, so we need 18 Pins of the Arduino to control the LEDs. We will be using Digital pins 2 to 13 and Analog Pins from A0 (14) to A5 (19). In Arduino Uno/Pro Mini/Nano boards the Analog pins can also be mentioned in numbers instead of A0-A5. It will be mapped automatically by Arduino IDE. So you can directly mention the Pin numbers from 2 to 19 (A5) instead of mentioning A0, A1, A2, A3, A4 and A5 separately. Analog pins and its digital pin mapping for Arduino Uno/Nano/Pro Mini/Micro A0 is equivalent to 14 A1 is equivalent to 15 A2 is equivalent to 16 A3 is equivalent to 17 A4 is equivalent to 18 A5 is equivalent to 19


Circuit Connections: First, place all the LEDs on the breadboard. The Cathode terminal (Short Leg) should be connected to Ground (GND) via a Resistor and the Anode terminal (Long Leg) of all LED will be connected to a sequence of Arduino Pins as shown in the Table below. Now connect the Power Supply +V and Ground. The Pro Mini has an inbuilt voltage regulator so the RAW pin can accept from 5V to 12V DC Power supply. Make sure the Positive and Negative terminals are connected correctly. Now Power ON and Upload the code using FDTI Programmer in case of Pro Mini Boards. Otherwise, use the supported cables for the boards. Code: /* Arduino LED Patterns/Show Light with 18 LED */ //Setting Up the Pins for LEDs void setup()


{ for (int pin = 2; pin <= 19; pin++) { pinMode(pin,OUTPUT); } } //Main Loop - Switches different LED Patterns void loop() { int pickme = random(1,20); // picks a random pattern of LED patterns switch(pickme) {


case 1: onrun(random(20,50)); break; case 2: alternate(random(80,100)); break; case 3: offrun(random(20,50)); break; case 4: stack(random(30,50)); break;


case 5: chaser(random(80,100)); break; case 6: fadealter(random(80,100)); break; } } void clearall() { for (int pin = 2; pin <= 19; pin++) {


digitalWrite(pin,LOW); } } void fillall() { for (int pin = 2; pin <= 19; pin++) { digitalWrite(pin, HIGH); } } //One ON LED Run and all other OFF


void onrun(int delaytime) { for(int pin = 2; pin <= 19; pin++) { clearall(); digitalWrite(pin, HIGH); delay(delaytime); } for(int pin = 18; pin >= 2; pin--) { clearall(); digitalWrite(pin, HIGH);


delay(delaytime); } } //One OFF LED Run and all other OFF void offrun(int delaytime) { for(int pin = 2; pin <= 19; pin++) { fillall(); digitalWrite(pin, LOW); delay(delaytime); }


for(int pin = 18; pin >= 2; pin--) { fillall(); digitalWrite(pin, LOW); delay(delaytime); } } //Flashing all LEDs ON and OFF void flash(int delaytime) { for(int i = 1; i <=20; i++) {


clearall(); delay(delaytime); fillall(); delay(delaytime); } } //Flashing LED in Fade manner void fadeflash(int delaytime) { clearall(); int newdelay = delaytime / 5;


for(int fade = 0; fade <= 255; fade += 5) { for(int pin = 2; pin <= 19; pin++) { analogWrite(pin, fade); } delay(newdelay); } for(int fade = 255; fade >= 0; fade -= 5) { for(int pin = 2; pin <= 19; pin++)


{ analogWrite(pin, fade); } delay(newdelay); } } //Alternatively Fade & Brightens void fadealter(int delaytime) { clearall(); int newdelay = delaytime / 5; for(int fade = 0; fade <= 255; fade += 5)


{ for(int i = 2; i <= 18; i+=2) { analogWrite(i, fade); } for (int j = 3; j <= 19; j += 2) { analogWrite(j, 255-fade); } delay(newdelay); }


for(int fade = 255; fade >= 0; fade -= 5) { for(int i = 2; i <= 18; i+=2) { analogWrite(i, fade); } for (int j = 3; j <= 19; j += 2) { analogWrite(j, 255-fade); } delay(newdelay);


} } //Alternate Flash - Similar to Flash but alternate LEDs void alternate(int delaytime) { for (int n = 1; n <= 5; n++) { clearall(); for (int i = 2; i <= 18; i += 2) { digitalWrite(i, HIGH); }


delay(delaytime); clearall(); for (int j = 3; j <= 19; j += 2) { digitalWrite(j, HIGH); } delay(delaytime); } } //Putting all LEDs one by one in a stack void stack(int delaytime) {


int stack = 0; while(stack < 18) { for(int pos = 2; pos <= (19 - stack); pos++) { clearall(); digitalWrite(pos, HIGH); drawstack(stack); delay(delaytime); } stack++; }


} //Subfunction of the stack function void drawstack(int stack) { for(int n = 19; n > (19 - stack); n--) { if(n >= 2) { digitalWrite(n, HIGH); } } }


//One LED chases another LED front and back void chaser(int delaytime) { int div = 40; int flashtime = delaytime / div; int A = random(2,7); int B = random(7,12); int Av = 1; int Bv = 1; if(random(0,2)) { Av *= -1;


} if(random(0,2)) { Bv *= -1; } for(int time = 1; time < 100; time++) { if(abs(A-B) == 1 && (Av*Bv) == -1) { for(int f = 1; f < round(div/4); f++) { clearall();


delay(flashtime); digitalWrite(A, HIGH); digitalWrite(B, HIGH); delay(flashtime); } Av *= -1; Bv *= -1; A += Av; B += Bv; } else {


clearall(); digitalWrite(A, HIGH); digitalWrite(B, HIGH); A += Av; B += Bv; delay(delaytime); } if(A < 2) { A = 3; Av *= -1; }


if(B > 19) { B = 18; Bv *= -1; } if(A >= B) { A = B-1; } } }


2. Experiment 2-Interfacing of push button and buzzerwith ArduinoUno. Before proceeding we need to know about the working of piezoelectric buzzer. Piezoelectric Buzzer It is a simple device which can generate beeps and tones. Working principle of the device is piezoelectric effect. The main component of this device is a piezo crystal, A special material that change shape when a voltage applied to it. Keypoint Simply change the frequency of the voltage sent to the piezo and it will start generating sounds by changing shape very quickly. This article is divided into two parts. One is Buzzer without tone() and second is Buzzer with tone(). Lets start. 1. Buzzer without tone() Step - 1 We can also done this with a Astable Multivibrator and without any microcontroller I am going to create a sketch to make a beep sound without tone() function. Open Arduino IDE. And open a new page. First program the setup() part. I decided to control the buzzer via the digital pin 11 of Arduino Uno. So first set the pin 11 as OUTPUT by the pinMode() function. void setup(){ pinMode(11,OUTPUT); } Step - 2 Next we need to code the loop part. First set the pin 11 as HIGH by using the digitalWrite() function. Then add the 0.5 second delay. This two lines responsible for turn on (generate sound) the buzzer for 0.5 seconds.


digitalWrite(11,HIGH); delay(500); Step - 3 Next set the pin 11 as LOW for 0.5 seconds. This will turn off the buzzer for 0.5 seconds. digitalWrite(11,LOW); delay(500); The code is completed. The complete code is given in Code part of this article. Then upload the code to Arduino Uno. Connection Arduino Uno - Buzzer GND - GND (The short leg) 5V - Vcc (The long leg) For prototyping purpose use the Male/Female Jumber wire. Next I am going to interface the buzzer with tone() function 2. Buzzer With tone() Before starting we need to know about tone() and noTone() function. tone() Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified, otherwise the wave continues until a call to noTone(). The pin can be connected to a piezo buzzer or other speaker to play tones. Syntax : tone(pin_number, frequency) noTone() Stops the generation of a square wave triggered by tone(). Has no effect if no tone is being generated. Syntax : noTone(pin_number) It's time to start. Step - 1 The setup part is same as the setup part of Buzzer without tone(). So refer the Step - 1 of Buzzer without tone(). Step - 2


Next I am going to code the loop part. First I call the tone() function. It have two parameters. First one is the pin number which the buzzer is attached. Here it is 11. And second parameter is the frequency in Hertz. Here I set the frequency as 200 Hz. Alternatively you can try with different frequencies. tone(11,200); Step -3 Then add a delay of 0.5 seconds. delay(500); Step - 4 Then call the function noTone(). This will help release the pin from tone() function. This function have only one parameter. It is the pin number which the buzzer attached. noTone(11) Step - 5 Again add a delay of 0.5 seconds. delay(500); Code //Buzzer with tone(). //sketch created by Akshay Joseph void setup() { pinMode(11,OUTPUT); } void loop() { tone(11,200); delay(500); noTone(11); delay(500); } 3. Design the different patterns using LEDs and Control with help of pushbuttons.


I will show you how to generate an LED pattern with push-button using an Arduino. This project is an advancement of simple Led to multiple LEDs with Arduino and a push-button which switches them at a very fast rate. Whenever you press a push-button it generates a unique pattern that is represented with the help of LEDs. This is a very interesting project Follow the steps below to make it. Hardware Components Following are the necessary hardware components: Working Explanation S.NO Components Qty 1. Arduino Uno R3 1 2. USB Cable A/B 1 3. Push Button 1 4. Resistors (10k,470 ohm) 1,7 5. 5mm LED 7 6. Breadboard 1 7. Connecting Wires 1 As mentioned earlier as well that this project of an LED pattern is an advancement of simple LEDs to multiple LEDs. After making a simple Led project of turning it on and turning it off with the help of Arduino you can make several other projects and learn new coding with it. In Led pattern project we are using 7 LEDs connected to digital pins of Arduino and a push-button is used to generate a unique pattern on LEDs. Every time a push-button is pressed, it switches the lighting pattern from previous values to the new outputs which are the main idea of the project. This project LED pattern is a great step of practicing your programming skills and learning some new projects. Connection  STEP # 1 ( Make Push Button Connections )  Pin1 to 5V of Arduino.


 Resistor 10k B/w Pin2 of Push Btn & GND of Arduino  Pin2 is also connected to D6 of Arduino  STEP # 2 ( Make LED Connections )  Connect All -VE of LED To GND to Arduino  STEP # 3 ( Make Resistors Connections )  All Resistor’s to +VE of LED and then D7,D8,D9,D10,D11,D12,D13 of Arduino  STEP # 4 ( Upload Code ) Application  This project can be used as an indication of something like errors  With the help of this project, you can your secret lock pattern Circuit Diagram led patterns circuit Code int L1 = 13; int L2 = 12; int L3 = 11; int L4 = 10; int L5 = 9; int L6 = 8; int L7 = 7; //7 LED pin


int buttonPin = 6; //the number of the pushbutton pin int de=50; // delay time int p=0; // variable for pattem int buttonState = 0; // variable for reading the pushbutton status void setup() { pinMode(L1, OUTPUT); pinMode(L2, OUTPUT); pinMode(L3, OUTPUT); pinMode(L4, OUTPUT); pinMode(L5, OUTPUT); pinMode(L6, OUTPUT); pinMode(L7, OUTPUT); pinMode(buttonPin, INPUT); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { p++; delay(2000);


} if(p==1) { digitalWrite(L1,1); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //1 delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //2 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //3 delay(de); digitalWrite(L1,0); digitalWrite(L2,0);


digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //5 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //6 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,1); //7 delay(de);


} if(p==2) { digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,1); //7 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //6 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //5 delay(de);


digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //3 delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //2 delay(de); digitalWrite(L1,1); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0);


digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //1 delay(de); } if(p==3) { digitalWrite(L1,1); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //1 delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //2 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0);


digitalWrite(L7,0); //3 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //5 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //6 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0);


digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,1); //7 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //6 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //5 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de);


digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //3 delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //2 delay(de); } if(p==4) { digitalWrite(L1,1); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,1); //1,7


delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //2,6 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //3,5 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de); } if(p==5)


{ digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //3,5 delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //2,6 delay(de); digitalWrite(L1,1); digitalWrite(L2,0); digitalWrite(L3,0);


digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,1); //1,7 delay(de); } if(p==6) { digitalWrite(L1,1); delay(de); digitalWrite(L2,1); delay(de); digitalWrite(L3,1); delay(de); digitalWrite(L4,1); delay(de); digitalWrite(L5,1); delay(de); digitalWrite(L6,1); delay(de); digitalWrite(L7,1); //1,7 delay(de); digitalWrite(L7,0); //1,7 delay(de); digitalWrite(L6,0); delay(de); digitalWrite(L5,0); delay(de); digitalWrite(L4,0); delay(de); digitalWrite(L3,0); delay(de);


digitalWrite(L2,0); delay(de); digitalWrite(L1,0); delay(de); } if(p==7) { digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //1,7 p=0; } } 4 Experiment 4-Interfacing of 16*2 LCD with Arduino and Print “Hello World” on LCD. The LiquidCrystal library allows you to control LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. This example sketch prints \"Hello World!\" to the LCD and shows the time in seconds since the Arduino was reset.


output of the sketch on a 16x2 LCD The LCDs have a parallel interface, meaning that the microcontroller has to manipulate several interface pins at once to control the display. The interface consists of the following pins: A register select (RS) pin that controls where in the LCD's memory you're writing data to. You can select either the data register, which holds what goes on the screen, or an instruction register, which is where the LCD's controller looks for instructions on what to do next. A Read/Write (R/W) pin that selects reading mode or writing mode An Enable pin that enables writing to the registers 8 data pins (D0 -D7). The states of these pins (high or low) are the bits that you're writing to a register when you write, or the values you're reading when you read. There's also a display constrast pin (Vo), power supply pins (+5V and Gnd) and LED Backlight (Bklt+ and BKlt-) pins that you can use to power the LCD, control the display contrast, and turn on and off the LED backlight, respectively. The process of controlling the display involves putting the data that form the image of what you want to display into the data registers, then putting instructions in the instruction register. The LiquidCrystal Library simplifies this for you so you don't need to know the low-level instructions. The Hitachi-compatible LCDs can be controlled in two modes: 4-bit or 8-bit. The 4-bit mode requires seven I/O pins from the Arduino, while the 8-bit mode requires 11 pins. For displaying text on the screen, you can do most everything in 4-bit mode, so example shows how to control a 16x2 LCD in 4-bit mode.


Hardware Required  Arduino Board  LCD Screen (compatible with Hitachi HD44780 driver)  pin headers to solder to the LCD display pins  10k ohm potentiometer  220 ohm resistor  hook-up wires  breadboard Circuit Before wiring the LCD screen to your Arduino board we suggest to solder a pin header strip to the 14 (or 16) pin count connector of the LCD screen, as you can see in the image above. To wire your LCD screen to your board, connect the following pins:  LCD RS pin to digital pin 12  LCD Enable pin to digital pin 11  LCD D4 pin to digital pin 5  LCD D5 pin to digital pin 4  LCD D6 pin to digital pin 3  LCD D7 pin to digital pin 2  LCD R/W pin to GND  LCD VSS pin to GND  LCD VCC pin to 5V  LCD LED+ to 5V through a 220 ohm resistor  LCD LED- to GND Additionally, wire a 10k pot to +5V and GND, with it's wiper (output) to LCD screens VO pin (pin3). click the images to enlarge


image developed using Fritzing. For more circuit examples, see the Fritzing project page Schematic click the images to enlarge


/* LiquidCrystal Library - Hello World Demonstrates the use a 16x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. This sketch prints \"Hello World!\" to the LCD and shows the time. The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 * LCD D4 pin to digital pin 5 * LCD D5 pin to digital pin 4 * LCD D6 pin to digital pin 3 * LCD D7 pin to digital pin 2 * LCD R/W pin to ground


* LCD VSS pin to ground * LCD VCC pin to 5V * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 by Tom Igoe modified 22 Nov 2010 by Tom Igoe modified 7 Nov 2016 by Arturo Guadalupi This example code is in the public domain. http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld */ // include the library code: #include <LiquidCrystal.h> // initialize the library by associating any needed LCD interface pin // with the arduino pin number it is connected to const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print(\"hello, world!\"); } void loop() { // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis() / 1000); }


5 Interfacing of gas sensors with Arduino and serial Monitor. Components Required  Arduino Uno.  Connecting cable.  Breadboard.  MQ2 Gas sensor.  Dupont cables Interfacing of MQ2 Sensor with Arduino Connect your MQ2 sensor with the Arduino as shown in the above diagram. 1. Connect the VCC pin of the sensor to the 5V of the Arduino. 2. Connect the GND of the sensor to the GND of the Arduino. 3. Connect the digital pin of the sensor D0 to the digital pin number 8 of the Arduino 4. Connect the analog pin of the sensor to the analog pin A0 of the Arduino. Code & Software Download and install Arduino Software in your system. Upload the below code to your Arduino. #define MQ2pin (0) float sensorValue; //variable to store sensor value void setup() { Serial.begin(9600); // sets the serial port to 9600 Serial.println(\"Gas sensor warming up!\"); delay(20000); // allow the MQ-2 to warm up } void loop() {


sensorValue = analogRead(MQ2pin); // read analog input pin 0 Serial.print(\"Sensor Value: \"); Serial.print(sensorValue); if(sensorValue > 200) { Serial.print(\" | Smoke detected!\"); } Serial.println(\"\"); delay(2000); // wait 2s for next reading } 6 Interface seven segment display with Arduino and print count 1 to 9 on display. A seven segment display got its name from the very fact that it got seven illuminating segments. Each of these segments has a LED (Light Emitting Diode), hence the lighting. The LEDs are so fabricated that lighting of each LED is contained to its own segment. The important thing to notice here that the LEDs in any seven segment display are arranged in common anode mode (common positive) or common cathode mode (common negative).


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook