Javier Adrián Liu Manzanilla
Published © GPL3+

LDR, LED, CHIP and Python

LDR detect luminosity and ON/OFF LED. using CHIP and Python.

BeginnerProtip1 hour2,996
LDR, LED, CHIP and Python

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×1
Photo resistor
Photo resistor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×8
C.H.I.P.
C.H.I.P.
×1

Story

Read more

Schematics

L.D.R., L.E.D., C.H.I.P.

This is the schematics (i will improve)

Breadboard Diagram

This is an idea for connect the components

Diagram

Code

Python Code (link library in DOCS)

Python
Please, before trying the code, first visit this site https://github.com/xtacocorex/CHIP_IO and follow the instructions for using the GPIO library.

This is a very basic code in Python, the comments import CHIP_IO.GPIO as GPIO # is where the magic being,
import os # is just for use command in terminal
import time # control the time with sleep

This code: time.strftime("%c") # just get the date and time when success the On/Off led

The last line GPIO.cleanup() # clean up the GPIO

Beginners for run the code type in terminal: python filename.py

NOTE: Press Ctrl - C for stop the code.

Comments are important for improve. Have a nice day and enjoy some ice cream.
#-*-coding:utf-8-*-
#!/usr/bin/python

import os # Just for use some commands in the terminal
import CHIP_IO.GPIO as GPIO # Make the magic
import time # Just for sleep and wait some time

GPIO.setup("XIO-P0", GPIO.IN) # port use for INPUT
GPIO.setup("XIO-P1", GPIO.OUT) # port use for OUTPUT

os.system('clear') # Just for presentation
print("Iniciando sistema espere porfavor ...")
time.sleep(3)
print("Comenzando secuencia en 3")
time.sleep(1)
print("2")
time.sleep(1)
print("1")
time.sleep(1)

while(True): # No finish cicle
    if(not GPIO.input("XIO-P0")): # NOT change the value detect in the port
        GPIO.output("XIO-P1", 1) # Turn On LED
        time.sleep(2) # Wait X seconds
        print("Encendido :D " + time.strftime("%c")) # Message with date
    else:
        GPIO.output("XIO-P1", 0) # Turn Off LED
        time.sleep(2)
        print("Apagado :)" + time.strftime("%c"))

GPIO.cleanup() # Clean up the GPIO

A CHIP IO library

Library mentioned in DOCS, please read and follow instructions, is very easy

Credits

Javier Adrián Liu Manzanilla

Javier Adrián Liu Manzanilla

1 project • 1 follower

Comments