0% found this document useful (0 votes)
3 views15 pages

Circuit Components and Sensors: For Microcontroller Programming

The document provides an overview of circuit components, sensors, and programming for microcontrollers, emphasizing the use of breadboards for prototyping and essential components like LEDs, resistors, and batteries. It details the types of sensors (digital and analog) and their functions, followed by an introduction to MicroPython modules and libraries for coding. A beginner-friendly example of a MicroPython program is included, demonstrating how to make an LED blink using basic programming concepts.

Uploaded by

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

Circuit Components and Sensors: For Microcontroller Programming

The document provides an overview of circuit components, sensors, and programming for microcontrollers, emphasizing the use of breadboards for prototyping and essential components like LEDs, resistors, and batteries. It details the types of sensors (digital and analog) and their functions, followed by an introduction to MicroPython modules and libraries for coding. A beginner-friendly example of a MicroPython program is included, demonstrating how to make an LED blink using basic programming concepts.

Uploaded by

arunadevy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Circuit Components and Sensors

For Microcontroller Programming


Breadboard:The Foundation of Prototyping
● A solderless breadboard allows for quick circuit
prototyping without permanent connections

● Columns are connected vertically in the power rails


(usually marked with + and -)

● Rows are connected horizontally in the component


rail

● The center channel divides the breadboard,


separating connections between the two sides

● Perfect for testing circuits before creating


permanent connections
Basic Circuit Components

Essential components needed for microcontroller circuits include LEDs, resistors, batteries, and jumper wires. These
components work together to create functional electronic projects.

LEDs Resistors
Convert electrical energy to light Limit current flow in circuits
Longer leg is positive(anode) Measured in ohms (Ω) Color
Require current-limiting resistor bands indicate value

Batteries
Provide power to the circuit
Common types: AA, AAA, 9V
Check voltage requirements
Introduction to Sensors
● Sensors are devices that detect changes in the
environment and convert them into electrical signals

● They act as the "senses" of your microcontroller


project, allowing it to interact with the world

● Sensors enable projects to respond to temperature,


light, motion, sound, and many other physical
phenomena

● They are essential components for creating interactive


and responsive systems

Digital Sensors Analog Sensors


Output discrete values(0sand1s) Example: Output continuous range of values
Push button Example: Temperature sensor, light sensor
Digital Sensors
● Digital sensors output discrete values,
typically represented as HIGH(1)or LOW(0)
Digital Signal Output
● They provide binary information: on/off, present/absent,
detected/not detected 1

● Connect directly to digital pins on microcontrollers


0
without additional conversion Time

● Often use threshold-based detection internally

Push Button/Switch Hall Effect Sensor


Detects physical press Detects magnetic fields
Output:0(not pressed)or1(pressed) Output:0(no magnet)or1(magnet present)

IR Obstacle Sensor Tilt Sensor Reed Switch


Detects objects using infrared Detects orientation changes Detects magnetic proximity
Output:0(no obstacle)or1(obstacle detected) Output:0(normal)or1(tilted) Output:0(open)or1(closed)
Analog Sensors
● Analog sensors output continuous range of values that
Vary with the measured quantity

● They provide precise measurements rather than just


AnalogSignalOutput

on/off states
Max

● Require Analog-to-Digital Converter (ADC) pins on


microcontrollers 0V
Time
● Outputvoltagetypicallyrangesfrom0VtoVCC(often
3.3V or 5V)

Temperature Sensor Light Sensor(LDR) Potentiometer


Measures ambient temperature Measures light intensity Variable resistor for manual input
Examples: LM35, TMP36, thermistor Resistance changes with light level Used for control knobs,
sliders

Soil Moisture Sensor Flex Sensor Gas/Air Quality Sensor


Measures water content in soil Measures degree of bending Measures concentration of gases
Used in smart gardening projects Used in motion capture, robotics Examples:MQ-2,MQ-135
Coding in Micropython

Grade 7
MODULES
• In MicroPython, a module is a file that
contains Python code, including functions,
classes, and variables
• Modules help in organizing code and making
it reusable
• You can import a module into your
MicroPython program to use its functions and
classes.
Library
• A library is a collection of modules that
provide additional functionality for your
projects
• Libraries extend the capabilities of your code
by providing pre-written functions and classes.
• MicroPython includes several built-in libraries
you can use.
machine library— functions related to
the hardware
• contains specific functions related to the
hardware on a particular board
• Most functions in this module allow to
achieve direct and unrestricted access to and
control of hardware blocks on a system (like
CPU, timers, buses, etc.)
utime library– time related functions

• The utime module provides functions for


getting the current time and date, measuring
time intervals, and for delays.
• utime.sleep(seconds)
Sleep for the given number of seconds.
MicroPython LED Blink Code - Line by
Line Explanation
This is a beginner-friendly explanation of the BLINK.PY code that makes an LED blink on
and off.

What This Program Does


This program makes an LED (Light Emitting Diode) connected to a microcontroller blink
3 times. Each blink cycle turns the LED on for 1 second, then off for 1 second.

Line-by-Line Breakdown

Line 1: #library files

• What it is: This is a comment (indicated by the # symbol)


• What it means: Comments are notes for humans to read - the computer ignores
them completely
• Purpose: This comment tells us that the next lines will import library files

Line 2: (Empty line)

• What it is: A blank line


• Purpose: Makes the code easier to read by separating different sections

Line 3: import machine

• What it is: An import statement


• What it means: This tells MicroPython to load the "machine" library
• Why we need it: The machine library contains functions to control hardware like
pins, LEDs, sensors, etc.
• Think of it like: Getting a toolbox that contains tools to control the physical parts
of your microcontroller

Line 4: import utime

• What it is: Another import statement


• What it means: This loads the "utime" library (micro-time)
• Why we need it: This library helps us work with time - like making the program
wait/pause
• Think of it like: Getting a stopwatch to control timing in your program

Line 5: (Empty line)

• Purpose: Another blank line to separate the imports from the main code

Line 6: #variable declaration

• What it is: Another comment


• Purpose: Tells us that the next line will create a variable

Line 7: led=machine.Pin(25,machine.Pin.OUT)

• What it is: Variable creation and pin setup


• Breaking it down:
• led = This creates a variable named "led"
• = = This assigns a value to the variable
• machine.Pin(25,machine.Pin.OUT) = This sets up pin number 25 as an output pin
• What it means: We're telling the microcontroller that pin 25 will be used to control
an LED, and we can send signals OUT to it
• Think of it like: Labeling a specific wire (pin 25) as "led" and saying "this wire will
send power out to light up an LED"

Line 8: (Empty line)

• Purpose: Separates the setup from the main program logic

Line 9: for i in range(3):

• What it is: A "for loop" that repeats code


• Breaking it down:
• for = Start a loop
• i = A counter variable (could be any name)
• in range(3) = Repeat 3 times (0, 1, 2)
• : = Indicates that the next indented lines belong to this loop
• What it means: "Do the following actions 3 times"
• Think of it like: "Repeat these steps 3 times"
Line 10: (Empty line)

• Purpose: Makes the code inside the loop easier to read

Line 11: utime.sleep(1)

• What it is: A pause/delay command


• What it means: Make the program wait for 1 second before continuing
• Why it's here: This creates a delay before turning the LED on
• Think of it like: "Wait 1 second"

Line 12: led.on()

• What it is: A command to turn on the LED


• What it means: Send power to pin 25, which lights up the LED
• Breaking it down:
• led = The variable we created earlier (referring to pin 25)
• .on() = A function that turns the pin on (sends power)
• Think of it like: "Turn on the light switch"

Line 13: print("led on")

• What it is: A print statement


• What it means: Display the text "led on" on the computer screen/console
• Purpose: Helps us see what the program is doing (for debugging)
• Think of it like: The program is telling us "Hey, I just turned the LED on!"

Line 14: (Empty line)

• Purpose: Separates the "LED on" section from the "LED off" section

Line 15: utime.sleep(1)

• What it is: Another 1-second pause


• Purpose: Keep the LED on for 1 second before turning it off
• Think of it like: "Keep the light on for 1 second"

Line 16: led.off()

• What it is: A command to turn off the LED


• What it means: Stop sending power to pin 25, which turns off the LED
• Breaking it down:
• led = Our pin 25 variable
• .off() = A function that turns the pin off (stops power)
• Think of it like: "Turn off the light switch"

Line 17: print("led off")

• What it is: Another print statement


• What it means: Display "led off" on the screen
• Purpose: Tells us the LED has been turned off
• Think of it like: The program saying "I just turned the LED off!"

How the Complete Program Works


1. Setup Phase: The program imports necessary libraries and sets up pin 25 to
control an LED
2. Loop Phase: The program repeats the following 3 times:
3. Wait 1 second
4. Turn LED on and print "led on"
5. Wait 1 second
6. Turn LED off and print "led off"
7. Result: The LED blinks 3 times, with each blink lasting 2 seconds total (1 second
on, 1 second off)

Key Programming Concepts Demonstrated


• Comments: Using # to add notes
• Importing libraries: Using import to get additional functions
• Variables: Storing values with names like led
• Functions: Using built-in functions like .on() , .off() , sleep() , print()
• Loops: Using for to repeat code multiple times
• Hardware control: Controlling physical components (LED) with code

This is a perfect beginner program because it combines basic programming concepts


with visible, physical results!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy