Difference between revisions of "KY-027 Magic light cup module"

From SensorKit X40 Wiki

Jump to: navigation, search
(No summary)
(No summary)
Line 1: Line 1:
 
==Picture==
 
==Picture==
[[File:ky-027.jpg|358x358px|none]]
+
[[File:ky-027.jpg|none|358x358px]]
  
 
==Technical data / Short description==
 
==Technical data / Short description==
Line 18: Line 18:
  
 
==Pinout==
 
==Pinout==
[[File:4_Pin-LightCup.png|500x262px|none]]
+
[[File:4_Pin-LightCup.png|none|500x262px]]
  
 
==Code example Arduino==
 
==Code example Arduino==
Line 76: Line 76:
 
'''Example program download'''
 
'''Example program download'''
  
[[Medium:SensorTest_Arduino.zip|SensorTest_Arduino.zip]]
+
[http://sensorkit.joy-it.net/images/a/a7/SensorTest_Arduino.zip SensorTest_Arduino.zip]
  
 
==Code example Raspberry Pi==
 
==Code example Raspberry Pi==
Line 142: Line 142:
 
'''Example program download'''
 
'''Example program download'''
  
[[Medium:KY-027-RPi-MagicLightCup.zip|KY-027-RPi-MagicLightCup.zip]]
+
[http://sensorkit.joy-it.net/images/c/cb/KY-027-RPi-MagicLightCup.zip KY-027-RPi-MagicLightCup.zip]
  
 
To start with the command:
 
To start with the command:

Revision as of 19:28, 20 March 2017

Picture

ky-027.jpg

Technical data / Short description

The LED will be switched on and off by vibration. The signal will be send to the output if the LED is on. You need pre-resistors for some voltages.


Pre-resistor:

Rf (3,3V) [Red]= 120Ω

[used with ARM CPU-Core based microcontroller like Raspberry-Pi]


Rf (5V) [Red] = 220Ω 

[used with Atmel Atmega based microcontroller like Arduino]

Pinout

4 Pin-LightCup.png

Code example Arduino

It is an example program wich lights up the LED from Magic-Light Cup-module if the sensor detects gradient.

int Led = 13 ;// Declaration of the LED-output pin
int Sensor = 10; // Declaration of the sensor input pin
int val; // Temporary variable
 
void setup ()
{
  pinMode (Led, OUTPUT) ; // Initialization output pin
  pinMode (Sensor, INPUT) ; // Initialization sensor pin
  digitalWrite(Sensor, HIGH); // Activating of the internal pull-up resistor
}
 
void loop ()
{
  val = digitalRead (Sensor) ; // The current signal from the sensor will be read
 
  if (val == HIGH) // If a signal will be detected, the LED will light up.
  {
    digitalWrite (Led, LOW);
  }
  else
  {
    digitalWrite (Led, HIGH);
  }
}

Connections Arduino:

LED + = [Pin 13]
LED - = [Pin GND]
Sensor signal = [Pin 10]
Sensor +V = [Pin 5V]
Sensor - = [Pin GND]

Example program download

SensorTest_Arduino.zip

Code example Raspberry Pi

Program example in the language python

The LED will light up, in this example, if a signal will be detected.

# Needed modules will be imported and configured.
import RPi.GPIO as GPIO
import time
  
GPIO.setmode(GPIO.BCM)
  
# Declaration of the LED and sensor pins
LED_PIN = 24
Sensor_PIN = 23
GPIO.setup(Sensor_PIN, GPIO.IN)
GPIO.setup(LED_PIN, GPIO.OUT)
  
print "Sensor-test [press ctrl+c to end the test]"
  
# This output function will be started at signal detection
def ausgabeFunktion(null):
        GPIO.output(LED_PIN, True)
  
# This output function will be started at signal detection 
GPIO.add_event_detect(Sensor_PIN, GPIO.FALLING, callback=ausgabeFunktion, bouncetime=10) 
  
# main program loop 
try:
        while True:
		time.sleep(1)
		# output will be reseted if the switch turn back to the default position.
		if GPIO.input(Sensor_PIN):
			GPIO.output(LED_PIN,False)
  
# Scavenging work after the program has ended
except KeyboardInterrupt:
        GPIO.cleanup()

Connections Raspberry Pi:

LED = GPIO24 [Pin 18]
Signal = GPIO23 [Pin 16]
+V = 3,3V [Pin 1]
GND = GND [Pin 6]

Example program download

KY-027-RPi-MagicLightCup.zip

To start with the command:

sudo python KY-027-RPi-MagicLightCup.py