ADC and Pico – Trimmer, LDR and Thermistor

Next is ADC ! We are connecting variable resistances which change based on light, temperature and manual control to test


# import machine, imports the Pico's functions and definitions
import machine
# imports time based functions
import utime
# Potentiometer to GPIO 26
potentiometer = machine.ADC(26)
# LDR GPIO 27
LDR = machine.ADC(27)
# Thermistor to GOIP 28
thermistor = machine.ADC(28)

conversion_factor = 100 / (65535) # Trying to get a percentage, else add VCC / 65535 (16 BIT max)

while True: #runs infinite 
 potScore = round(potentiometer.read_u16() * conversion_factor,0)
 print("Potentiometer score :" , int(potScore))
 
 LDRScore = round(LDR.read_u16() * conversion_factor,0)
 print("LDR score :" , int(LDRScore/2))
 
 tempScore = round(thermistor.read_u16() * conversion_factor,0)
 print("Temperature score :" , int(tempScore))
 
 #delay for 2 seconds
 utime.sleep(2)

Move the trimmer, shine some light on the LDR and light a matchstick near the thermistor. You will see the numbers change on the serial monitor.

This entry was posted in Electronics, raspberrypipico and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *