Skip to content

Instantly share code, notes, and snippets.

@greenbreakfast
Last active July 14, 2019 01:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenbreakfast/e2c6c98809621de478b7e6073f393944 to your computer and use it in GitHub Desktop.
Save greenbreakfast/e2c6c98809621de478b7e6073f393944 to your computer and use it in GitHub Desktop.
How to Build IoT Sensors using Python
import time
import os
# Import the ADC Expansion module.
from OmegaExpansion import AdcExp
# create ADC Expansion object
adc = AdcExp.AdcExp()
#infinite loop to read sensors and display data
while 1:
# read ADC channels
a0 = adc.read_voltage(0)
a1 = adc.read_voltage(1)
# a2 = adc.read_voltage(2)
a3 = adc.read_voltage(3)
# convert temperature sensor voltage to temperature
temp = (a0 - 0.5) * 100
# convert soil sensor voltage to percentage
soil = (a1 / 5) * 100
# convert light sensor voltage to lux
rPhoto = 5.0 / a3 * 1000 - 1000
lux = 500/(rPhoto/1000)
# clear screen
os.system('cls' if os.name == 'nt' else 'clear')
# write sensor readings to screen
print('''
Temperature\t| %.02f C
Soil Moisture\t| %.02f %%
Light Intensity\t| %d lux
'''%(temp, soil, lux))
#wait half a second
time.sleep (0.5)
@JDRValverde
Copy link

Great work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment