MODULE 2

Embedded Systems [II]

An Electronic circuit is a complete circular path that electricity flows through. It directs and controls electric current to perform various functions.

Electrical components:These are elements in electrical circuits that perform specific functions to control, regulate, or manipulate
the flow of electric current.

These components can be classified into two :

Active components are electronic devices that can control the flow of electrical current.
They require a power source to operate and can amplify, switch, or generate electrical signals.
They include transistors,micro-controllers

Passive components are electronic devices that do not require a power source to perform their specified function.
They do not control the flow of electrical current but instead modify or store it.
They include resistors, capacitors, inductors, transformers, and diodes.


A circuit has three essential components that work together to enable current flow:

a conductive path- a pathway for current to pass through...wire
a power source-for providence of electrical energy(battery)
a load-any device that needs electric power to operate

Traffic lights using LEDS with PI PICO

with the code below:

from machine import Pin
from time import sleep

one= Pin(0,Pin.OUT)
two= Pin(1,Pin.OUT)
three= Pin(2,Pin.OUT)

#button=Pin(1,Pin.IN,Pin.PULL_UP)

while True:

one.value(1)
two.value(0)
three.value(0)

one.value(0)
two.value(1)
three.value(0)

one.value(0)
two.value(0)
three.value(1)

>

Controlling an LED using pushbutton

from machine import Pin
from utime import sleep_ms

button = Pin(0, Pin.IN, Pin.PULL_UP) #Internal pull-up
led = Pin(1, Pin.OUT)
State = 0

if __name__ == '__main__':
while True:
print(button.value())
if button.value() == 0: #key press
if State == 0:
led.value(1)
sleep_ms = 100
while button.value() == 0:
State = 1
else:
led.value(0)
sleep_ms = 100
while button.value() == 0:
State = 0

Sensor- a device that detect/ senses physical phenomenon then reacts to it in a particular way.
It converts physical attributes to electric signal.
eg..Ultrasonic sensor which sends out soundwaves and measures the time it takes for the sound to be reflected back.

Actuator- is a part of a device that achieves physical movement by converting energy to mechanical force.
It controls movement or positioning.
An actuator recieves and acts on the information given.Initially it relies on the sensor for info inorder for it to work.

Here is a simple project using an ultrasonic sensor

from machine import Pin

import utime
trigger = Pin(3, Pin.OUT)
echo = Pin(2, Pin.IN)
led =Pin(4, Pin.OUT)
buzzer= Pin(5, Pin.OUT)
led.value(0)
buzzer.value(0)

def ultra():
trigger.low()
utime.sleep_us(2)
trigger.high()
utime.sleep_us(5)
trigger.low()

while echo.value() == 0:
signaloff = utime.ticks_us()

while echo.value() == 1:

timepassed = signalon - signaloff
distance = (timepassed * 0.0343) / 2
return distance

while True:
measured_distance = ultra()
if measured_distance <= 50:
print("The distance from the object is ", measured_distance, "cm")
led.value(1)
buzzer.value(1)
utime.sleep(1)
led.value(0)
buzzer.value(0)
break

utime.sleep(1)