IoT using Arduino - Unit 4 Interfacing Sensors and Actuators PDF
Document Details
Chitkara University
Tags
Summary
This document is a presentation or lecture notes on concepts of IoT using Arduino, including various sensors and actuators. It provides a good overview of components, types, and usage in electronic systems.
Full Transcript
Hello Students! Welcome to IoT class! 1 IoT using Arduino Topic: : Interfacing Arduino Uno with Sensors and Actuators Unit 4: Interfacing Arduino with Sensors and Actuators Overview of Sensors working , sensor interfacing, communicati...
Hello Students! Welcome to IoT class! 1 IoT using Arduino Topic: : Interfacing Arduino Uno with Sensors and Actuators Unit 4: Interfacing Arduino with Sensors and Actuators Overview of Sensors working , sensor interfacing, communication protocols. Analog and Digital Sensors Interfacing of temperature sensor Interfacing of ultrasonic Motion Sensor, IR, PIR sensors with Arduino Interfacing of Actuators with Arduino, servo motor Interfacing of Relay with Arduino- relay and its types Understanding Sensors and Their Purpose Sensors are devices used to measure properties such as pressure, position, temperature, acceleration etc. and to respond with feedback. They are basically chips/modules that work by observing the changes in the physical world and sending feedback to the microprocessor. The sensors must be provided with a power supply in order to work. Sensors are the eyes and ears of our devices, providing valuable data from the physical world. They monitor environmental factors, detect changes, and relay this info to other parts of the system. What sensor you choose depends largely on what you want to measure. Types of Sensors The variety of sensors can make your head spin! Here's a snapshot of some of the most common ones: 1. Temperature Sensors: As the name suggests, these track temperature variations. They're the bread and butter of HVAC systems and many industrial processes. 2. Proximity Sensors: Handy for robotics and security systems, these sensors detect the presence or absence of an object within a certain range. 3. Pressure Sensors: Monitoring air or fluid pressure is their forte. You'll find them in vehicles, medical devices, and weather monitoring systems. 4. Light Sensors: These detect light levels and are commonly used in automatic lighting systems and cameras. Wired/wireless Sensors And the sensors are divided into the wireless sensor and conventional wired sensor. Conventional wired sensors connect the device that receives input, has the advantage of high accuracy, durable and can be used many times without replacement. The wireless sensor is a wireless data communication collector that integrates the functions of data acquisition, data management and data communication, has the advantage of low-power operation, wireless data transport, no wiring, flexible installation and debugging and so on. Analog and Digital Sensors: Microcontrollers accept two types of sensors based on their input i.e. analog or digital. Analog Sensors measure the external parameters and give an analog voltage as an output. They produce a continuous output signal or voltage which is proportional to the quantity being measured. The output voltage may be from the range of 0 to 5V. Low logic 0 (0V-3.5V) and High logic (3.5V-5V). Digital Sensors act as electronic sensors where data is digitally converted and transmitted. Digital sensors produce discrete values (0s and 1s) or ‘binary’ signals. Communication protocols The communication protocols are divided into wireless communication protocols and wired communication protocols. The communication protocol defines – the format used by the data unit, – the information and meaning that the information unit should contain, – the connection mode, and – the timing when the information is sent and received, to ensure the smooth transfer of data to the determined place. The types of communication protocols have RFID, infrared, ZigBee, Bluetooth, GPRS,4G, Wifi and NB-IoT. The communication protocols have MBus, USB, RS232, RS485 and ethernet. Wireless Protocols 1. RFID (Radio Frequency Identification): RFID is used for contactless data exchange, most commonly in access control and asset tracking systems. 2. Infrared: Infrared communication is used in short-range applications, such as television remotes and short-range data transfer between devices. 3. ZigBee: ZigBee is a low-power, low-data-rate wireless network mainly used in industrial settings, smart homes, and remote control systems. 4. Bluetooth: You probably know this one! Bluetooth is used for short-range, point-to-point, and point-to-multipoint communication. It's perfect for connecting peripherals like keyboards, mice, and headphones. 5. GPRS (General Packet Radio Service): GPRS is used in mobile communication for internet access, multimedia messaging, and location-based services. 6. 4G: The fourth generation of cellular technology, 4G provides mobile ultra-broadband internet access for mobile phones, laptops, and other mobile devices. 7. Wifi: Wifi is a wireless networking protocol that allows devices to communicate without direct cable connections. It's extensively used in home networks, office networks, and public hotspots. 8. NB-IoT (Narrowband Internet of Things): NB-IoT is a low-power wide-area network protocol designed to connect devices across long distances in hard-to-reach areas. It's ideal for IoT applications. Wired Protocols Even in our wireless world, wired protocols still have a crucial role, particularly in industrial and high-data-rate applications. 1. MBus (Meter-Bus): MBus is a European standard for remote reading of heat meters and other consumption meters. 2. USB (Universal Serial Bus): USB is used for connection, communication, and power supply between computers and their peripheral devices. 3. RS232: This is a standard for serial communication transmission of data. It's traditionally used in computer serial ports. 4. RS485: Similar to RS232, RS485 supports more nodes per network and longer cable lengths. It's used in industrial control systems and building automation. 5. Ethernet: Ethernet is widely used in local area networks (LANs). It provides high speed and reliable communication between devices. Selecting the appropriate protocol will largely depend on the application and the environment. Always consider factors like range, power consumption, data rate, and the type of devices being connected when making your choice. Interfacing of temperature sensor Schematic Sketch char degree=176; //ASCII Value of Degree const int sensor=A1; void setup() { pinMode(sensor, INPUT); Serial.begin(9600); } void loop() { int tmp = analogRead(sensor);//Reading data from the sensor. This voltage is stored as a 10bit number. float voltage = (tmp * 5.0)/1024;//(5*temp)/1024 is to convert the 10 bit number to a voltage reading. float milliVolt = voltage * 1000;//This is multiplied by 1000 to convert it to millivolt. float tmpCel = (milliVolt-500)/10 ; Serial.print("Celsius: "); Serial.print(tmpCel); Serial.println(degree); delay(1000); } PIR (Passive Infra Red) Motion Sensors A passive infrared sensor is an electronic sensor that measures infrared light radiating from objects. It is used in security alarms and automatic lighting applications. The PIR sensor consist of 3 pins The PIR sensor has two slots that are sensitive to IR. Pin1 (VCC): This is a source terminal of the device which is connected to the 5V DC supply. Pin2 (OUT): This is the o/p pin of the sensor. Pin3 (GND): This is a ground pin. 14 PIR (Passive Infra Red) Motion Sensors A PIR sensor includes two main parts like pyroelectric sensor and fresnel lens. The sensor is a round metal including a rectangular crystal within the center. A fresnel lens is a special lens that focuses the IR signals on the pyroelectric sensor. The pyroelectric sensor is capable of detecting different infrared radiation levels. PIR (Passive Infra Red) Motion Sensors Pyroelectric sensor has a window including two rectangular slots & allows IR radiation to flow. There are two separate IR sensor electrodes where one electrode is responsible for generating the positive output & the other electrode is responsible for generating the negative output. Whenever there is no movement in the region, then both slots can detect a similar amount of IR radiation which results in zero o/p signal. when a human body moves in the region of the sensor, first it interrupts half of the sensor. So it causes a positive differential change between the two halves. Once the human body interrupts the other half of the sensor then the opposite happens & the sensor generates a negative differential change. So by reading this change within voltage, then motion is detected. The Fresnel lens in the sensor increases the sensor’s field & range of view of the sensor. PIR Motion Sensors: Lenses The lens can change the range, sensing pattern. Lens condenses a large area (such as a landscape) into a small one lens The Field of View (FOV) of a Passive Infrared (PIR) sensor refers to the angular range within which the sensor can detect infrared radiation from moving objects 17 Specifications of PIR sensor The recommended input voltage supply is +5V. The output voltage is 3.3V. It can differentiate between the movement of an object & human. The motion sensor has a detection range of 3 to 7m. Working temperature ranges from -20-+80°C. Low power utilization – 65mA. Field of View is 90 to 180 degrees horizontally. Interfacing PIR Sensor Schematic Sketch int sensorState = 0; void setup() { pinMode(2, INPUT); pinMode(LED_BUILTIN, OUTPUT); } void loop() { // read the state of the sensor/digital input sensorState = digitalRead(2); // check if sensor pin is HIGH. if it is, set the LED on. if (sensorState == HIGH) { digitalWrite(LED_BUILTIN, HIGH); } else { digitalWrite(LED_BUILTIN, LOW); } delay(10); // Delay a little bit to improve simulation performance } Ultrasonic Sensor Ultrasonic Sensor are electronic devices that calculate the target’s distance by emission of ultrasonic sound waves and convert those waves into electrical signals. The speed of emitted ultrasonic waves traveling speed is faster than the audible sound. There are mainly two essential elements which are the transmitter and receiver. Using the piezoelectric crystals, the transmitter generates sound, and from there it travels to the target and gets back to the receiver component. Ultrasonic sensors are used in robotics, automation, and other projects where distance measurement is required. Ultrasonic Sensor Vcc – This pin has to be connected to a power supply +5V. TRIG – This pin is used to receive controlling signals from the Arduino board. This is the triggering input pin of the sensor ECHO – This pin is used for sending signals to the Arduino board where the Arduino calculates the pulse duration to know the distance. This pin is the ECHO output of the sensor. GND – This pin has to be connected to the ground. Ultrasonic Sensor In ultrasonic sensor, the sensor calculates the amount of time required for sound emission to travel from transmitter to receiver. The ultrasonic sensor emits a high-frequency sound wave when the trigPin is set high. This sound wave travels through the air, hits an object, and reflects back to the sensor. The echoPin detects the returning wave, and the Arduino measures the time it takes for the wave to return (duration). The distance between transmitter and receiver is given as D = 1/2 T * C Where ‘T’ corresponds to time measured in seconds ‘C’ corresponds to sound speed = 343 measured in m/sec Ultrasonic Sensor Specifications The sensing range lies between 40 cm to 300 cm. The response time is between 50 milliseconds to 200 milliseconds. The Beam angle is around 50. It operates within the voltage range of 20 VDC to 30 VDC The frequency of the ultrasound wave is 120 kHz The voltage of sensor output is between 0 VDC – 10 VDC Operating temperature range is -250C to +700C Interfacing Ultrasonic Sensor Schematic const int trigPin = 9; const int echoPin = 10; // defining variables long duration; int distance; void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(echoPin, INPUT); // Sets the echoPin as an Input Serial.begin(9600); // Starts the serial communication } void loop() { // Clears the trigPin digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin on HIGH state for 10 micro seconds digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin, HIGH); // Calculating the distance distance= duration*0.034/2; // Prints the distance on the Serial Monitor Serial.print("Distance: "); Serial.println(distance); } IR Sensor IR sensor is an electronic device, that emits the light in order to sense some object of the surroundings. An IR sensor can measure the heat of an object as well as detects the motion. IR sensor has two main parts: IR transmitter and IR receiver. Transmitter is an IR LED or laser diode. The detector is an IR photodiode or phototransistor. Photodiode is sensitive to IR light of the same wavelength which is emitted by the IR LED. When IR light falls on the photodiode, the resistances and the output voltages will change in proportion to the magnitude of the IR light received. Working of IR Sensor IR Sensor Module IR Sensor Schematic Sketch int IRsensor= 2; int DCwater_pump =7; void setup() { pinMode(IRsensor,INPUT); pinMode(DCwater_pump, OUTPUT); irrecv.enableIRIn(); } int readPin = 0; void loop() { readPin = digitalRead(IRsensor); if (readPin == HIGH) { digitalWrite(DCwater_pump,HIGH); delay(500); } else { digitalWrite(DCwater_pump,LOW); delay(500); } } Servo Motor A servo motor is used to precisely control the position, speed, and angular rotation of mechanical systems. It's designed to provide accurate control of its output shaft, allowing for precise angular position control. Specifications of MG90S (Micro servo): Weight: 13 gm Operating voltage: 4.8V~ 6.6V It offers torque of 1.8 kg/cm High resolution No. Pins Colour Accurate positioning 1 Signal Yellow Fast control response 2 VCC Red Constant torque throughout the servo travel range 3 GND Brown Excellent holding power Metal gear Servo Motor Working Standard DC Servo Motor Working A servo motor receives PWM (Pulse Width Modulation) signals to determine its angle of rotation. The PWM signal is a square wave with a variable duty cycle, where the width of the high signal (the "on" time) corresponds to a specific angle. This signal is usually generated by Arduino. When the PWM signal is fed to the servo motor's control input the motor's control circuit interprets it as a command to move to a particular angle. The control circuit measures the duration of the high part (1 to 2 milliseconds) of the PWM signal, which corresponds to the desired angle. The control circuit then compares this measured duration with the center position (typically 1.5 milliseconds) and adjusts the motor's shaft to move towards the desired angle. If the duration of the high part of the PWM signal is shorter than the center position, the motor turns in one direction; if it's longer, the motor turns in the opposite direction. The servo motor continuously adjusts its position to match the incoming PWM signal. As the duty cycle of the PWM changes, the motor's shaft rotates accordingly. This closed-loop control mechanism ensures that the motor accurately follows the input signal, allowing for precise and repeatable angular positioning. Interfacing Servo Motor Schematic Sketch #include Servo myservo; // Object [myservo] of Servo Library is created // OOPs Concept void setup() { myservo.attach(9); } void loop() { myservo.write(45); delay(1000); myservo.write(90); delay(1000); myservo.write(135); delay(1000); myservo.write(180); // Servo Motor Can Rotate maximum 180 degree. delay(1000); Relay A relay is an electrical switch that can be used to control devices and systems that use higher voltages. A relay is a single device with an electromagnet and a switch. It uses an electromagnet to open and close a set of electrical contacts. When a small current flows through the first circuit, the electromagnet is energized, creating a magnetic field around it. The energized electromagnet attracts the second circuit’s contact, closing the switch and allowing a large current to flow. When the current in the first circuit stops flowing, the contact returns to its original position, reopening the second circuit. Relay Module The relay module input voltage is usually DC. The electrical load that a relay will control can be either AC or DC A relay module is available in an array of input voltage ratings: It can be a 3.2V or 5V relay module for low power switching, or it can be a 12 or 24V relay module for heavy- duty systems. The relay module information is printed on the surface of the device and includes the input voltage rating, switch voltage, and current limit. Relay Module Construction Relay modules contain other components than the relay unit. These include indicator LEDs, protection diodes, transistors, resistors, and other parts. Indicator LEDs: The power LED will light up when the module is powered on. The status LED will light up when the relay is activated. Output Terminal Block (NC, COM, and NO) Input side consists of 3 jumper pins, and an output side has 3 screw terminals. The module operates on 5 volts and draws approximately 70 mA when the relay is activated. The module also includes a flyback diode that is connected in parallel with the relay coil to safely shunt current when the relay coil is de-energized. Relay Module Pin Configuration Power Pins: GND is the common ground pin. VCC pin provides power to the module. Control Pin: IN pin is used to control the relay. This is an active low pin, which means that pulling it LOW activates the relay and pulling it HIGH deactivates it. Output Terminals: COM terminal connects to the device you intend to control. NC terminal is normally connected to the COM terminal, unless you activate the relay, which breaks the connection. NO terminal is normally open, unless you activate the relay that connects it to the COM terminal. Types of Relays Interfacing Relay Schematic Sketch void setup() { pinMode(11, OUTPUT); } void loop() { digitalWrite(11, 1); delay(1000); // Wait for 1000 millisecond(s) digitalWrite(11, 0); delay(1000); // Wait for 1000 millisecond(s) }