Home Automation and Electronics for Starters (Extract)

Page 1

Home Automation and Electronics for Starters

Projects with Arduino, ESPHome, Home Assistant, and Raspberry Pi & Co. WITH MANY VIDEO TUTORIALS

Edi’s Techlab
booksbooks

My name is Thomas Edlinger, born in Austria and I live in Switzerland since 2004. As an electrical engineer, I work full-time in the semiconductor field. In June 2019 I decided to start with my YouTube channel “Edi'sTechlab”.This channel is mainly about home automation in the DIYarea. From my own experience I know that the combination of video and written instructions is unbeatable and simplifies the reconstruction of projects many times over. For most of the projects you will find here in the book, you will also find a corresponding video on my YouTube channel. The book covers all topics in much more detail and provides additional background knowledge. As a hobby, I have been involved with home automation for many years. Since my colleagues asked me several times about the functioning of sensors and home electronics, I decided to share my knowledge with you. The decision to make YouTube videos was made quickly - the implementation, however, was not so easy, especially at the beginning. As I quickly discovered, making videos is not as trivial as I initially imagined. In addition, I was completely lacking in experience when it came to editing videos. So I had to learn a lot of things that had nothing to do with electronics and it took quite some time.After a few initial difficulties it went then nevertheless quite well and I had found large fun to stand before as well as behind the camera. First comments and praise showed me to be on the right track and motivated me to continue. An initially small and steadily growing community has emerged and continues to grow. I hope that with this book I can help many newcomers and hobby electronics enthusiasts on their way into home automation and that together as Edi's Techlab community we can help each other and enrich each other with project ideas.

Thank you and .....EVERYONE CAN DO IT!!!

Yours Edi.

A4
ANALOGIN WWW.ARDUINO.CC-MADEINITALY ICSP 2
A5
Author

About the book

In this book I explain in each chapter first some basics with simple examples and then with a project the practical application. If the code is a bit longer, you can find the link to Github where you can download it. This book is written for absolute beginners and no prior knowledge is needed. I use different hints in this book to visually highlight what is most important. I would like to present you all the hints used in this book with a short description.

Version note

Because the Arduino IDE and the libraries are all about tinkering projects, it sometimes happens that the sketch no longer works after an update. Therefore please always check the versions I give, because they are tested and work.

Note

Show you succinctly how something works with a simple explanation.

ATTENTION

The most important sign in the whole book, if you do not follow what is written here, problems can occur or it can even be dangerous.

3
EVERYONE CAN DO IT!!!!

Task

Here you can find more examples and exercises on the topic.

Source Code

https://github.com/Edistechlab/

Here you can find the sketch for the current theme, if the code is longer, then you find here the link to Github for download.

/*

Project: DHT11 Temperature and humidity sensor

Author: Thomas Edlinger for www.edistechlab.com

Date: Created 29.08.2020

Version: V1.0

*/ void setup() { } void loop() { }

Needed parts

Here you can find the links to the needed parts. The links are marked with an asterisk which means that they are so called affiliate links. If you place an order I get a small share without any additional costs for you. With this you can also support Edi's Techlab.

© Copyright 2024 - Copyright notice

All contents of this book, in particular texts, photographs and graphics, are protected by copyright. Copyright is held by Thomas Edlinger, unless explicitly stated otherwise. Please ask me if you want to use the contents of this book.

info@edistechlab.com

- I use theAdfruit libraries a lot in this book, if you want to support them, you can buy the parts from them.

https://www.adafruit.com

- I created the book and all graphics with software fromAffinity

First edition, July 2022 - English version, March 2024, translated by Olesia Efimova o.efimova.v@yandex.ru YouTube @olesia_dotravel IG @olesia_dotravel

Changes:

New added: E-ink Displays,Arduino Nano and Nano ESP32, digital Potenziometer

These links are NOT sponsored, but I think these programs are worth recommending.

