End Presentation

Lecture 3: Switches

CSC 321: Embedded Sysytem

First Semester 2020/2021


TWiki Slide Show
Next
Switches
A Switch is a device which is designed to interrupt the current flow of electrons in a circuit.

Switches are essentially binary devices: they are either completely on (“closed”) or completely off (“open”).

A Switch simply can make or break an electrical circuit.

Every electrical and electronics application uses at least one switch to perform ON and OFF operation of the device.

Switches are a part of the control system and without it, control operation cannot be achieved.

When the contacts of a switch are closed, the switch creates a closed path for the current to flow and hence load consumes the power from source.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 1 of 15





















TWiki Slide Show
Next
Types of Switches
• Switches exist in various incarnation.

• A Switch object is used to control a push-button switch.

• There are the simple mechanical switches: on/off or push button switches

• There are also switches than turn on or off with various external conditions:

• Temperature

• infra red radiation (e.g. the Passive Infrared Sensor or PIR sensor)

• Hall switches detecting magnetic field

• microphone switches which turn on when a certain noise level is detected

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 2 of 15





















TWiki Slide Show
Next
Types of Switches

Toggle Switches

Toggle Switch

Toggle switches are actuated by a lever angled in one of two or more positions.

The common light switch used in household wiring is an example of a toggle switch.

Pushbutton Switches

Pushbutton Switch

Pushbutton switches are two-position devices actuated with a button that is pressed and released.

Most pushbutton switches have an internal spring mechanism returning the button to its “out,”

or “unpressed,” position, for momentary operation.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 3 of 15





















TWiki Slide Show
Next
Types of Switches

Selector Switches

Selector Switch

Selector switches are actuated with a rotary knob or lever of some sort to select one of two or more positions.

Joystick Switches

Joystick Switch

A joystick switch is actuated by a lever free to move in more than one axis of motion.

One or more of several switch contact mechanisms are actuated depending on

which way the lever is pushed, and sometimes by how far it is pushed.

Pressure Switches

Pressure Switch

Gas or liquid pressure can be used to actuate a switch mechanism if that pressure is applied to a piston,

diaphragm, or bellows, which converts pressure to mechanical force.

Temperature Switches

Temperature Switch

An inexpensive temperature-sensing mechanism is the “bimetallic strip:” a thin strip of two metals,

joined back-to-back, each metal having a different rate of thermal expansion.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 4 of 15





















TWiki Slide Show
Next
The Push Button & PIR
pushbutton.png pir.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 5 of 15





















TWiki Slide Show
Next
Digital Inputs
When you try to use a microcontroller to detect activity in the physical world,

the simplest activity you can perceive is whether an activity is True or False.

  • Is the audience in the room or outside?
  • Are they touching the table?
  • Is the door open or closed?
In these cases, you can use the digital input or the switch to determine the state.

Schematic of a Digital Input to a microcontroller

From the schematic diagram current has two directions it can go to ground:
through the resistor or through the microcontroller.

When the switch is closed, the current will follow the path of least resistance, to the microcontroller pin,
and the microcontroller can then read the voltage. The microcontroller pin will then read as high voltage or HIGH.

When the switch is open, the resistor connects the digital input to ground, so that it reads as zero voltage, or LOW.

• A digital input is a board pin which can read if it sees a high (on) or low (off) logic level connected to it.

• For example if you connect a button to a digital input you can detect when it's pressed and released.

• Also if you connect a PIR(passive infrared sensor) to a digital input, it can detect the infrared (IR) light radiating from objects in its field of view.

• MicroPython makes it just as easy to use a pin digital inputs as it does outputs.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 6 of 15





















TWiki Slide Show
Next
The Push Button
• The push button switch is usually used to turn on and off the control circuit, and it is a kind of control switch appliance that is widely used.

• This is very similar to switching a LED on or off.

• A single GPIO line is used.

• The pin in programmed as a digital input and we can add a pullup or pulldown resistor:

_PB_PIN = 22 
pushButton = Pin(_PB_PIN, Pin.IN, Pin.PULL_UP)

• Once the pushButton pin is defined we can get its current state with:

state = pushButton.value()

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 7 of 15





















TWiki Slide Show
Next
Pull-up Resistors
• Pull-up resistors are very common when using microcontrollers (MCUs) or any digital logic device.`

• The value of the pull-up resistor needs to be chosen to satisfy two conditions:

When the button is pressed, the input pin is pulled low. The value of resistor R1 controls how much current you want to flow from

VCC, through the button, and then to ground.

When the button is not pressed, the input pin is pulled high. The value of the pull-up resistor controls the voltage on the input pin.

pullup.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 8 of 15





















TWiki Slide Show
Next
Interrupts
• Interrupts are useful for making things happen automatically in microcontroller programs

• With interrupts you don’t need to constantly check the current pin value.

• When a change is detected, an event is triggered (a function is called).

• When an interrupt happens, the processor stops the execution of the main program to execute a task,

and then gets back to the main program

• This is especially useful to trigger an action whenever motion is detected or

whenever a pushbutton is pressed without the need for constantly checking its state.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 9 of 15





















TWiki Slide Show
Next
Interrupt Method
The irq() method accepts the following arguments:
  • trigger: this defines the trigger mode. There are 3 different conditions:
  • Pin.IRQ_FALLING: to trigger the interrupt whenever the pin goes from HIGH to LOW;
  • Pin.IRQ_RISING: to trigger the interrupt whenever the pin goes from LOW to HIGH.
  • 3 or Pin.IRQ_FALLING | Pin.IRQ_RISING: to trigger the interrupt in both edges (this means, when any change is detected)
  • handler: this is a function that will be called when an interrupt is detected, in this case the handle_interrupt() function.
pushButton.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 10 of 15





















TWiki Slide Show
Next
The PIR Sensor
• PIR sensors allow you to sense motion, almost always used to detect whether a human has moved in or out of the sensors range.

• They are small, inexpensive, low-power, easy to use and don't wear out.

• They are often referred to as PIR, "Passive Infrared", "Pyroelectric", or "IR motion" sensors.

• PIR is an electronic sensor which detects the changes in the infrared light across certain

distance and gives out an electrical signal at its output in response to a detected IR signal.

• It can detect any infrared emitting object(Objects that generate heat) such as human beings or

animals if it is the range of the sensor, or moves away from the range, or moves within the range of the sensor.

• The radiation of the infrared object should be strongest at a wavelength of 9.4μm.

• Infrared in this range will not pass through many types of material that pass visible light such as ordinary window glass and plastic.

• However it will pass through, with some attenuation, material that is opaque to visible light such as germanium and silicon.

pir.png pir_back.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 11 of 15





















TWiki Slide Show
Next

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 12 of 15





















TWiki Slide Show
Next
PIR Sensor Features
  • Wide range on input voltage varying from 4.V to 12V (+5V recommended)
  • Output voltage is High/Low (3.3V TTL)
  • Can distinguish between object movement and human movement
  • Has to operating modes - Repeatable(H) and Non- Repeatable(H)
  • Cover distance of about 120° and 7 meters
  • Low power consumption of 65mA
  • Operating temperature from -20° to +80° Celsius

Repeatable(H) mode

In Repeatable(H) mode the output pin Dout will go high (3.3V) when a person is detected within range

It goes low after a particular time (time is set by “Off time control” potentiometer).

In this mode the output pin will go high irrespective of whether the person is still present inside the range or has left the area.

The sensitivity can be set using the “sensitivity control” potentiometer

Non- Repeatable(L) mode

In “I” mode the output pin Dout will go high (3.3V) when a person is detected within range

It will stay high as long as he/she stays within the limit of the Sensors range.

Once the person has left the area the pin will go low after the particular time which can be set using the potentiometer.

The sensitivity can be set using the “sensitivity control” potentiometer

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 13 of 15





















TWiki Slide Show
Next
PIR Sensitive Crystal
PIR-Sensor-Image.jpg

There are two important materials present in the sensor:

  • The pyroelectric crystal which can detect the heat signatures from a living organism (humans/animals)
  • The Fresnel lenses which can widen the range of the sensor.
• The dark portion of the metal is where the IR sensitive crystal is housed,

• The sensitive crystal can detect the level of infrared in the surroundings.

• It actually houses two pyroelectic sensors for detecting moving objects.

• If one of the sensitive crystals detects change in infrared (increment or decrement) than the other sensitive crystal,

the output gets triggered.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 14 of 15





















TWiki Slide Show
Next
PIR to MCU
• A single GPIO line is used.

• The pin in programmed as a digital input and we can add a pullup or pulldown resistor:

_IR_PIN = 16
pir_sensor = Pin(_PB_PIN, Pin.IN, Pin.PULL_UP)

• Once the pushButton pin is defined we can get its current state with:

state = pir_sensor.value()


First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 15 of 15





















First slide Previous End Presentation






























-- Isaac Armah-Mensah - 2021-05-25

Comments


I Attachment History Action Size Date Who Comment
JPEGjpg PIR-Sensor-Image.jpg r1 manage 50.0 K 2023-11-27 - 09:29 UliRaich  
PNGpng pir.png r1 manage 319.4 K 2023-11-27 - 09:34 UliRaich  
PNGpng pir_back.png r1 manage 336.6 K 2023-11-27 - 09:34 UliRaich  
PNGpng pullup.png r1 manage 2.0 K 2023-11-27 - 09:27 UliRaich  
PNGpng pushbutton.png r1 manage 154.5 K 2023-11-27 - 09:10 UliRaich  

This topic: IoT_Course_English > WebHome > Slides > SwitchesWithESP32
Topic revision: r3 - 2023-11-27 - UliRaich
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback