Last active
July 14, 2019 01:05
-
-
Save greenbreakfast/e2c6c98809621de478b7e6073f393944 to your computer and use it in GitHub Desktop.
How to Build IoT Sensors using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great work.