4
5 Table of content EVERYONE CAN DO IT!!!! Electronicsbasics 31 Current and voltage..........................................................................................32 Electric current I .......................................................................................................33 Current in a circuit ................................................................................................................................33 Current direction (technical/physical)....................................................................34 Calculation of the current strength - Ohm's law....................................................................................34 Electrical voltage U ..................................................................................................36 Circuit symbols for the voltage source .................................................................................................36 Calculation of the electrical voltage......................................................................................................37 Direct and alternating current...............................................................................................................37 Resistance ........................................................................................................38 Function of a resistor............................................................................................................................39 „Normal“ resistors.................................................................................................................................39 Resistor color code table......................................................................................................................39 Temperature-dependent resistors ........................................................................................................40 Photoresistors ......................................................................................................................................41 Varistors................................................................................................................................................41 Adjustable resistors..............................................................................................................................42
6 Pull-up / Pull-down resistors...................................................................................43 Without resistor: ...................................................................................................................................43 Pull-up resistor: ....................................................................................................................................43 Pull-down resistor:................................................................................................................................44 What values should pull-up and pull-down resistors have? .................................................................44 Pull-up or pull-down resistor, which one do I use now? .......................................................................44 Simple circuits..................................................................................................45 Series connection of resistors................................................................................46 Parallel connection of resistors..............................................................................47 Mixed circuits of resistors.......................................................................................48 Extended series circuit .........................................................................................................................48 Extended parallel circuit .......................................................................................................................49 Capacitor...........................................................................................................50 Structure of a capacitor ...........................................................................................51 The capacitance of a capacitor ............................................................................................................51 Circuit symbols of capacitors................................................................................................................52 Capacitor in DC circuit..........................................................................................................................52 Capacitor types ....................................................................................................................................53 Electrolytic capacitor ...............................................................................................53 Ceramic capacitor ....................................................................................................54 Semiconductor devices ...................................................................................55 Structure of semiconductor devices ......................................................................56 The silicon atom ...................................................................................................................................56 Band model ..........................................................................................................................................57 Doping of semiconductor........................................................................................57 n-doping ...............................................................................................................................................57 p-doping ...............................................................................................................................................58 The pn junction.........................................................................................................59 Diodes ...............................................................................................................60 Structure of a diode..................................................................................................61
Diode characteristic..............................................................................................................................61 The pn junction in the diode .................................................................................................................62 Zener diode and avalanche diode........................................................................................................63 The Z-diode ...............................................................................................................63 Voltage stabilization with a Z-diode......................................................................................................64 The Schottky diode ..................................................................................................66 Light Emitting Diode – LED .....................................................................................67 Functionality of LED .............................................................................................................................67 Calculate series resistor.......................................................................................................................68 Transistor..........................................................................................................69 What is a transistor?.............................................................................................................................70 Function of a NPN transistor ................................................................................................................70 Function of a PNP transistor.................................................................................................................71 Why NPN transistors are used more often?.........................................................................................72 Simple NPN transistor circuit................................................................................................................72 MOSFET.............................................................................................................73 What is a MOSFET? ............................................................................................................................74 Function of an n-channel MOSFET? (Enrichment type) ......................................................................74 Function of a p-channel MOSFET? (Enrichment type) ........................................................................75 MOSFET circuit with a microcontroller.................................................................................................75 Voltage regulator ..............................................................................................76 LDO voltage regulator ..........................................................................................................................77 Pulse width modulation ...................................................................................80 PWM - Pulse Width Modulation............................................................................................................81 Period duration.....................................................................................................................................81 Duty cycle.............................................................................................................................................81 Arithmetic mean and effective voltage..................................................................................................82 EVERYONE CAN DO IT!!!! 7
8 Arduino 83 The history of the Arduino UNO..............................................................................85 The structure of the Arduino UNO..........................................................................86 Processor .............................................................................................................................................86 Power supply........................................................................................................................................86 86 USB Controller .....................................................................................................................................87 Reset push button ................................................................................................................................87 LED‘s....................................................................................................................................................87 Various electronic parts........................................................................................................................88 Interfaces..............................................................................................................................................88 ICSP Header ........................................................................................................................................88 Arduino UNO - Pin-out .........................................................................................................................89 Install Arduino IDE ...........................................................................................90 Structure of an Arduino Sketch...............................................................................92 Basics of C/C++ in the Arduino IDE........................................................................93 Add ESP boards ...............................................................................................96 The board manager ..................................................................................................97 Install ESP8266 Board .........................................................................................................................98 Install ESP32 Board .............................................................................................................................98 Add Libraries ....................................................................................................99 The Arduino IDE Library ........................................................................................100 The Library Manager..........................................................................................................................100 Install Zip Library................................................................................................................................101 Including a Library in a Sketch ...........................................................................................................101 Flashing LED with the Arduino UNO - Output ....................................................................................103 A push button switches a LED with the Arduino UNO - Input.............................................................106 Arduino Nano..........................................................................................................108 Arduino Nano ESP32..............................................................................................109
HomeAssistantServer-RPi 110 Installation of HASSIO ....................................................................................111 What is Home Assistant?.......................................................................................112 Installation of Home Assistant..............................................................................112 The Raspberry Pi Imager ...................................................................................................................113 Bootloader update - booting from an external SSD hard drive...........................................................113 The Home Assistant OS Installation...................................................................................................114 Advanced Options - RPi Imager.........................................................................................................114 Home Assistant Server over LAN .........................................................................115 Home Assistant server via Wi-Fi...........................................................................116 Create config file for Wi-Fi access......................................................................................................116 The UUID Generator ..........................................................................................................................116 Static IP address ................................................................................................................................117 Connecting the Raspberry Pi Server..................................................................................................117 First start of Home Assistant.................................................................................118 Restore Home Assistant from a backup...............................................................120 Add-on installation.........................................................................................121 What are add-ons?.............................................................................................................................122 Menu in the settings? .........................................................................................................................122 The Add-on Store ...............................................................................................................................123 Add-on Installation - Terminal & SSH.................................................................................................124 Add-on installation - File editor...........................................................................................................125 Add-on Installation - Mosquitto broker................................................................................................126 Add-on Installation - Node-red ...........................................................................................................127 Add-on Installation - ESPHome..........................................................................................................128 Add-on Installation - InfluxDB.............................................................................................................129 Add-on Installation - Grafana .............................................................................................................130 Add-on Installation - Samba share.....................................................................................................131 Add-on Installation - MotionEye .........................................................................................................132 Add-on Installation - Duck DNS..........................................................................................................133 EVERYONE CAN DO IT!!!! 9
Add-on Installation - Studio Code Server...........................................................................................135 Add-on - Home Assistant Google Drive Backup.................................................................................136 Linking the add-on to Google drive ....................................................................................................136 Set automation ...................................................................................................................................138 Add-on - ZigBee2MQTT.....................................................................................................................139 Set configuration ................................................................................................................................139 Zigbee2MQTT interface......................................................................................................................140 Configuration.yaml file...................................................................................141 YAML Basics ......................................................................................................................................142 MQTT - Sensor in YAML file...............................................................................................................146 MQTT - Switch in YAML file................................................................................................................148 Integrate ESP32-CAM........................................................................................................................149 YAML !secrets ....................................................................................................................................150 Automations....................................................................................................151 What is automation? ..............................................................................................152 The trigger..........................................................................................................................................152 The condition......................................................................................................................................152 The action...........................................................................................................................................152 Ways to create an automation............................................................................................................152 Example with a motion sensor and an LED.........................................................153 Adding the sensor and the LED in YAML...........................................................................................156 Add test setup to a map .....................................................................................................................156 Integrating ready-made automations with blueprints.........................................157 Create the automation from a blueprint..............................................................................................158 Creating automations manually in the GUI..........................................................159 New automation .................................................................................................................................159 When - Trigger....................................................................................................................................160 And if - Condition................................................................................................................................160 Then do - Action .................................................................................................................................161 More actions.......................................................................................................................................161 10
11 EVERYONE CAN DO IT!!!! Create automations in YAML.................................................................................162 Scripts .............................................................................................................163 What are scripts? ...................................................................................................164 The condition......................................................................................................................................164 The action...........................................................................................................................................164 Creating scripts manually in the GUI....................................................................164 New script...........................................................................................................................................164 Sequence ...........................................................................................................................................165 Creating scripts in YAML .......................................................................................166 Scenes.............................................................................................................167 What are scenes?...................................................................................................168 Creating scenes manually in the GUI ...................................................................168 New scene..........................................................................................................................................168 Devices...............................................................................................................................................168 Entities................................................................................................................................................169 Create scenes in YAML ..........................................................................................170 Trigger .............................................................................................................171 List of triggers ........................................................................................................172 Device ................................................................................................................................................172 * Event................................................................................................................................................173 Entity State.........................................................................................................................................173 * Geolocation......................................................................................................................................174 Home Assistant ..................................................................................................................................174 MQTT .................................................................................................................................................174 Numerical state of a device................................................................................................................174 * Template...........................................................................................................................................174 Sun 175 Tag 175 Time....................................................................................................................................................176 Time pattern .......................................................................................................................................176
12 * Webhook..........................................................................................................................................177 Zone ...................................................................................................................................................177 List of conditions....................................................................................................179 Device ................................................................................................................................................179 And / Or / Not in Building blocks.........................................................................................................179 Configure conditions as with the trigger .............................................................................................179 Actions list ..............................................................................................................181 Condition ............................................................................................................................................181 Delay in Building blocks .....................................................................................................................181 * Trigger event....................................................................................................................................181 Device ................................................................................................................................................181 Activate scene....................................................................................................................................182 Call service.........................................................................................................................................182 Repeat in buildings blocks..................................................................................................................183 Wait for trigger in building blocks........................................................................................................183 Choose under building blocks ............................................................................................................184 Dashboard - Energy .......................................................................................185 View in the energy dashboard...............................................................................186 Integrating SCT013 sensor into ESPHome ..........................................................186 Install firmware .......................................................................................................187 Calibrate sensor .....................................................................................................189 Add sensor to Home Assistant .............................................................................191 Insert sensor into the energy dashboard.............................................................191 Protocols 193 MQTT ...............................................................................................................194 History of MQTT.................................................................................................................................195 Client - Server (Broker) Principle........................................................................................................195 The MQTT Topic.................................................................................................................................196 The MQTT Broker...............................................................................................................................196
13 EVERYONE CAN DO IT!!!! The MQTT client.................................................................................................................................196 Topic Wildcards ..................................................................................................................................197 Retained Messages............................................................................................................................197 Persistent Session..............................................................................................................................198 Quality of Service Levels....................................................................................................................198 MQTT Publish - Send message .........................................................................................................199 Last Will and Testament .....................................................................................................................199 MQTT Subscribe - Subscribe message..............................................................................................200 MQTT Unsubscribe - Unsubscribe message......................................................................................200 First connection to the broker - CONNECT Packet............................................................................201 MQTT - Keep Alive.............................................................................................................................201 Practical MQTT example................................................................................202 MQTT - Practical Example .................................................................................................................203 MQTT Practice Example - Part 1 with NodeMCU-ESP8266..............................................................203 MQTT Practice Example - Concept Overview....................................................................................206 Source Code Explanation - Part 1 with NodeMCU-ESP8266 ............................................................206 MQTT Practice Example - Part 2 with NodeMCU-ESP32..................................................................207 Bluetooth.........................................................................................................208 How does Bluetooth work?.................................................................................................................209 Bluetooth radio technology and frequency hopping ...........................................................................210 The range of Bluetooth.......................................................................................................................211 Bluetooth versions and speeds ..........................................................................................................211 Serialinterfaces 212 Parallel data transmission ..................................................................................................................213 Serial data transmission.....................................................................................................................213 How does UART work? ......................................................................................................................214 How does I2C work? ..........................................................................................................................215 How does SPI work?..........................................................................................................................219 What is JSON?...................................................................................................................................223 Data types in JSON............................................................................................................................223
14 JSON syntax rules..............................................................................................................................223 JSON Basics Practice Example ............................................................................224 JSON sent and evaluated via MQTT .....................................................................226 ZigBee .............................................................................................................228 The history of ZigBee technology.......................................................................................................229 ZZigBee versions ...............................................................................................................................229 ZigBee coordinator.............................................................................................................................229 ZigBee router......................................................................................................................................229 ZigBee end device..............................................................................................................................229 ZigBee Mesh Network........................................................................................................................230 ESP8266 232 The ESP Family.......................................................................................................233 ESP8266-01 Pin-out................................................................................................235 CH340G - ESP01 UART adapter.......................................................................................................236 The FT232RL FTDI adapter ...............................................................................................................236 ESP01 - Example - internal LED flashing...........................................................................................237 ESP01 - Deep-sleep...........................................................................................................................238 ESP8266-12 Pin-out................................................................................................239 PWM - pulse width modulation...........................................................................................................240 Interrupts ............................................................................................................................................240 Programming an ESP8266-12................................................................................241 ESP8266 voltage regulator to 3,3 Volt ..................................................................244 ESP8266 - NodeMCU Pin-out.................................................................................245 ESP8266 - Wemos D1 mini.....................................................................................246 ESP8266 - Wemos D1 mini (light) V3.0.0 .............................................................247 ESP8266 - Operating Modes (sleep) .....................................................................248 Operating mode..................................................................................................................................248 Simple code example.........................................................................................................................249 Wake up with a push button...............................................................................................................250
15 EVERYONE CAN DO IT!!!! ESP8266 - Projects.........................................................................................251 BME280 sensor via MQTT with Deep-sleep and solar. .......................................252 Switch relay via MQTT ...........................................................................................256 ESP32 259 ESP32 Pin-out.........................................................................................................260 Digital Input GPIO Pins ......................................................................................................................262 DAC - Digital to analog Converter Pins..............................................................................................262 Touch-sensor Pins..............................................................................................................................263 PWM - Pulse Width Modulation..........................................................................................................263 Interrupts ............................................................................................................................................263 ADC Pins - Analog to Digital Converter..............................................................................................264 Hall Sensor.........................................................................................................................................264 RTC - Pins..........................................................................................................................................265 ESP32 - Operating modes (sleep).........................................................................265 Operating mode..................................................................................................................................265 Sources for waking up........................................................................................................................266 Wake up via timer...............................................................................................................................267 Wake-up via the touchpad..................................................................................................................267 External wake up................................................................................................................................268 Specify the GPIO that woke up ..........................................................................................................271 Store data in the RTC memory...........................................................................................................271 ESP32 - CAM...................................................................................................272 ESP32-CAM Hardware............................................................................................273 ESP32-CAM Pin-out................................................................................................274 Micro SD card pins.............................................................................................................................275 Flash light - (GPIO 4) .........................................................................................................................276 GPIO 33 - red LED light for status messages ....................................................................................276 GPIO 16 .............................................................................................................................................277 Power Pins .........................................................................................................................................277
16 GPIO 0 ...............................................................................................................................................277 Connection of an external antenna ....................................................................................................278 Serial Pins ..........................................................................................................................................278 The UART interface............................................................................................................................278 Camera connection and pin assignment............................................................................................279 Programming the ESP32-CAM ..............................................................................280 Prepare the Arduino IDE ....................................................................................................................281 Example Source Code .......................................................................................................................281 ESP32-CAM web server with the OV2640 camera...............................................284 Overview of camera functions............................................................................................................285 ESP32-CAM with a static IP address ....................................................................286 Describing the ESP32-CAM SD card ....................................................................288 The most important commands for handling the SD card..................................................................289 ESP32-CAM Time-lapse photos write to SD card................................................290 ESP32-CAM surveillance camera..........................................................................292 Test signal strength without external antenna ....................................................................................294 ESP32-CAM Antenna Signal Strength Test..........................................................294 Test signal strength with the external antenna IPEX 2.4 GHz............................................................296 Sensors 297 Indoor climate sensors ..................................................................................298 Temperature / Humidity / Pressure - Sensors......................................................299 Basics for an optimal indoor climate...................................................................................................299 Dew point ...........................................................................................................................................300 Absolute, relative and maximum humidity..........................................................................................300 Dew point example.............................................................................................................................301 Condensation .....................................................................................................................................301 DHT11 ......................................................................................................................302 DHT22/AM2302........................................................................................................304 BME280 / BMP280...................................................................................................306
17 EVERYONE CAN DO IT!!!! Configure I2C address .......................................................................................................................306 Si7021 ......................................................................................................................311 MCP9808..................................................................................................................313 Configure I2C address .......................................................................................................................314 Define temperature resolution............................................................................................................314 DS18B20..................................................................................................................316 Multiple DS18B20 sensors.................................................................................................................318 Set measurement resolution ..............................................................................................................320 Set alarm............................................................................................................................................320 Parasitic Power Mode ........................................................................................................................321 Waterproof sensor..............................................................................................................................321 Air quality sensors .........................................................................................322 AQI - Definition of Air Quality................................................................................323 Pollutants in the air.............................................................................................................................324 IAQ - Indoor Air Quality - Indoor Air Quality ........................................................325 What is VOC? (Volatile Organic Compounds)....................................................................................326 What is ppm and ppb? .......................................................................................................................326 Operating principle of MOX sensors ....................................................................327 BME680....................................................................................................................329 Configure I2C address .......................................................................................................................329 BME680 IAQ values with the BSEC library ..........................................................334 SGP30......................................................................................................................338 SGP40......................................................................................................................340 MQ-x Series Gas and Pollution Sensors..............................................................342 Types of the MQ sensor series...........................................................................................................342 How does the gas sensor work? ........................................................................................................343 The MQ-2 module ..............................................................................................................................344 Calibrate digital output........................................................................................................................344 Example program...............................................................................................................................345 IR transmitter and receiver............................................................................347
18 What is infrared (IR) ...........................................................................................................................348 Infrared signal modulation..................................................................................................................348 Transmission protocol ........................................................................................................................348 Practical example with IR receiver modules.......................................................................................349 Switching LEDs with the IR remote control ........................................................................................351 Sending IR data with the transmitter module .....................................................................................353 RFID Reader....................................................................................................354 How does an RFID chip work?...........................................................................................................355 RFID-RC522 module..........................................................................................................................356 RFID-RC522 module on a microcontroller .........................................................................................356 The source code for our RC522 module ............................................................................................358 LDR - photoresistor........................................................................................360 LDR switches an LED in the dark with the ESP8266 NodeMCU .......................................................361 LDR G5516 module............................................................................................................................363 Piezo vibration sensor ...................................................................................364 The piezo effect..................................................................................................................................365 How does the piezo effect work?........................................................................................................365 Piezo disk as vibration sensor............................................................................................................366 Motion sensors...............................................................................................368 Function of a pyroelectric IR sensor ....................................................................369 The HC-SR501 PIR Motion Sensor........................................................................370 Power supply......................................................................................................................................370 Switch-off delay..................................................................................................................................371 Sensitivity ...........................................................................................................................................371 Jumper ...............................................................................................................................................371 Modifying the HC-SR501 sensor........................................................................................................372 Using the HC-SR501 sensor as a stand-alone device.......................................................................373 The HC-SR501 sensor with NodeMCU-ESP8266 .............................................................................374 The Sketch function............................................................................................................................375 The AM312 PIR Motion Sensor..............................................................................376
19 EVERYONE CAN DO IT!!!! The Sketch function............................................................................................................................377 Rain sensors...................................................................................................378 Rain sensor YL-83 / FC-37 / MH-RD ......................................................................379 The comparator module .....................................................................................................................379 How does a rain sensor work?...........................................................................................................380 Mounting a rain sensor.......................................................................................................................380 The sketch function ............................................................................................................................382 Water level sensor..........................................................................................383 Calibrating the water level sensor ......................................................................................................385 The sketch function ............................................................................................................................387 Soil moisture sensors....................................................................................388 Resistance-dependent soil moisture sensor.......................................................389 The comparator module .....................................................................................................................390 How does a resistance-dependent soil moisture sensor work? .........................................................390 Calibrating the soil moisture sensor ...................................................................................................390 The sketch function ............................................................................................................................392 Capacitive soil moisture sensor ...........................................................................393 How does a capacitive soil moisture sensor work?............................................................................393 Calibrating the soil moisture sensor ...................................................................................................394 The sketch function ............................................................................................................................396 Ultrasonic sensor HC-SR04...........................................................................397 How does the HC-SR04 sensor work?...............................................................................................399 How do you calculate the distance?...................................................................................................400 The sketch function ............................................................................................................................402 The sketch function with the NewPing library.....................................................................................403 The HC-SR04 sensor with only 3 pins - 3-wire ..................................................................................404 The HC-SR04 sensor at extreme temperatures.................................................................................404 The limits of the HC-SR04 sensor......................................................................................................405 Magnetic switch..............................................................................................406 Function of a magnetic switch............................................................................................................407
20 The sketch function ............................................................................................................................409 AC current measurement, SCT-013 ..............................................................410 Sensors of the SCT-013 series ..........................................................................................................411 Function of a current transformer.......................................................................................................412 Connection to an Arduino or ESP board.............................................................................................412 Calculation of the load resistor (burden resistor)................................................................................413 3.5 mm audio plug - assignment ........................................................................................................414 The sketch for the SCT-013 sensor....................................................................................................415 SCT-013 Sensor calibration ...............................................................................................................416 BH1750 Light intensity...................................................................................418 Measuring LUX with the BH1750 sensor ...........................................................................................419 Lumen / Candela / Lux .......................................................................................................................419 Measuring methods of the sensor......................................................................................................420 Change I2C address ..........................................................................................................................420 The sketch for the BH1750 sensor.....................................................................................................420 RTC DS3231 ....................................................................................................422 The DS3231 RTC module..................................................................................................................423 Hardware overview.............................................................................................................................423 The 24C32 EEPROM.........................................................................................................................424 Use with a CR2032 battery ................................................................................................................424 Unix time ............................................................................................................................................425 The sketch for the DS32331 RTC module..........................................................................................425 Alarm with the DS3231 and interrupt with the SQW pin.....................................................................428 Formatting the time output .................................................................................................................428 Sketch explanation.............................................................................................................................431 SQW pin 1 Hz output..........................................................................................................................431 The 24C32 EEPROM.........................................................................................................................432
21 EVERYONE CAN DO IT!!!! Actuators 434 7 segment display ..........................................................................................435 Structure of a 7-segment display........................................................................................................436 Common anode or cathode................................................................................................................437 Calculating the series resistor ............................................................................................................438 How the 7-segment display works......................................................................................................438 Truth table ..........................................................................................................................................439 Connection to a microprocessor.........................................................................................................440 The SevSegShift Library ....................................................................................................................442 Servo motors ..................................................................................................445 SG-90 servo motor.............................................................................................................................446 How do you control an SG-90 servo motor? ......................................................................................447 How do you connect an SG-90 servo motor? ....................................................................................448 SG-90 servo motor with potentiometer to various microcontrollers....................................................448 ESP8266 and Arduino with the SG90 servo motor ............................................................................449 The sketch function ............................................................................................................................450 ESP32 with the SG-90 servo motor ...................................................................................................451 The sketch function ............................................................................................................................452 SSD1306 OLED Display .................................................................................453 SSD1306 OLED display on a microcontroller ....................................................................................454 The source code for our SSH1306 display.........................................................................................456 Font size and background..................................................................................................................457 Changing the font...............................................................................................................................457 Scrolling Text......................................................................................................................................458 Drawing on the display.......................................................................................................................459 Display of bitmaps..............................................................................................................................460 Piezo Buzzer ...................................................................................................463 The piezo effect ......................................................................................................464 How does the inverse piezo effect work?...........................................................................................464 The piezo buzzer structure.................................................................................................................464
22 Playing a buzzer melody ....................................................................................................................466 Stepper motors...............................................................................................468 General function of stepper motors .....................................................................469 Types of stepper motors........................................................................................469 Reluctance stepper motors ................................................................................................................469 Permanent magnet stepper motors....................................................................................................470 Hybrid stepper motors........................................................................................................................470 Bipolar and unipolar stepper motors ...................................................................471 Bipolar stepper motors .......................................................................................................................471 Unipolar stepper motors.....................................................................................................................472 Circuits of unipolar stepper motors.....................................................................................................473 Magnetization of coils............................................................................................474 Step resolution of a stepper motor.......................................................................474 Full step mode....................................................................................................................................475 Wave step mode.................................................................................................................................475 Operating modes of stepper motors ....................................................................475 Half step mode ...................................................................................................................................476 Micro step mode.................................................................................................................................477 Find / measure stepper motor phase pair ..........................................................................................477 What is the 28BYJ-48 stepper motor?..................................................................479 Pin-out of the 28BYJ-48 motor...........................................................................................................480 Pin-out of the ULN2003 module.........................................................................................................480 Gear reduction ratio............................................................................................................................481 The 28BYJ-48 stepper motor on the Arduino UNO .............................................482 The sketch..........................................................................................................................................483 The 28BYJ-48 controlled with two push buttons ................................................484 The sketch..........................................................................................................................................486 Two 28BYJ-48 motors on the Arduino UNO.........................................................486 The sketch..........................................................................................................................................487 The NEMA-17 stepper motor .................................................................................489
23 EVERYONE CAN DO IT!!!! L298N stepper motor driver...................................................................................491 Power pins..........................................................................................................................................491 Control and enable pins .....................................................................................................................492 Output pins.........................................................................................................................................492 Practical example...............................................................................................................................493 DRV8825 Stepper Motor Driver .............................................................................494 Power pins..........................................................................................................................................494 Micro step selection pins....................................................................................................................495 Control pins for power status..............................................................................................................495 Output pins.........................................................................................................................................495 Setting the current limit.......................................................................................................................496 A4988 stepper motor driver...................................................................................498 TMC2208 stepper motor driver..............................................................................498 E-Ink Display...................................................................................................499 What are E-Ink Displays?.......................................................................................500 How does an E-Ink Display work? ........................................................................500 Representation of shades of gray.........................................................................501 Now color comes into play....................................................................................501 Full color in the CMY-W (CMY-K) color model....................................................................................502 Full color with color filter.....................................................................................................................503 E-Ink Display practical examples..........................................................................504 Example 1 - Basics.................................................................................................504 The Sketch .........................................................................................................................................505 Example 2 - Partial updates...................................................................................506 The Sketch .........................................................................................................................................507 Choice of display....................................................................................................507 ProgrammingforPro’s 508 Push button with microcontroller.................................................................509 Things to consider when using push buttons.....................................................510
24 Structure of mechanical push buttons................................................................................................510 The push button noise...........................................................................................510 Hardware solution, prevent push button noise...................................................................................511 Software solution, prevent push button noise ....................................................................................512 Debouncing the push button.................................................................................513 Hardware solution, debouncing the push button................................................................................514 The 74HC14 Schmitt trigger IC ..........................................................................................................514 Software solution, program debouncing of push buttons yourself......................................................515 Software solution, debouncing the push button .................................................................................515 How long has the push button been pressed?....................................................517 Interrupts.........................................................................................................518 What is an interrupt?..............................................................................................519 The Interrupt Service Routine (ISR)......................................................................519 Triggering the interrupt service routine ...............................................................520 The hardware interrupt ..........................................................................................521 The software interrupt............................................................................................522 Division of the clock frequency – „Tick“..............................................................................................522 LED flashing without delay()...............................................................................................................523 What is an NTP server?..........................................................................................525 NTP server architecture......................................................................................................................525 Retrieving NTP server data................................................................................................................525 Unix time - Epoch...............................................................................................................................526 POSIX - Time zone setting.................................................................................................................527 Commands to format the time............................................................................................................527 Practical example...............................................................................................................................527 How does the sketch work? ...............................................................................................................529 ESPHome 530 What is ESPHome? ................................................................................................531 The installation of ESPHome.................................................................................531
25 EVERYONE CAN DO IT!!!! ESPHome secrets...................................................................................................532 Creating a new node ..............................................................................................532 Install firmware .......................................................................................................534 Settings from a device ...........................................................................................535 Edit: ...................................................................................................................................................535 Rename:.............................................................................................................................................535 Delete:................................................................................................................................................535 Logs:...................................................................................................................................................536 Validate:..............................................................................................................................................536 Install:.................................................................................................................................................536 Clean Build Files: ...............................................................................................................................536 ESPHome Flasher Software ..................................................................................537 Practical examples .........................................................................................538 Practical example: Wemos D1 mini with BME280 sensor ..................................539 Settings in the ESPHome Wizard.......................................................................................................540 Configure ESPHome YAML file..........................................................................................................540 Upload the code .................................................................................................................................541 Integrate sensor into Home Assistant.................................................................................................541 Adding the sensor to the user interface..............................................................................................542 Practical example: Wemos D1 mini LED strips ...................................................543 Settings in the ESPHome Wizard and YAML file................................................................................543 Upload the code - integrate it into Home Assistant ............................................................................544 Calculating the LED power.................................................................................................................545 Overview of different LED strips - 5 Volt..............................................................546 RGB - LED..........................................................................................................................................546 RGB – LED WS2812B .......................................................................................................................547 RGBW - LED SK6812 ........................................................................................................................547 Connection of 12 Volt LED strips..........................................................................548 12 Volt - RGB LED .............................................................................................................................548 12 Volt - RGBW LED..........................................................................................................................549
26 12 Volt - WS2815 - RGB LED ............................................................................................................550 Sensors overview...................................................................................................552 BME280..............................................................................................................................................552 BME680..............................................................................................................................................552 MCP9808 ...........................................................................................................................................553 DHT11 / DHT22..................................................................................................................................553 PIR Motion Sensor .............................................................................................................................553 Ultrasonic Distance Sensor................................................................................................................553 Measuring current with the SCT-013 sensor......................................................................................554 IC‘s-Integratedcircuits 555 CD4051BE - Multiplexer .................................................................................556 CD4051BE – Pin-out..........................................................................................................................557 How does the CD4051BE work?........................................................................................................558 The source code function - reading out channels individually............................................................559 Source code - read all channels.........................................................................................................560 MCP23017 - I/O Expander ..............................................................................561 MCP23017 – Pin-out..........................................................................................................................562 Pin ID of the MCP23017.....................................................................................................................563 Configuring the I2C address...............................................................................................................563 The sketch for the MCP23017 IC.......................................................................................................564 ADS1115 – Pin-out .............................................................................................................................567 ADS1115 - Select I2C address...........................................................................................................567 Example setup....................................................................................................................................568 ADS1115 Module................................................................................................................................568 Reading the analog data from each channel......................................................................................569 Comparing values with each other.....................................................................................................570 Setting the measurement accuracy of the ADS1115..........................................................................570 Alarm when limit is exceeded.............................................................................................................571 X9C103 – Pin-out...............................................................................................................................573 Internal structure of the X9C103 ........................................................................................................574
27 EVERYONE CAN DO IT!!!! Example setup....................................................................................................................................575 The sketch..........................................................................................................................................575 MCP4131 – Pin-out............................................................................................................................577 The sketch..........................................................................................................................................578 LEDstrips 579 Parameters of LED strips.......................................................................................581 Voltage ...............................................................................................................................................581 Current / power supply / power ..........................................................................................................582 LED sizes ...........................................................................................................................................582 IP protection class of LED strips.........................................................................................................582 White LEDs ........................................................................................................................................583 RGB LEDs..........................................................................................................................................583 The luminous flux (lumen)..................................................................................................................584 Number of LEDs per meter ................................................................................................................584 LED control.........................................................................................................................................585 Color Rendering Index (CRI)..............................................................................................................585 Cut marks on LED strips ....................................................................................................................585 Dimming LEDs....................................................................................................................................586 Lumen / Lux / Candela .......................................................................................................................586 SMD 5050 - LED types....................................................................................587 The SMD LEDs........................................................................................................588 Single color LEDs...............................................................................................................................588 Single color white LEDs - W / WW / CW............................................................................................589 RGB 3in1 LED....................................................................................................................................589 RGBW / RGBWW / RGBCW - 4in1 LED............................................................................................589 CCT- 2in1 LED ...................................................................................................................................590 RGBCCT- 5in1 LED ...........................................................................................................................590 Addressable LEDs..............................................................................................................................590 SK6812 RGBW / RGBWW / RGBCW................................................................................................591 LED control - structure ..................................................................................592
28 Microprocessors with LED strips .........................................................................593 Connection of 12 Volt LED strips........................................................................................................593 Connecting 5 Volt LED strips directly .................................................................................................594 Connection WS2812B LED strips, ext. power supply ........................................................................594 Connection of 5 Volt WS2813 LED strips, ext. power supply.............................................................595 Basics of the FastLED Library ..............................................................................597 Software: Installing the Arduino FastLED Library...............................................................................597 Hardware: WS2812B LED strip, ext. power supply............................................................................598 Programming: Library basics..............................................................................................................598 Practical example 01: Red - Green - Blue..........................................................................................599 Practical example 02: Blue running light ............................................................................................599 Practical example 03: Filling LED strips.............................................................................................600 The HUE color space with FastLED......................................................................601 Practical example 04: Rainbow animation .........................................................................................602 Practical example 05: Color temperatures .........................................................................................603 Color list .............................................................................................................................................604 Node-Red 605 What is Node-Red?.................................................................................................606 Structure of Node-Red ...........................................................................................606 First small practical example - Hello World ........................................................607 Node-Red basics ............................................................................................609 The flow...................................................................................................................610 Load and install Node ............................................................................................610 Exporting and importing flows ............................................................................................................611 Grouping nodes......................................................................................................612 Subflows..................................................................................................................612 Two ways to create a subflow ............................................................................................................613 The Sidebar.............................................................................................................614 Info 615
29 EVERYONE CAN DO IT!!!! Help615 Debug messages ...............................................................................................................................615 Configuration Node ............................................................................................................................616 Context Data ......................................................................................................................................616 Dashboard..........................................................................................................................................616 MQTT in Node-Red .................................................................................................617 Server settings ...................................................................................................................................617 MQTT out / in Node............................................................................................................................618 Create GUI (Dashboard).........................................................................................618 Dashboard Site and Theme................................................................................................................620 Dashboard Slider and Gauge.............................................................................................................621 Gauge for displaying temperature......................................................................................................622 Attachment 623 Different data types................................................................................................624 Numbers - Integers.............................................................................................................................624 Numbers - Decimal numbers..............................................................................................................624 No numbers........................................................................................................................................624 Complex data type .............................................................................................................................625 Overview of the most important data types........................................................................................625 Number systems.....................................................................................................626 How are number systems structured?................................................................................................626 The decimal system ...........................................................................................................................626 The dual/binary system ......................................................................................................................627 The hexadecimal system....................................................................................................................628 Resistor series - E24..........................................................................................................................629 SMD components overview...........................................................................630 SMD - Surface Mounted Devices...........................................................................631 Passive SMD components in chip design............................................................631 Marking of SMD resistors...................................................................................................................632
30 Marking of SMD tantalum capacitors .................................................................................................634 Marking of SMD electrolytic capacitors - V-Chip (Vertical Chip).........................................................634 Active SMD components in chip design ..............................................................635 Forms of the connecting cables ...........................................................................637 Material 638 Microcontroller....................................................................................................................................639 Raspberry Pi.......................................................................................................................................640 Indoor climate sensors .......................................................................................................................641 Various sensors..................................................................................................................................642 Various sensors..................................................................................................................................643 Actuators ............................................................................................................................................644 Stepper motors and drivers................................................................................................................645 General electronics material...............................................................................................................646 Equipment for the workshop...............................................................................................................647 Integrated Circuits ..............................................................................................................................647 ZigBee................................................................................................................................................647

In this chapter:

■ Current and voltage

■ Resistance

■ Simple circuits

■ Capacitor / semiconductor devices

■ Diode / transistor / MOSFET

■ Voltage regulator

■ Pulse width modulation

1Electronics basics

31
EVERYONE CAN DO IT!!!!

Current and voltage

32

Electric current I

The electric current, with the unit ampere (A), is the flow or directed movement of electrons. Current can only flow when there are sufficient free and mobile charge carriers between two different electric charges. For a better idea, we can think of the flow of electricity as flowing water in a pipe.The more water flows through the pipe, the greater the quantity of water. Electricity behaves in the same way: the more electrons flow through a conductor, the higher the electric current strength.

Current flow

Current in a circuit

Electric currents flow in most cases in a closed circuit, for this the following three components are needed.

Voltage source: The voltage source is needed to exert a “pressure” on the electrons. This pressure sets the electrons in motion.

Consumer: We use the term “consumer” to refer to components or devices, such as light bulbs or a hair dryer, which start to glow as a result of the electric current, or generate warm air to dry hair. Here it also becomes clear that electricity in the actual sense is not consumed, but merely converted. The assumption of the “current consumption” has, like that of the current direction also, an equally stored, historical origin - in addition however equal more.

Electric lines: To allow electrons to move freely, the voltage source is connected to electrical wires and the consumer to form a circuit - the electric circuit. These lines are usually made of copper or aluminum.

Current direction

33 EVERYONE CAN DO IT!!!!
Picture 1.1.1: Model for current in a conductor Picture 1.1.2: Simple circuit with a lamp
+ --

Current direction (technical/physical)

We distinguish between the technical and physical direction of current. In the technical direction of current, the flow of electrons runs from plus to minus; in the physical direction of current, it is exactly the opposite.

The background of these two different current directions has - like the assumption of the “current consumption” - its origin in history. When the current was discovered, it was determined that the current flows from the positive pole to the negative pole. With the progress of knowledge about the electricity, in particular at the beginning of the atomic physics, one noticed the “wrong” assumption made before. One agreed on the designation physical current direction. In addition, it was decided to continue to use the original direction of current and to call it the technical direction of current. In circuit diagrams, unless otherwise specified, the technical current direction is always used.

Calculation of the current strength - Ohm's law

To be able to calculate the current strength, I would like to introduce three different formulas to you here. The first formula comes from the famous Ohm's law. Variations of Ohm's law lead in the further to calculations of the power and electricity quantity.

Please note that in mathematical formulas and circuit diagrams, however, not the SI units but uniformly defined formula letters are used. For example, we know that electric current carries the SI unit „A“ for ampere. In formulas, however, the letter „I“ (capital i) is used. Only, the result of the current calculation leads then again the physical unit „A“. The same applies to the voltage, which we measure in volts (SI unit „V“), the formula letter „U“. For the resistance, after whose name the Ohm's law is also named, the formula letter is „R“ and stands for the ohm - for this, the Greek letter omega „Ω“ is also used as the SI unit.

34
Picture 1.1.3: Technical current direction (+ to -) Picture 1.1.4: Physical current direction (- to +) Electron flow direction
Current = Electricity quantity Time I = Q t Current = Power Voltage I = P U Current = Voltage Resistance I = U R R R

The results of the above calculations all carry the SI unit A for ampere or powers derived from it, such as “mA” (milli-ampere =1/1000A) or “kA” (kilo-ampere =1,000A).

To complete Ohm's law - this describes the always same relationships between current (I), voltage (U) and resistance (R) and can be connected via a “magic triangle”.

IRUDepending on what you want to calculate, simply cover the relevant formula letter and read the rest as “formula”. Thus, if you want to calculate the current and cover the I accordingly, you will only see U/R, which tells you to divide the measured voltage (U) by the resistance (R). Proceed in the same way to calculate the voltage: Cover the U and read and calculate RxI, i.e. current (I) times the resistance (R). Ohm's law can be as simple as that, but in electrical engineering it is an elementary component and basic knowledge.

I will go into the details of voltage and resistance in the following chapters.

35 EVERYONE CAN DO IT!!!!
x

Electrical voltage U

The electrical voltage U, with the unit volt (V), is the difference between two potentials and different charges.Ononesideisthepositivepolewithashortageofelectrons,ontheothersideisthenegative pole with a surplus of electrons. If you connect the two poles with an electrical conductor, a discharge occurs and an electric current flows. The higher the electrical voltage, the higher the pressure or force on the free electrons.

Currentflow Voltage

Circuit symbols for the voltage source

Depending on the type of voltage source, there are two different circuit symbols. The general circuit symbol for a voltage source or, if it is a battery, you can use the circuit symbol provided for it to define the voltage source more precisely.

36
Picture 1.1.5: Model for the voltage Picture 1.1.7: Voltage source (battery) circuit symbols Picture 1.1.6: Voltage source circuit symbols

Direct and alternating current

With direct current, the magnitude and direction of the voltage is the same at all times. The current flows in a constant direction. Direct current is often abbreviated DC and an example of a voltage source of this type is the battery.

With alternating current, on the other hand, the magnitude and direction of the voltage changes constantly and cyclically. Accordingly, the direction in which the current flows also changes. The alternating current is abbreviated as AC. The AC is provided to us as useful electrical energy at the sockets, with an effective value of the voltage of 230 volts at 50 hertz. This means that the voltage oscillates sinusoidally from +325 volts to -325 volts and back 50 times in one second.

In our electronics projects, we only use DC voltage for the power supply, which is why I will not go intoAC voltage any further here.

Calculation of the electrical voltage

I would like to present you three of the numerous formulas for the calculation of the voltage. The first formula comes again from the Ohm's law mentioned earlier. The second formula describes the relationship between voltage to work and charge. The last formula serves the voltage calculation over the power and the current.

37 EVERYONE CAN DO IT!!!!
Voltage = Power Current U = P I Voltage = Resistance x Current U = R x I Voltage = Work Charge U = W Q 0-180º 180-360º T 2T +V 0 -V
Amplitude
Picture 1.1.8: Sine wave of an alternating current
sine wave positive negative Period duration (T) RMS value Peakvalley value time (t)

Resistance

38

Function of a resistor

If the electric charge moves, then you get electric current, which is driven by the charge. A resistor hinders the flow of the electric charge. It can be said that almost any conductor (except superconductor) or device is a resistor.

Resistors have a wide variety of uses, whether for current limiting, e.g., for LEDs, as voltage dividers, or as pull-up or pull-down resistors.

Resistance has the formula symbol R and is expressed in Ω (ohms). We can determine the resistance using the Ohm's law with the following formula.

Resistance = Voltage Current R = U I

„Normal“ resistors

Resistors usually consist of an insulating porcelain body covered with a thin layer of carbon or metal and a protective lacquer. Carbon layer resistors are usually ocher colored, metal layer resistors are usually painted blue. The resistance value is then printed on the protective lacquer in the form of colored rings to make it equally legible without a magnifying glass and from all sides.

The circuit symbol for a resistor in Europe shown on the left side is a rectangle, on the right side you see how the circuit symbol looks like in the USA. Since many circuit diagrams come from there, it is important to know this sign.

Resistor color code table

Before you start determining the value of resistors, you need to count how many color rings are printed on the resistor. Carbon film resistors usually have 4 rings. Metal film resistors have 5 rings. Resistors with 5 rings have a more accurate resistance value.

As a first step, we need to figure out where, front is and where back is. As a rule of thumb, for the blue metal film resistors we look for the brown (sometimes red) stripe and for the ochre carbon film resistors we look for the gold (sometimes silver) stripe. This indicates the tolerance in each case. This ring is then at the back and we can now start reading from the front. There are of course other colors for the indication of the tolerance, these are then rather more special resistors and are not usually used in home electronics projects.There are also resistors where the tolerance ring is slightly separated from the other color rings and therefore easier to recognize.

Then you start from the front to assemble the resistor value. The individual colors are assigned specific and unique values. We take these from the following tables. The third or the fourth ring (in case of 5 rings) is the multiplier. Let's try this in practice with two examples.

Picture 1.2.1: Resistance according to EN Picture 1.2.2: Resistance according to ANSI
39 EVERYONE CAN DO IT!!!!

Example 1:

Ring 1: brown =1

Ring 2: black = 0

Ring 3: orange = x1000 (multiplier)

Ring 4: gold 5% (tolerance)

10 x 1000 = 10k Ohm ± 5%

Example 2:

Ring 1: red = 2

Ring 2: red = 2

Ring 3: black = 0

Ring 4: brown = x10 (multiplier)

Ring 5: brown 1% (tolerance)

220 x 10 = 2.2k Ohm ± 1%

Please note that for carbon film resistors - i.e. those that have only fourth rings printed on them and are ocher colored - the third ring is already the multiplication factor. You skip in the table above the column labeled „3rd ring“ - this column is explicitly and without exception only for the metal film resistors.

Temperature-dependent resistors

Almost all electrical components usually also exhibit a slightly higher resistance at higher temperatures. However, there are also semiconductor materials in which this temperature dependence is very pronounced and is used specifically. As special resistors, these particular materials are often used as temperature sensors.

The following is an overview of the different resistors and their possible applications.

40
Table 1.2.1 Resistor color code table Picture 1.2.3: Resistor 4 rings Picture 1.2.4: Resistor 5 rings
Ring color Ring 1 Ring 2 Ring 3 Ring 4 (multiplier) Ring 5 (tolerance) black 0 0 0 -brown 1 1 1 X 10 1 % red 2 2 2 X 100 2 % orange 3 3 3 X 1000yellow 4 4 4 X 10000green 5 5 5 X 100000 0,5 % blue 6 6 6 X 1000000 0,25% purple 7 7 7 X 10000000 0,1 % gray 8 8 8 -white 9 9 9 -gold - - - X 0,1 5 % silver - - - X 0,01 10 %

PTC resistors

PTC thermistors or PTC resistors „Positive Temperature Coefficient“ is the name given to substances whose resistance increases with increasing temperatures. Mostly used the PT100 or PT1000. However, the „PT“ does not come from the type of resistor (PTC), but is derived here from the resistor material - the chemical element designation for platinum.

Picture 1.2.5: PTC resistor circuit symbol

NTC resistors

Application

Temperature control

Liquid level sensor

NTC thermistors or NTC resistors „Negative Temperature Coefficient“ are substances whose resistance decreases with increasing temperatures.

Picture 1.2.6: NTC resistor circuit symbol

Photoresistors

Application

Temperature sensor

Temp. stabilization of semiconductor circuits

In addition to temperature-dependent resistors, there are also resistors that are exposure-dependent. The photoresistor or LDR resistor called “Light Dependent Resistor” has a resistance of a few hundred ohms at full illumination. As the light intensity decreases, the resistance increases and can rise to a few mega ohms. The change in resistance of an LDR is very slow compared to the temperature dependent resistors described above.

Application

Illuminance measurement

Twilight switch

Flame detector

Varistors

A varistor or VDR resistor „Voltage Dependent Resistor“ is an electrical resistor whose value depends on the applied voltage. The resistance value of a varistor behaves in the opposite direction to the applied voltage. This means that the resistance decreases with increasing voltage and increases with decreasing voltage.

Picture 1.2.8: Varistor circuit symbol U

Application

Voltage limitation

Voltage stabilization

Overvoltage protection

Picture 1.2.7: Photoresistor circuit symbol
EVERYONE CAN DO IT!!!! 41

Adjustable resistors

An adjustable resistor is a resistor whose resistance value can be changed mechanically via a sliding contact, by turning or moving it.

