Tommaso Martorellasilvia11931
Published © GPL3+

How to Read an Analog Sensor with Zerynth (Python for IoT)

In this tutorial, we'll see how to read data from a light analog sensor and print them to the serial monitor in a visual way.

BeginnerFull instructions provided1 hour1,465
How to Read an Analog Sensor with Zerynth (Python for IoT)

Things used in this project

Hardware components

Adafruit ALS-PT19 Analog Light Sensor
×1
ESP32S
Espressif ESP32S
×1

Software apps and online services

Zerynth Studio
Zerynth Studio

Story

Read more

Schematics

schematics

Code

AnalogReadToVoltage.py

Python
################################################################################
# Analog Read to Voltage
#
# Created by Zerynth Team 2015 CC
# Authors: G. Baldi, D. Mazzei
################################################################################

import streams
import adc      # import the adc module  

#create a serial port stream with default parameters
streams.serial()

#define the analog pin for reading the value 
inputAnalog = A0

#set the pin as input with INPUT_ANALOG,
pinMode(inputAnalog,INPUT_ANALOG)

while True:
       
    #read the input on analog pin 0
    sensorValue = adc.read(inputAnalog)
    
    #convert the analog reading (which goes from 0 - 4095.0) to a voltage (0 - 3.3V):
    voltage = sensorValue * (3.3 / 4095.0)
    
    #print out the raw and converted values:
    print("sensor raw value:", sensorValue,"Voltage:",voltage)
    
    sleep(300)

Oscilloscope.py

Python
###############################################################################
# Zerynth oscilloscope
#
# Created by Zerynth Team 2015 CC
# Authors: G. Baldi, D. Mazzei
###############################################################################

import streams
import adc
   
streams.serial()

while True:
    value = adc.read(A4)
    conv = value*80//4095
    print("|","#"*conv," "*(80-conv),"|")
    sleep(200)
    

Credits

Tommaso Martorella

Tommaso Martorella

8 projects • 4 followers
silvia11931

silvia11931

10 projects • 9 followers

Comments