0% found this document useful (0 votes)
27 views14 pages

Sepk Lab7

The document outlines an experiment involving the use of an analogue to digital converter (ADC) with various sensors and actuators interfaced with a Raspberry Pi Pico microcontroller. The experiment has 7 objectives: 1) Control an LED by turning a potentiometer knob, 2) Swing a servo motor from left to right using the potentiometer, 3) Measure temperature using a thermistor module, 4) Calculate light intensity using an LDR light sensor, 5) Build a musical instrument that responds to light. By completing the objectives, students will gain experience with IoT fundamentals, micropython programming, and building circuits to establish communication between analogue and digital systems.

Uploaded by

ritikgbmrc
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)
27 views14 pages

Sepk Lab7

The document outlines an experiment involving the use of an analogue to digital converter (ADC) with various sensors and actuators interfaced with a Raspberry Pi Pico microcontroller. The experiment has 7 objectives: 1) Control an LED by turning a potentiometer knob, 2) Swing a servo motor from left to right using the potentiometer, 3) Measure temperature using a thermistor module, 4) Calculate light intensity using an LDR light sensor, 5) Build a musical instrument that responds to light. By completing the objectives, students will gain experience with IoT fundamentals, micropython programming, and building circuits to establish communication between analogue and digital systems.

Uploaded by

ritikgbmrc
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/ 14

IOTPP LAB

ASSIGNMENT
Familiarization with Analogue to
Digital Converter (ADC) using various
07 sensors and Actuators interfacing With
Raspberry Pi Pico and LEDs.
Aim:
Familiarization with Analogue to Digital Converter (ADC) using various sensors and
actuators interfacing with Raspberry Pi Pico and LEDs.

Objectives:
1) Introduction to Analogue to Digital Converter (ADC) Technique, its behaviour and applications.
2) Implementation of ADC on Micro-python with Raspberry Pi - Turn the Knob: Welcome to
Analog World.
3) Implementation of ADC on Micro-python with Raspberry Pi - Turn the Knob: Control an LED
using POT.
4) Implementation of Swinging Servo using Raspberry Pi with control systems that require constant
angle changes.
5) Implementation of Swing the servo from left to right using POT with ADC technique using
Raspberry Pi.
6) Implementation of Thermometer: Calculation of Temperature using thermistor module and
Raspberry Pi.
7) Implementation of a LDR Testing to calculate the Percentage of Light using LDR module and
Raspberry Pi.
8) Implementation of a Light Theremin: Electronic musical instrument using LDR module and
Raspberry Pi.
Summary of Experiment - 7 Goals and OutcomesBy
the end of this experiment, students will have gained a solid understanding of IoT fundamentals,
Raspberry Pi Pico, Python programming, and practical experience in building and controlling
IoT-related hardware to establish communication between the analogue and digital world.
These skills will facilitate as a strong foundation for more complex IoT projects in the future.

Pre-Lab Questionnaire:
1) What is the resolution of the ADC on the Raspberry Pi Pico?
2) How many ADC channels does the Raspberry Pi Pico have?
3) What is the maximum sample rate of the ADC on the Raspberry Pi Pico?
4) How do you configure and use the ADC on the Raspberry Pi Pico in MicroPython?
5) How does the voltage range of the ADC on the Raspberry Pi Pico affect the resolution?
6) What is the voltage range of the ADC on the Raspberry Pi Pico?
7) How is the voltage level measured by the ADC on the Raspberry Pi Pico converted to a
digital value?
8) How does the number of bits in the ADC resolution affect the accuracy of the readings?
9) How can you reduce noise in the readings from the ADC on the Raspberry Pi Pico?
10) What is the input impedance of the ADC on the Raspberry Pi Pico?

Components/Equipment Required:
Sl. Name of the Specification Quantity
No. Component / Equipment
1) Raspberry Pi Pico RP2040 microcontroller chip, 1
125MHz
2) Raspberry Pi Pico cable USB Type A to Micro-B 1
3) Resistors (carbon type) ¼ watt (330 Ω) 1
4) LED 3mm, Red 1
5) Trimmer Pot 10k 1
6) Mini Servo Motor SG 90, Plastic Gear 1
7) Thermister Module KY-013 Analog Temperature Sensor 1
Module
8) LDR Light Sensor 5mm 1
9) Transistor NPN, 2N2222 1
10) Buzzer Active, Small 1
11) Breadboard 840 Tie points 1
12) Jumper Wire --------------------------- As per requirement

Objective 1
Objective 2
Implementation of ADC on Micro-python with Raspberry Pi Pico- Turn the Knob: Welcome to
Analog World.

Circuit/Schematic Diagram:

(Figure 1: Circuit diagram for implementation of ADC on Micro-python with


Raspberry Pi Pico - Turn the Knob: Welcome to Analog World.)
Code