An adjustable resistor value has a low and a high value. The minimum value can be 0 Ω, for example. The maximum value results from the resistance designation. Each potentiometer, also known as a “poti” for short, has three terminals, with the full resistance value specified on the potentiometer appearing between the two outer terminals.

If one of the end contacts and the middle tap from the potentiometer is connected to the circuit, the resistance can be adjusted between zero and the maximum value with the help of a rotary knob or slider.

Application

Variable voltage divider

Variable resistors

Finally, it should not go unmentioned that every electrical line in itself has a certain resistance. This resistance can also be determined as a function of the cable cross-section, the cable length and the respective cable material. An overload of the electrical lines leads to a heating of these, which can lead up to the cable fire. The dangers that can emanate from electricity should therefore not be underestimated.

If you already have experience with the Arduino IDE, then you can build this small example that writes the value of the potentiometer every 0.5 seconds in the serial monitor.

Source Code https://github.com/Edistechlab/

int potpin = 0; //Analog pin A0 for the potentiometer

void setup() { Serial.begin(115200); }

void loop() {

Serial.println(analogRead(potpin)); // (Value between 0 and 1023) delay(500); }

42
Picture 1.2.9: Poti circuit symbol
1 1 5 5 10 10 15 15 20 20 25 25 30 30 A A B C D E F G H SILABS DCL00X 1016+ RST RST RXD5D6D7D8 D0D2D3D4 D1 TX EN3V3 3V3 3V3 VinGND GND GND GNDSD2SD1CMDSDOCLKSD3RSVRSVA0 FLASH AMS1117 3.3H844MP J3Y 106C J3Y
Picture 1.2.10: Node-MCU structure with Poti

Pull-up / Pull-down resistors

„Pull“ means to pull, „up“ means to go up and „down“ means to go down. So a pull-up resistor „pulls“ something up, the pull-down resistor pulls something down. It's super simple, isn't it? One pulls the electrical voltage up and the other pulls it down. The pull-up usually goes to the operating voltage and the pull-down to GND, i.e. 0V.

What do we need these pull-up / pull-down resistors for?

Raspberry Pi and Arduino have inputs and outputs, called pins. These need to be in a defined state to work correctly, e.g. HIGH or LOW. Now, however, voltage fluctuations or high-frequency interference from surrounding components can cause the input to have no clear HIGH or LOW signal present and switch even though it shouldn't yet. To counteract this, we use pull-down and pull-up resistors. Let's take a closer look at the different possibilities.

Without resistor:

+5 Volt direct

In this example we don't use a resistor and now this bears the risk that there could be a voltage at the input due to external influences that switches the Arduino. The contact is hanging in the air.

When the push button is pressed, the +5 V are present and the Arduino switches properly.

GND direct

Pull-up resistor:

Here is the same example, but this time we switch against GND. Again, the contact is hanging in the air.

When the push button is pressed, GND is present and the Arduino switches properly.

Pull-up

When the push button is open, the resistor pulls up the input to +5 V. This is definitely “HIGH”. Therefore this resistor is called pull-up resistor - the resistor pulls the input up to the operating voltage.

When the push button is closed, GND is connected to the input. The voltage drops completely at the pull-up resistor and thus GND is present at the input - a definite “LOW”.

Arduino Pins +5V R Inputs Output Arduino Pins +5V Input Output
Arduino Pins +5V Output Input
EVERYONE CAN DO IT!!!! 43

Pull-down

When the push button is open, the resistor pulls the input to GND. Here is definitely 0 V, so „LOW“. Therefore this resistor is called pull-down resistor. The input is pulled down to GND.

When the push button is closed, +5 V is connected to the input. The voltage drops completely at the pull-down resistor, whereby +5 V and thus a definite „HIGH“ is present at the input.

What values should pull-up and pull-down resistors have?

How large the resistor should be depends entirely on the application. Normally, values from 10 to 100 kΩ are suitable. So you don't necessarily have to use the often recommended 10 kΩ resistors. A resistor larger than 10 kΩ should be used especially if the Arduino is operated by battery. In general, battery operation requires the lowest possible power consumption, which is why the highest possible resistors should be used. Thanks to Ohm's law we already know: the smaller the resistance, the higher the current flow.This is at the expense of power consumption and thus reduces the battery runtime. However, since higher currents can swallow more external interference, it may make sense to use a smaller resistor in a “harsher environment”. Higher resistors conserve battery capacity, but make the circuit more susceptible to glitches - lower resistance values do the opposite. Take a look at the following graph as a guideline, which shows you which resistor values should be used for which application. The general requirement is 1-10 kΩ and for battery powered projects 10-100 kΩ.

Pull-up or pull-down resistor, which one do I use now?

It doesn't really matter if we use a pull-up or pull-down resistor. If you have the choice to switch to GND or VCC, then it is a question of noise immunity. The better choice here is the pull-up resistor, because it is also more battery friendly. Short

Note

The resistance value is not critical for our DIY projects. With 10 kΩ you are in the golden mean. Alternatively, you can use the next largest resistor that you have available. It doesn't matter much, so we shouldn't worry about it unnecessarily.

44
Arduino Pins +5V R Inputs Output
Pull-down resistor:
circuit Contact open
0 1k 10k 100k ∞ in gen. battery Ω

Simple circuits

45
EVERYONE CAN DO IT!!!!

Series connection of resistors

The connection of components in series is also called series connection. In this circuit, the current remains the same for all resistors.

The total resistance in a series circuit is the sum of the individual resistances.

Since the current in the series circuit is the same everywhere, the unequal resistances cause different voltage drops. The voltage is distributed proportionally to the respective resistors. Therefore, in the series circuit, the highest resistance causes the highest voltage drop.

Note

In the series circuit, the current remains the same for all resistors and the voltage divides.

46
R1 R2 R3 U1 U2 U3
Rtotal = R1 + R2 + R3 Utotal = U1 + U2 + U3 Utotal = R
total x I Itotal

Parallel connection of resistors

In the parallel connection of resistors, in contrast to the series connection, the voltage remains the same for all resistors and the current divides.

The total resistance of the parallel circuit is smaller than the smallest individual resistor. We can imagine the resistor as a door. The more doors we have next to each other, the more people can go through the doors at the same time. The same applies to the charge carriers in a parallel circuit. The total resistance is calculated as the reciprocal of the sum of all reciprocals of the individual resistances.

Since the voltage in the parallel circuit is the same everywhere, the different resistances cause different partial currents. The currents behave inversely to their resistances. That is why a small current drops at high-resistance resistors.

Note

In the parallel circuit, the voltage remains the same for all resistors and the current divides.

EVERYONE CAN DO IT!!!! 47
R3 I1 I2 I3 R1 R2 Utotal Itotal = I1 + I2 + I3 U = Rtotal x Itotal = + 1 Rtotal 1 R1 + 1 R2 1 R3

Mixed circuits of resistors

Series and parallel circuits also regularly occur together in devices/circuits, which is why we then speak of a mixed or group circuit. There are both extended series and extended parallel circuits. In both cases, the resistors are combined, resulting in an increasingly simple circuit. It is also said that the circuit dissolves.

For better understanding, we will make examples with the calculation of different group circuits. I will also show you the simplified calculation form that can be applied when a parallel circuit consists of only two resistors.

Extended series circuit

This circuit consists of a parallel connection of resistors R2 and R3, which are in turn connected in series with resistor R1. To be able to calculate the total resistance of this circuit, the resistor R23 is calculated first. Since this is a parallel connection of only two resistors, we can use the simplified formula.After the calculation we get a series connection of the resistors R1 and R23, which we can simply add to get the total resistance.

48
R1 R2 R3 I 1 1 2 2 R1 U I R23 = R23 R2 x R3 R2 + R3 Rtotal= R1 + R23 U

Extended parallel circuit

The extended parallel circuit consists of a series circuit with the resistors R2 and R3, which in turn are connected in parallel to R1. Here we start with the calculation of R23 by adding the two resistors R2 and R3. After that, we can again use the simplified formula to calculate the parallel circuit with resistors R1 and R23.

No matter how complex a circuit is, the procedure is always the same. By combining and calculating the series and parallel circuits, the circuit is simplified further and further - resolved.

49 EVERYONE CAN DO IT!!!!
1 1 R2 U I R1 2 R1 U I 2 R3 R23 = Rtotal R1 x R23 R1 + R23 R23 = R2 + R3

Capacitor

50

Structure of a capacitor

A capacitor is an electrical component that can be used to store electrical charge and thus electrical energy. The simplest form of a capacitor is a plate capacitor, which consists of two metal plates facing each other and insulated from each other, with air between them as a dielectric. The dielectric is to be understood as an insulator.

If direct current (DC) is now applied to the capacitor, an electric field is created between the two metallic plates in which field energy is stored. One plate absorbs positive charge carriers and the other negative charge carriers, with the same distribution of charge carriers. Capacitors are used to store electrical energy temporarily, to filter frequencies and to compensate for fluctuations in DC voltage - to name some examples.

Dielectric

Electrode

Connection

Connection

ATTENTION

Sometimes considerable amounts of charge can be stored in a capacitor. Therefore, never touch the terminals of a capacitor unless you are sure that it is not in a charged state!

The capacitance of a capacitor

The capacitance (C) is the storage capacity of a capacitor and it indicates the ratio of maximum charge (Q) that can be stored at a given voltage (U). The unit for the capacitance is given in Farad (F).

The capacitance of a capacitor is determined by its structural size. It depends on the size of the plates, the distance between them and the material between them.

The capacitance of capacitors is rather small and the values are usually given in µF (micro 1E-6) nF (nano 1E-9) or pF (pico 1E-12) Farad.

C = Q U

51 EVERYONE CAN DO IT!!!!
Picture 1.4.1: Plate capacitor Picture 1.4.2: Capacitor circuit symbol Plate spacing

Capacitor in DC circuit

To fully charge a capacitor often takes only a few seconds or fractions of a second, depending on the capacitance of the capacitor and the strength of the charging current. The charging process usually starts very quickly with the voltage building up between the capacitor plates and then becomes progressively slower. The charging process is finished when the voltage UC equals the charging voltage U0 and no more current can flow through the capacitor.

U0

U I t t charge discharge

Circuit symbols of capacitors

Here I would like to present you the four most frequently used circuit symbols of capacitors.

Parts needed

* https://amzn.to/3hEWFmW - Capacitor set

* https://amzn.to/3hKPytf - Ceramic capacitor set

All links with "*" are Amazon affiliate links.

52
+
Picture 1.4.4: Capacitor Picture 1.4.3: Capacitor charge-discharge characteristics Picture 1.4.5: Electrolytic capacitor Picture 1.4.6: Rotary capacitor Picture 1.4.7: Trimmer capacitor

Capacitor types

A distinction is made between capacitors with fixed capacitance and variable capacitance, such as rotary capacitors and trimmer capacitors.

Another distinguishing feature is whether the capacitor is polarized or non-polarized. Polarized capacitors include electrolytic capacitors, aluminum electrolytic capacitors, and double layer capacitors to name a few.

For non-polarized capacitors, we have film capacitors and ceramic capacitors, which are the most commonly used.

Electrolytic capacitor

An electrolytic capacitor, usually has a high capacitance value of 1 µF to 10 mF or even more. The electrolytic capacitor belongs to the group of polarized capacitors, which means that the capacitor has a plus and a minus terminal and these must not be interchanged. The minus pole can be recognized by the printed minus sign and in most capacitors the plus pole is designed with a longer connecting wire.

With electrolytic capacitors it is important to know that the capacity can decrease considerably over time. They should therefore only be used where the deviation of the capacitance value is not too important for the circuit.

Because of the large capacitance of electrolytic capacitors , they are often used for current storage or as a backup capacitor for the supply voltage.

The capacitors consists of two aluminum electrodes, one of which is artificially oxidized.This oxide layer at the anode acts as the dielectric of the capacitor. Layers of paper or insulating permeable fabric separate the anode foil from the cathode foil. The paper or fabric is soaked in an electrolyte and placed rolled up in an aluminum cup.

EVERYONE CAN DO IT!!!! 53
10µF
Picture 1.4.9: Electrolytic capacitor Picture 1.4.8: Electrolytic capacitor structure
Cathode foilAnode foil + Connection Fabric / Paper

Ceramic capacitor

Aceramic capacitor uses ceramics for the dielectric, as the name implies. On it, the electrodes of the capacitor are metallized and the terminals are placed on it.Aplastic protective cover is fitted over it.

Ceramic capacitors have capacitances from a few picofarads (pF) to a few nanofarads (nF) and they are used as temporary storage or to cut off voltage spikes.

Polarity is not important for this capacitor.

Connection Connection

Protective cover

Dielectric

Electrode

54
Picture 1.4.10: Ceramic disc capacitor structure

Semiconductor devices

55
EVERYONE CAN DO IT!!!!

Structure of semiconductor devices

The electrical conductivity of semiconductors is between metals like copper and insulators like glass. In metals we have a high density of freely moving charge carriers and in insulators the charge carriers are tightly bound to the atoms.

At room temperature, the conductivity of semiconductors is low. If energy is added in the form of heat, light, voltage, or magnetic energy, then the conductivity changes.

Semiconductor materials have a crystal structure and the best known semiconductor material is silicon. Silicon (Si) is found in sand and is abundant in nature.

The silicon atom

Silicon is the most commonly used semiconductor material and on the basis of this we will look at the principle of semiconductors.The silicon has 14 electrons, four of eight of them as outer electrons (valence electrons) and can bond with other silicon atoms to form a silicon lattice. In this bond, the Si atoms each share one electron to fill the valence shell with eight electrons. This bond is called a covalent bond.At low temperatures, nothing happens to this semiconductor and all the electrons are tightly bound.

If the temperature is increased, the silicon atoms start to vibrate and the electrons can break away from the lattice bond and are now free to move.At the place where the electron was, a positive hole is now formed and due to the freely moving electrons, the conductivity increases in square with the temperature.

56
-- Si
Si
Silizium 14 28,09
Picture 1.5.1: Silicon atom Picture 1.5.2: Silicon in the periodic table Picture 1.5.3: Silicon connected as a lattice
- ----- - -------------Si Si Si Si Si Si Si Si Si+ +----- - --------------Si Si Si Si Si Si Si Si Si + +
Picture 1.5.4: Heated silicon lattice with holes and free electrons

Band model

The band model is a physical model for the energy states of electrons in a solid. A semiconductor has two energetic bands. The valence band (p-line) which is occupied by electrons and the conduction band (n-line) which is occupied by skipped electrons. In between we have the band gap which is so small in undoped semiconductors (intrinsic semiconductors) that already at room temperature the electrons can jump from the valence band to the conduction band. In this model, it is assumed that only electrons in the conduction band contribute to charge transport.

Doping of semiconductor

The intrinsic conductivity of pure semiconductor crystals is undesirable because of their strong temperature dependence. To make semiconductors technically usable, the semiconductor crystals are contaminated with foreign atoms. This process is called doping and either an electron surplus (n-layer) or an electron deficiency (p-layer) can be doped.

n-doping

In n-doping, a foreign atom with more outer electrons than silicon is used. Typically phosphorus (P) is used here, which provides a free electron. However, arsenic (As) or antimony (Sb) can also be used. Since an electron is a negatively charged charge carrier, this is called an n-type conductor. In the atomic nucleus, each electron is opposed by a proton, which allows the semiconductor to remain electrically neutral even after doping.

EVERYONE CAN DO IT!!!! 57
Energy E Line
- - -
Band
Energy E Line
- -+ -
Valence band Band gap
band
Valence band
gap
band
--- P Phosphorus 15 30,97 P
Picture 1.5.5: Phosphorus atom Picture 1.5.6: Phosphorus in the periodic table

p-doping

In p-doping, a foreign atom with fewer outer electrons than silicon is used. For p-doping aluminum (Al), gallium (Ga), indium (In) or boron (B) can be used. The missing electron creates a defect electron which is also called a positive hole. If an electron is released by heat, it is attracted to the open bond. This causes the hole to disappear, but a new hole is created at a different location. Due to the lack of electrons or positive charge, this is called a p-type conductor, which remains electrically neutral even after doping, since the five electrons are opposed by five protons in the nucleus.

Boron 5 10,81

58
Picture 1.5.9: n-doped silicon lattice
- ----- - -------------Si Si Si Si Si Si P Si Si - ----- - -------------Si Si Si Si Si Si B Si Si +
Picture 1.5.10: p-doped silicon lattice
--
B
B
Picture 1.5.7: Boron atom Picture 1.5.8: Boron in the periodic table

The pn junction

If a p-type material is joined with an n-type material, the so-called pn junction is formed in the boundary region. This region is also called the boundary or junction layer. Without external influence by voltage, the free electrons migrate from the n-layer to the holes in the p-layer due to thermal oscillation and form a bond there. The migration of the electrons is called charge carrier diffusion and an ion lattice is formed. A strong electric field is created in this junction, which is depleted of free charge carriers, preventing further electrode migration.As the temperature rises, the junction widens and the electric field increases. At 20 °C, a diffusion voltage (UDif) of 0.7 volts is generated in the junction for silicon. As a note: For germanium, the diffusion voltage is only 0.3 volts.

59 EVERYONE CAN DO IT!!!!
Picture 1.5.11: pn transition at room temperature Picture 1.5.12: pn transition in hot state
--------------------+++++++++++++++++++++++++ p pn n UDif ---------------+++++++++++++--+++++--++++++++++++ p pn n UDif

Diodes

60

Structure of a diode

The semiconductor diode consists of a p- and an n-layer, which is cast in resin. Because of the pn junction, a diode is polarized and it allows the current to flow in only one direction.Aring is printed on the diode which marks the cathode (n-layer).

The circuit symbol consists of a triangle, which is the anode (p-layer) and a bar which symbolizes the cathode (n-layer). The tip of the triangle indicates the forward direction of the technical current. If you want to operate the diode in forward direction, the positive pole is connected to the anode. If you want to operate it in reverse direction, the positive pole is connected to the cathode. Typical applications for diodes are rectification of voltages and reverse polarity protection.

Anode Cathode Anode Cathode

With the diode characteristic we can read the behavior of the diode for an operation in reverse and in forward direction. Two important values when dealing with diodes are the threshold value, which indicates from which voltage a diode becomes conductive and the breakdown voltage, which indicates how high the maximum voltage may be when operating in reverse direction. The nominal values can be found in the data sheet of the respective diode. The following characteristic curve is general and serves only for a better understanding of the diodes.

Breakdown range: If the diode is operated in reverse direction and the voltage exceeds the value UBR (breakdown voltage / Zener breakdown), the current increases abruptly. If this current is not limited, then the diode becomes so hot that the diode is destroyed. As an example, for a 1N4001 diode the breakdown range is 50 volts.

Blocking range: If the diode is operated in blocking direction, then only a small blocking current flows through the diode. The reverse current remains as long as the breakdown voltage of the diode is not exceeded.

Forward range: The threshold voltage US indicates the voltage above which the diode becomes conductive in the forward direction. A diode is not always conductive, but only when the threshold voltage is reached. When US is exceeded, the current flowing through the diode increases rapidly. How high the threshold voltage (diffusion voltage) is depends on the semiconductor material of the diode. For silicon it is ~ 0.7 volts and for germanium it is approximately ~ 0.3 volts. The threshold voltage drops when current flows through the diode, which you should take into account in your design.

61 EVERYONE CAN DO IT!!!!
Picture 1.6.1: Diode circuit symbol Picture 1.6.2: Diode - layer structure p n pn Diode characteristic

Diode

UR - voltage reverse direction

UF - voltage forward direction

UBR - breakdown voltage

US - threshold voltage

IF - forward current

IR - reverse current

The pn junction in the diode

For a better understanding, let's look at the PN junction using a few different voltages on a silicon diode.As a reminder, in a silicon diode the forward voltage is ~ 0.7 volts.

If we apply the positive terminal to the anode and the negative terminal to the cathode with a voltage of 0.3 volts, then the pn junction is reduced somewhat. If the voltage is further increased to 0.5 volts, this will further reduce the pn junction. If we apply the forward voltage of 0.7 volts to the diode, then the diode becomes conductive and we no longer have a junction.

If the voltage is reversed, i.e. the negative pool is connected to the anode and the positive pole to the cathode, the pn junction is enlarged. We can increase this voltage to a maximum of the breakdown voltage, otherwise the diode will be destroyed.

Voltage: 0,3 Volt

Voltage: >0,7 Volt

Voltage: 0,5 Volt

Voltage: -x Volt

62 U -V V R US UBR -IR ImA µA F -IS U
F Legend
Picture 1.6.3: Diode characteristic
Breakdown range
Blocking range Forward range pn pn ++pn p n pn +pn +pn

The Z-diode

The Z-diode is a silicon semiconductor diode and it consists of a p- and an n-layer, which is permanently operated in reverse direction. If it is operated in forward direction, it works like a normal diode.

The most important parameter for Z-diodes is the clearly defined breakdown voltage UBR above which the diode allows the electric current to pass and, unlike normal diodes, is not destroyed in the process.

Over a wide range of currents, the voltage drop across the Z-diode corresponds exactly to the breakdown voltage. To protect the diode from high currents and overheating, a series resistor is required.

Atypical application of Z-diodes is voltage stabilization in circuits with small current consumption, the use for voltage limitation of voltage peaks or as reference voltage in circuits.

Anode Cathode

The Z at the diode does not stand for Zener, but symbolizes the course of the typical characteristic curve of a Z-diode. Zener diodes may only be called such if the breakdown voltage is 1.5 V to 5 volts. If the breakdown voltage is above this, it is called an avalanche diode.

Zener effect:

The Zener effect is triggered by the electric field once the breakdown voltage is reached.This causes electrons to be released from their crystal bonds of the p-doped layer and they tunnel to the n-doped layer. This results in free charge carriers and current flow in the reverse direction.

Avalanche effect:

If the voltage is above 5 volts, the avalanche effect dominates. The charge carriers released by the Zener effect are very strongly accelerated by the electric field and this causes further electrons to be released from their crystal bonds and to migrate into the junction. On the way there, they can knock out more bound charge carriers and, as a result, the current strength rises sharply in a very short period of time.

Both effects occur simultaneously in the 5 volt range. Below 5 volts the Zener effect dominates and above that the avalanche effect.

EVERYONE CAN DO IT!!!! 63
Picture 1.6.4: Z-diode circuit symbol Picture 1.6.5: Z-diode alternative circuit symbol Zener diode and avalanche diode

Z-diode

Passing characteristic

3.3 V - Z-diode

4.7 V - Z-diode

6.8 V - Z-diode

Blocking range

Forward range

Voltage stabilization with a Z-diode

If we need a constant voltage of for example 3.3 volts, but we supply the circuit with 12 volts, it is a good idea to use a Z-diode for small powers in the mW range or as reference voltage. The Z-diode 1N4728 has a breakdown voltage of 3.3 volts. Let's make a calculation example for this voltage stabilization with a Z-diode.

Calculate currents:

The maximum current that can flow through the Z-diode is calculated using the power and the voltage with the following formula. (Data from the diode data sheet)

IZmax = P U2 IZmax = 0,5 W 3,3 V IZmax = 151 mA

To be able to calculate the total current of the circuit, we need the minimum current from the Zdiode, which is needed to let the diode break through cleanly. This is about 10% of the maximum current, the exact data can be taken from the data sheet. To allow for some safety, we assume IZ = 20 mA, and for the load current IL we also use 20 mA. The currents can be added to get the total current Itotal. Itotal = IZ + IL = 40 mA.

Calculation of the load resistance:

We can calculate the load resistance RL using the Ohm's law. R = U / I (3.3V/ 20 mA) and as a result we get 165 Ω. Since there is no 165 Ω resistor, we use a resistor with 160 Ω for RL

64 U -V V R -IR IF UF 0.7 -2 -4 -6 -8
Picture 1.6.6: Z-diode characteristic

Calculation of the series resistor:

The series resistor limits the current to the total current and thus protects the Z-diode. It is calculated with the following formula.

Since there is no resistor with 217 Ω, we take the nearest standard with 220 Ω.

Calculation of the powers:

We can now calculate the powers with the matched resistors to ensure that the components used are within specification. Let's start with the series resistor. PV = (Utotal - UZ) x Itotal = (12 V - 3,3 V) x 39.5 mA= 344 mW

The power of the diode is calculated as follows. PZ = 3,3 V x 20 mA= 66 mW and the load resistor has a power of PL = 3,3 V x 20,6 mA= 68 mW

ATTENTION

Very high powers can be generated and the components can become very hot. It must be ensured that the components are designed for the power. For the series resistor we have a power of 344 mW, which means that we should use a resistor with at least 500 mW power and the standard resistor with 1/4 watt is not sufficient.

Table 1.6.2: 1 W Z-diodes example values

EVERYONE CAN DO IT!!!! 65 12V 3,3V (500mA) RL RV IZ IL
160Ω
220Ω
Overview
1W
1N47xx 3.0 V 3.3 V 3.6 V 5.1 V 5.6 V 7.5 V 10.0 V 12 V 13 V 15.0 V 16.0 V 18.0 V 20.0 V 22.0 V 24.0 V 30.0 V 33.0 V 39.0 V
of
Z-diode values
BZX55Cxx 3.0 V 3.3 V 3.6 V 3.6 V 3.9V 4.3V 4.7 V 5.1 V 5.6 V 6.2 V 6.8 V 7.5 V 8.2 V 9.1 V 10.0 V 11.0 V 12.0 V 13.0 V 15.0 V 16.0 V 18.0 V 20.0 V 24.0 V 27.0 V
Overview of 0.5 W Z-diode values
RV Utotal - UZ Itotal = RV 12 V - 3,3 V 40 mA RV = 217,5 Ω ITOTAL Z-diode 1N4728
Table
1.6.1: 0.5 W Z-diodes
example
values =

The Schottky diode

The Schottky diode differs in construction from a silicon semiconductor diode in that the anode is not a p-doped semiconductor, but a low-capacitance metal electrode. Thus, the Schottky diode has a metal-semiconductor junction instead of the pn junction. This electron-depleted region is called the Schottky junction.

Schottky diodes are characterized by a low voltage drop of about 0.4 volts in the forward direction. A further advantage is very fast switching from the forward region to the reverse region and vice versa, with switching times of one to three nanoseconds. Due to the low forward voltage and the short switching time, Schottky diodes have a much lower power dissipation compared to a silicon diode.

The Schottky diode is used where fast switching is required or a low voltage drop is needed. Therefore, there are two types of Schottky diodes, one with reduced power consumption and one with extremely short switching times.

Anode Cathode

Schottky-diode

Blocking range

Forward

Anode

Cathode

The Schottky effect is named after the German physicist Walter Schottky (1886-1976).

66
Picture 1.6.8: Schottky diode - layer structure
U -V V R -IR IF UF 0.4 -50
Picture 1.6.7: Schottky diode circuit symbol Picture 1.6.9: Schottky diode characteristic
range n Metal SchottkyBarrier layer

Light Emitting Diode – LED

LED is the abbreviation for Light Emitting Diode. They are a special type of diode that converts electrical energy into light. They have almost identical electrical properties as a silicon semiconductor diode. That is why the symbol is similar to LED, except that it contains arrows indicating that the diode emits light.

LEDs are very widely used and there is a great variety of shapes, sizes and colors.

The structure of an LED is very different from that of an ordinary diode. The PN junction of an LED is surrounded by a transparent, rigid plastic envelope made of epoxy resin.

The envelope is designed in such a way that the light photons emitted by the junction are focused upward by the curved top surface of the LED, which itself acts like a lens. Consequently, the emitted light appears brightest at the top of the LED.

In the LED, the anode has a longer terminal than the cathode, and if you look closely, the anode is quite a bit thinner than the cathode.

Anode Cathode

Anode Cathode

Light / Photons

CATHODE

Functionality of LED

The LED has a very thin p-layer with a large hole density and it can only be operated in the forward direction. The free electrons pass through the PN junction and recombine with the holes. As these electrons fall from a high to a lower energy level, they radiate energy in the form of photons (light). Since the p-layer is very thin, the light can escape.

Light-emitting diodes are available in a wide range of colors, which can be produced by using different materials in the semiconductor crystal.

Unlike conventional diodes, which are made of germanium or silicon, LEDs are made of elements such as gallium, arsenic and phosphorus. By mixing these elements in varying proportions, LEDs can be made that emit different colors, as shown in the table below. ANODE

EVERYONE CAN DO IT!!!! 67
Picture 1.6.11: LED - structure of the layers Picture 1.6.10: LED circuit symbol
- + p n pn

Violet

Blue

Green

Yellow

Orange

Red

Aluminum nitride(ALN)

Aluminum gallium nitride (AIGaN)

Indium gallium nitride (InGaN)

Indium gallium nitride (InGaN)

Silicon carbide (SiC)

Gallium phosphide (GaP)

Aluminum gallium phospide (ALGaP)

Gallium arsenide phosphide (GaAsP)

Gallium phosphide (GaP)

Gallium arsenide phosphide (GaAsP)

Gallium phosphide (GaP)

Aluminum-gallium-arsenid (AIGaAs)

Gallium arsenide phosphide (GaAsP)

Gallium arsenide (GaAs)

Gallium phosphide (GaP) Infrared

Aluminum gallium arsenides(AIGaAs)

Calculate series resistor

To prevent the LED from being destroyed because it draws too much current, it is necessary to use a series resistor to limit the current I. In the example we use an orange LED and a supply voltage of 5 volts. We take 2 volts as the forward voltage of the LED and since LEDs already shine brightly with little current, we take I = 20 mA.

Note

If you don't know the exact values of your LED, then you can use 2 volts as a rule of thumb for the forward voltage and 20 mA current. From 10 mA most LEDs already shine quite strongly and you can check whether it should shine even brighter.

68 Color Wavelength (nm) Flow voltage UF (V) Material
<400 3,1 - 4,4
Ultraviolet
400-450 2,8 - 4,0
450-500 2,5
3,7
-
500-570 1,9 - 4,0
570-590 2,1 - 2,2
590-610 2,0 - 2,1
610-760 1,6
2,0
-
>760 >1,9
Table 1.6.3: Diode colors overview - please refer to the data sheet of the LED for details.
= RV Utotal- UF I = RV 5 V - 2 V 20 mA RV = 150 Ω 5V I Utotal UF UV RV LED

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.