KY-002: Skillnad mellan sidversioner

Från Stockholm Makerspace Wiki
Rad 15: Rad 15:
<pre>
<pre>
int LED = 13 ;// define LED pin
int LED = 13 ;// define LED pin
int SHOCK = 2; // vibration sensor pin
int SENSOR = 2; // sensor pin
int val ; // define numeric variable val
int val ; // define numeric variable val
void setup ()
void setup ()
{
{
   pinMode (LED, OUTPUT) ; // define LED as output  
   pinMode (LED, OUTPUT) ; // define LED as output  
   pinMode (SHOCK, INPUT) ; // define SHOCK as input
   pinMode (SENSOR, INPUT) ; // define SENSOR as input
}
}
void loop ()
void loop ()
{
{
   val = digitalRead (SHOCK) ;// read SHOCK and put it into val
   val = digitalRead (SENSOR) ;// read SENSOR and put it into val
   if (val == HIGH) // When the shock sensor detects a signal, LED flashes
   if (val == HIGH) // When the sensor detects a signal, LED flashes
   {
   {
     digitalWrite (LED, LOW);
     digitalWrite (LED, LOW);

Versionen från 9 oktober 2013 kl. 15.09

Bild

Om sensorn

Shock är en stötsensor som skickar ut HIGH på signalstiftet när den får en stöt/vibration

Synonymer

KEYES Shock Module, KY002, Hit sensor module, 02 ARDUINO vibration switch module

Koppling

Arduino exempelkod

int LED = 13 ;// define LED pin
int SENSOR = 2; // sensor pin
int val ; // define numeric variable val
void setup ()
{
  pinMode (LED, OUTPUT) ; // define LED as output 
  pinMode (SENSOR, INPUT) ; // define SENSOR as input
}
void loop ()
{
  val = digitalRead (SENSOR) ;// read SENSOR and put it into val
  if (val == HIGH) // When the sensor detects a signal, LED flashes
  {
    digitalWrite (LED, LOW);
  }
  else
  {
    digitalWrite (LED, HIGH);
  }
 }

Bibliotek