2.1: write a program that implement an ADC on Micro-python with Raspberry Pi Pico-
Turn the Knob: Welcome to Analogue World.

import machine
import utime
analog_value = machine.ADC(28)
while True:
reading = analog_value.read_u16()
print("ADC: ",reading)
utime.sleep(0.2)

Observation

Figure 2: (Simulation based electronic circuit for implementation of ADC on Micro-python with
Raspberry Pi - Turn the Knob: Welcome to Analog World.)
Figure 3: (Hardware based electronic circuit for implementation of ADC on Micro-python with
Raspberry Pi - Turn the Knob: Welcome to Analog World.)

Objective 3
Implementation of ADC on Micro-python with Raspberry Pi Pico- Turn the Knob: Control an
LED using POT.
Circuit/Schematic Diagram:

(Figure 4: Circuit diagram for implementation of ADC on Micro-python with Raspberry Pi Pico- Turn the Knob:
Control an LED using POT.)

Code

3.1: Write a program that implementation of ADC on Micro-python with Raspberry Pi


Pico - Turn the Knob: Control a LED using POT.

import machine
import utime
potentiometer = machine.ADC(28)
led = machine.PWM(machine.Pin(15))
led.freq(1000)
while True:
value=potentiometer.read_u16()
print(value)
led.duty_u16(value)
utime.sleep_ms(200)
Observation

Figure 5: (Simulation based electronic circuit for implementation of ADC on Micro-python with
Raspberry Pi - Turn the Knob: Control a LED using POT .)

Figure 6: (Hardware based electronic circuit for implementation of ADC on Micro-python with
Raspberry Pi - Turn the Knob: Control a LED using POT .)

Objective 4
4.1. Implementation of Swinging Servo using Raspberry Pi Pico with control systems that
require constant angle changes.

Circuit / Schematic Diagram

(Figure 7: Circuit diagram for implementation of Swinging Servo using Raspberry Pi with control systems that
require constant angle changes.)
Code

4.1: write a program for the implementation of Swinging Servo using Raspberry Pi Pico
with control systems that require constant angle changes.

from machine import Pin, PWM


from utime import sleep_ms

servo = PWM(Pin(15))
servo.freq(50)
def interval_mapping(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
def servo_write(pin, angle):
pulse_width=interval_mapping(angle, 0, 180, 0.5,2.5)
duty=int(interval_mapping(pulse_width, 0, 20, 0,65535))
pin.duty_u16(duty)
while True:
for angle in range(180):
servo_write(servo, angle)
sleep_ms(20)
for angle in range(180,-1,-1):
servo_write(servo, angle)
sleep_ms(20)

Observation

Figure 8: (Simulation based Swinging Servo using Raspberry Pi Pico with control systems
that require constant angle changes.)
Figure 9: (Hardware based Swinging Servo using Raspberry Pi Pico with control systems
that require constant angle changes.)

Objective 5
5.1: write a program for the implementation of Swing the servo from left to right using POT
with ADC technique using Raspberry Pi Pico.

Circuit / Schematic Diagram

(Figure 10: Circuit diagram for implementation of Swing the servo from left to right using POT with ADC
technique using Raspberry Pi.)

Code

5.1: write a program for the implementation of Swing the servo from left to right using POT
with ADC technique using Raspberry Pi Pico.

from machine import Pin, PWM


import utime
potentiometer = machine.ADC(28)
servo = machine.PWM(machine.Pin(15))
servo.freq(50)

def interval_mapping(x, in_min, in_max, out_min, out_max):


return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
def servo_write(pin, angle):
pulse_width=interval_mapping(angle, 0, 180, 0.5,2.5)
duty=int(interval_mapping(pulse_width, 0, 20, 0,65535))
pin.duty_u16(duty)
while True:
value=potentiometer.read_u16()
angle=interval_mapping(value, 0,65535,0,180)
servo_write(servo, angle)
utime.sleep_ms(200)

Observation

Figure 11: (Simulation based Swing the servo from left to right using POT with ADC technique using
Raspberry Pi Pico.)

Figure 12: (Hardware based Swing the servo from left to right using POT with ADC technique using
Raspberry Pi Pico.)

Objective 6
6.1 Implementation of Thermometer: Calculation of Temperature using thermistor module
and Raspberry Pi Pico
Circuit / Schematic Diagram

(Figure 13: Circuit diagram for implementation of Thermometer: Calculation of Temperature using thermistor
module and Raspberry Pi.)
Code

Write a program for implementation of Thermometer: Calculation of Temperature using


thermistor module on Micro-python with Raspberry Pi Pico.

from machine import ADC


import utime
import math
thermistor = ADC(28)
while True:
temperature_value = thermistor.read_u16()
Vr = 3.3 * float (temperature_value) / 65535
Rt = 10000 * Vr / (3.3 - Vr)
temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15+25)))
Cel = temp - 273.15
Fah = Cel * 1.8 + 32
print ('Celsius: %.2f C Fahrenheit: %.2f F' % (Cel, Fah))
utime.sleep_ms(200)

