Advertisement
silver2row

MCP3008 and LDR!

Nov 24th, 2019
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. from LDRone import MCP3008
  2. import time
  3.  
  4. adc = MCP3008(bus=0, device=0, vref=3.3)
  5.  
  6. while True:
  7.     voltage = adc.read(channel=0)                 # across resistor
  8.     current = voltage * 10000                       # through resistor and LDR
  9.     resistance = (adc.vref - voltage) / current     # of LDR
  10.     print("voltage: \t", voltage)
  11.     print("current: \t", current)
  12.     print("resistance: \t", resistance)
  13.     time.sleep(4)
  14.  
  15. #except:
  16.     print("MCP3008 and LDRs!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement