Instructions
KY-018 Photoresistor module
ADS1015 = 0x00 # 12-bit ADC
ADS1115 = 0x01 # 16-bit
# choosing the amplifing gain
gain = 4096 # +/- 4.096V
# gain = 2048 # +/- 2.048V
# gain = 1024 # +/- 1.024V
# gain = 512 # +/- 0.512V
# gain = 256 # +/- 0.256V
# choosing the sampling rate
# sps = 8 # 8 Samples per second
# sps = 16 # 16 Samples per second
# sps = 32 # 32 Samples per second
sps = 64 # 64 Samples per second
# sps = 128 # 128 Samples per second
# sps = 250 # 250 Samples per second
# sps = 475 # 475 Samples per second
# sps = 860 # 860 Samples per second
# assigning the ADC-Channel (1-4)
adc_channel_0 = 0 # Channel 0
adc_channel_1 = 1 # Channel 1
adc_channel_2 = 2 # Channel 2
adc_channel_3 = 3 # Channel 3
# initialise ADC (ADS1115)
adc = ADS1x15(ic=ADS1115)
#######################################################################################
# ########
# Main Loop
# ########
# Reading the values from the input pins and print to console
try:
while True:
#read values
adc0 = adc.readADCSingleEnded(adc_channel_0, gain, sps)
adc1 = adc.readADCSingleEnded(adc_channel_1, gain, sps)
adc2 = adc.readADCSingleEnded(adc_channel_2, gain, sps)
adc3 = adc.readADCSingleEnded(adc_channel_3, gain, sps)
# print to console
print "Channel 0:", adc0, "mV "
print "Channel 1:", adc1, "mV "
print "Channel 2:", adc2, "mV "
print "Channel 3:", adc3, "mV "
print "---------------------------------------"
time.sleep(delayTime)
except KeyboardInterrupt:
GPIO.cleanup()
Connections Raspberry Pi:
Sensor
GND = GND [Pin 06(RPi)]
+V = 3,3V [Pin 01(RPi)]
Export: 16.06.2017 Copyright by Joy-IT - Published under CC BY-NC-SA 3.0 Page 77 of 214