Observation

Figure 14: (Simulation-based electronic circuit for implementation of Thermometer: Calculation of


Temperature using thermistor module with Raspberry Pi Pico.)

Figure 15: (Hardware implementation based electronic circuit for implementation of Thermometer:
Calculation of Temperature using thermistor module with Raspberry Pi Pico.)
Objective 7
7.1. Implementation of a LDR Testing to calculate the Percentage of Light using LDR module
on Micro-python with Raspberry Pi Pico.

Circuit / Schematic Diagram

(Figure 16: Circuit diagram for implementation of a LDR Testing to calculate the Percentage of Light using LDR
module and Raspberry Pi.)

Code

Write a program for implementation of a LDR Testing to calculate the Percentage of Light
using LDR module on Micro-python with Raspberry Pi Pico.

from machine import ADC, Pin


from time import sleep
photoPIN = 28
def readLight (photoGP):
photoRes = ADC(Pin(28))
light = photoRes.read_u16()
light = round(light/65535*100,2)
return light
while True:
print("light: "+ str(readLight (photoPIN)) +"%")
sleep (1)

Observation

Figure 17: (Simulation-based electronic circuit for implementation of a LDR Testing to calculate the
Percentage of Light using LDR module and Raspberry Pi Pico.)
Figure 18: (Hardware implementation based electronic circuit for implementation of a LDR Testing to
calculate the Percentage of Light using LDR module and Raspberry Pi Pico.)

Objective 8
8.1. Implementation of a Light Theremin: Electronic musical instrument using LDR module
on Micro-python and Raspberry Pi Pico.
Circuit / Schematic Diagram

(Figure 19: Circuit diagram for implementation of a Light Theremin: Electronic musical instrument using LDR
module and Raspberry Pi.)

Code

Write a program for implementation of a Light Theremin: Electronic musical instrument


using LDR module on Micro-python and Raspberry Pi Pico.

from machine import Pin, PWM, ADC


import utime
led = Pin(16, Pin.OUT)
photoresistor = ADC(28)
buzzer = PWM(Pin(15))
light_low=65535
light_high=0

def interval_mapping(x, in_min, in_max, out_min, out_max):


return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
def tone(pin, frequency, duration):
pin.freq(frequency)
pin.duty_u16(30000)
utime.sleep_ms(duration)
pin.duty_u16(0)
# calibrate the photoresistor max & min values.
timer_init_start = utime.ticks_ms()
led.value(1)
while utime.ticks_diff(utime.ticks_ms(), timer_init_start)<5000:
light_value = photoresistor.read_u16()
if light_value > light_high:
light_high = light_value
if light_value < light_low:
light_low = light_value
led.value(0)
# play
while True:
light_value = photoresistor.read_u16()
pitch = int(interval_mapping(light_value, light_low,light_high,50,6000))
if pitch > 50:
tone(buzzer, pitch, 20)
utime.sleep_ms(10)

Observation

Figure 20: (Hardware implementation based electronic circuit for implementation of a Light
Theremin: Electronic musical instrument using LDR module and Raspberry Pi Pico.)

Post Experiment Questionnaire:


Answer all the Questions in brief with some appropriate examples.
1) A voltage of 2.5V is applied to the ADC on the Raspberry Pi Pico. The ADC has a resolution of
12 bits and a voltage range of 0-3.3V. What is the digital value that represents this voltage?
2) A voltage of 1.8V is applied to the ADC on the Raspberry Pi Pico. The ADC has a resolution of
12 bits and a voltage range of 0-3.3V. What is the digital value that represents this voltage?
3) A digital value of 3500 is read from the ADC on the Raspberry Pi Pico. The ADC has a resolution
of 12 bits and a voltage range of 0-3.3V. What is the voltage that this digital value represents?
4) A signal with a frequency of 50Hz is applied to the ADC on the Raspberry Pi Pico. The maximum
sample rate of the ADC is 15ksps. Will the ADC be able to accurately sample the signal?
5) A voltage of 2.1V is applied to the ADC on the Raspberry Pi Pico. The ADC has a resolution of
12 bits and a voltage range of 0-3.3V. How accurate the reading will be?
6) A digital value of 2000 is read from the ADC on the Raspberry Pi Pico. The ADC has a resolution
of 12 bits and a voltage range of 0-3.3V. How to calculate the percentage error if the actual voltage
was 2.5V?
(Signature of the Faculty) (Signature of the Student)
Name:
Date: Registration No.:
Branch:
Section

You might also like