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

light intensity and ultrasonic distance sensor

jhihi

Uploaded by

Arjun Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
4 views

light intensity and ultrasonic distance sensor

jhihi

Uploaded by

Arjun Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Controllers 4.11.3. Arduino LDR Arduino LDR (Light Dependent Resistor) project uses the photoresistor to light an LED. The LED will light up whenever there is dark or no light over the sensor. It is defined as a light- controlled resistor, which is also called as LDR. It is a variable resistor that controls the resistance in accordance with the received light intensity. It means, the resistance decreases as intensity of light increases. Example: Connect an LDR to show dark and light when the light falls on the sensor. Hardware required: ‘The components required for the project are listed below: ; > vvvyv > Connection diagram: ‘The connection diagram of the project is shown in Figure 4.17. 1x Red LED 1x 220.0 Resistor ! 1 * 10 kQ Ohm Resistor Arduino UNO R3 board Jump wires 1 = Photoresistor De Pw 2200 10 PwMySs 011 PmwMost D12miso) \/ ep prarscx} GRO Connection steps: The connection of the above project is discussed below: > Step 1: The postive leg of the LED is connected in series with the resistor to pin number 12 of the Arduino board, > Step 2: The negative leg ofthe LED is connected tothe Ground, Re ‘Step 3: One edge of the photoresstr is connected to the SV pin on the Arduino board, Step 4: A 10 k0 resistor is attached in series with the other edge of the photoresi ries with the other edge of ores and connected to the GND, meteors > Step 5: The edge of the photoresisor is connected to the analog pin AO, Arduino code ‘The Arduino code forthe above circuits shown below: const int LEDpin « 12) const int photoPIN = A0; void setup() // Anitializing the serial communication: Serial.begin(9600) ; pinMode(photoPIN, INPUT) ; pinMode(LEDpin, OUTPUT) ; y void leopt) { // read the sensor: Amt seneorstatue = analogRead(photoPIN) ; 7/ now, it will check the reading or status of the sensor is < 200 77 3f it is, LED will be HIGH Af (wensorstatus <200) { digitalWrite(LEDpin, HIGH); // LED is on Serial.printn(* LED is ON, status of sensor 4 DARK"); 2 au ( digitalWrite(LitDpin, LOW): gerial.printin(® © Res "The output on the serial monitor will appear as follows LED de ON, statua of sensor is DARK LED Le ON, atatua of LED te ON, status of 4.11.4, Arduino Ultrasonic Distance Sensor "The Ultrasonic sensor of 1C-SROM is used to measure the distance of the object using SONAR, It emits the Ultrasound at a frequency of 40 A7fs oF 40000 Hf, the Frequency travels through the air and strikes the object on its path. The rays bounce back from the object and reach back tothe module, The four terminals of the HC-SRO4 are VCC, TRIG, ECHO, and GND, The voltge supply or VCC is +5V. The ECHO and TRIG terminals can be connected to any ofthe digal VO pins on the specific Arduino boord, > The Ultrasonic sensors work best for medium ranges, > The resolution is 0.3em, > The medium ranges of the sensor are 10cm to 3m, It works best a this duration, > The maximum range the sensor may detect is 4.5m, (@) Working of ultrasonic sensor: Please refer to the working principle of ultrasonic sensor described in Chapter 1.12.13 0 Page 1.92, (6) Structure of ultrasonic sensor: ‘The structure of HC-SRO4 is shown in Figure 4.18 Figure 418 HC-SRO4 Ultrasonic sensor module (¢) Ultrasone sensor timing diagram: ‘To measure the distance using an ultrasonic sensor, the following steps are involved: > The TRIG pin is set to HIGH for a short period (typically about 3 ys to 100 ps). > As-soon as the ‘TRIG pin is sot to LOW, the ultrasonic sensor sends out sound pulses and sets the ECHO pin to HIGH, 2 When the sensor receives the reflected pulses it sets the ECHO pin to LOW. » The time duration for which the ECHO pin remains HIGH is measured The timing diagram of the ultrasonic sensor HC-SRO4 is shown in Figure 4.19 Trg pin Ons Wager pulse Pusses trom _] t____ ‘module "Eight 40kHz sound wave generated fom HG-SRO# ECHO pin Time taken by pulse to leave and return back Pipure 4.19 Timing diagram of the HC-SR04 ultrasonic sensor module Frample: Creating the Arduino ultrasonic sensor to measure distance, Nortwure required: ‘i components required to ereate the project are listed below: 1» UNO R3 board (Any Arduino board) > AK > Jump wires > Ultrasonic sensor HC-SRO4 > Breadboard Principles IL will send out the burst of 8 be further received ‘output The TRIG (triggered) pin needs to be set to HIGH f ‘ele called the sonic burst, whieh will travel at the sound speed, It ‘ythe FCHO pin, The time traveted by the sound wave is considered the ECHO pit ‘he pulsetng) funtion will be used t0 read the time fromm the output ofthe ECHO pin. I vill wait tor the spectied pin to go LIIGH and LOW. ‘The funetion would retara the ting at et, ‘The TRIG pin is set LOW for 4 microseconds and th "ning willbe cakwlated in microseconds Procedures len HIGH for 15 mieroseconds. The The steps to connect the Utrasonie sensor to the board are listed below! he VCE pin of the HHCSROM is conned tothe $V oF the Arduino board (0 provite Power, LT > ‘The GND pin ofthe HC-SROM fs connected 0 the GND of the Arduino board for completing the circuit and grounding, > The TRIG pin ofthe IIC-SRO4 is conneeted to pin 6 of the Arduino board to initiate the ultrasonic pulse transmission, > Tho ECHO pin af the HC=SRO4 is connected to pin $ of the Ard any! measure the returning vltrasonie pulse. Arduino code: ‘The Arduino code for the above circuit is sho define KcHopin 9 // it defines the ECHO pin of the sensor to pin 9 of Arduino Hdofine TRIGpin 8 defined, long duration; // variable for the duration of sound wave travel int distance; // variable for the distance meaaurement up) yo board to receive below: // The variable has been void { pinNode(TRrGpin, OUTPUT); // It seta the ECHO pin as ourpUT pinMode(BCHopin, INPUT); // It sete the TRIG pin as INPUT Serial.begin(9600); // Serial Communication at the rate of 9600 bps Serial.printIn ("Test of the Ultrasonic Roa"), // Tt will appear on Serial Monitor rial.printin ("with the Arduino UNO R3 board); nor HC- } votd loop( ) ( (7 Av Liver wets the TRIG pin at LOW for 2 microaeconds digitalWrite(TRIGpin, LOW) ; delayticroseconds (4) ; \ | oe met TRI sly at MN tan aN WA vameeonetn Mat eatve Lee Critaetiy, LANDY etayNtoeommenita th) MOT Cadma Ha (rerapin, LOW) FEAL WENT yoo Che KeMO ppt and WELL vetinnny the Vine duration = puta 47 dint (CHOPIN, TAH) » ve tormuta, Matance » duration®(0.034/2)) // (apoed tn inieroneeonde) 47 Speod oF wound wave (140 W/u) divided by 2 (torward and backward bomnee) ¢/ To display the distance on Serial Monitor Serial.print (*Dietance: *); eal print (distance) ; ehal.peintin(® emt); divtance ) ‘Steps to uptoad che code ro the projects ‘The steps are listed below: > The Arduino IDE is opened, > The type of boar is selected by navigating to Toots —+ Board —+ Arduino UNO. > ‘The port is selevted by navigating to Tools =+ Port =+ COM, > The sketch is uploaded to the connection diagram, Connection diagram: ‘The connection diagram is shown in Figure 4.20, Result: //pecitied unit of ‘The output on the serial monitor will appear as follows: Distance: Distance: 110 em Distance: 110 cm Distance: 110 em Distance: 110 em Oem vt Ly Ld 3a fers bo Utlrasonie sonsor fersrs own Hic-sro4 Jane | — erst apa of Figure 420 Arduino UNO connected to an HCSRO ultrasonic sensor 4a . Arduino Ultrasonic Range Finder {Im the Arduino Ultrasonie Distance Sensor setup, a threesterminal Ultrasonic sensor will ‘be utilized, depicted below: {ths thees terminal GND (Ground), $V, and SIG (signal), The process and the function ofthis sensor is similar othe Ultrasonic Distance Sensor. The frequency waves travel through ‘he alr and trike the object om its path. The waves bounce back from the abject and reach back to the module Figure 4.21 Utrasonie distance sensor ' ‘he Utrasonie Range sensor pings the obstacles or objects with the ultrasound Ut detects {he range fom 3 em or 400 em, The example a such a sensor i: SENIGDSN, Iti tsenany

You might also like