Back to Browse

Raspberry Pi Workshop Kit Tutorials - 8 Light Dependent Resistor

1.5K views
Jun 15, 2017
7:15

Welcome to the Raspberry Pi Workshop Tutorials, brought to you by ModMyPi, BuyaPi.ca, and PiShop.us. In this series, we’ll demonstrate nine projects that can be made using the YouTube Workshop Kit for Raspberry Pi. These projects are a great way to familiarize yourself with the Pi’s input and output functions, as well as creating programs in Python that we’ll use to control the Pi’s hardware. Tutorial 8 - Light Dependent Resistor Circuit Diagram: http://www.modmypi.com/download/led_button_buzzer_temp_ldr_bb.png Tutorial 8 download: http://www.modmypi.com/download/youtube_workshop_8_ldr.pdf View Tutorial Online: https://www.modmypi.com/blog/youtube-workshop-kit/gpio-and-python-89-ldr *** Code Used In This Tutorial *** #!/usr/bin/python import os import datetime from time import sleep import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) def RCtime (RCpin): reading = 0 GPIO.setup(RCpin, GPIO.OUT) GPIO.output(RCpin, GPIO.LOW) sleep(.1) GPIO.setup(RCpin, GPIO.IN) # This takes about 1 millisecond per loop cycle while (GPIO.input(RCpin) == GPIO.LOW): reading += 1 return reading while True: GetDateTime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") LDRReading = RCtime(3) print RCtime(3) # Open a file fo = open("/home/pi/gpio_python_code/foo.txt", "wb") fo.write (GetDateTime) LDRReading = str(LDRReading) fo.write ("\n") fo.write (LDRReading) # Close opened file fo.close() sleep(1)

Download

0 formats

No download links available.

Raspberry Pi Workshop Kit Tutorials - 8 Light Dependent Resistor | NatokHD