Вернуться на страницу библиотеки модулей

int led_pin = 13; // Define the LED interface
int switch_pin = 3; // Definition of mercury tilt switch sensor interface
int val; // Defines a numeric variable

void setup()
{
	pinMode(led_pin, OUTPUT);
	pinMode(switch_pin, INPUT);
}

void loop()
{
	val = digitalRead(switch_pin); // check mercury switch state
	if(val == HIGH)
	{
		digitalWrite(led_pin, HIGH);
	}
	else
	{
		digitalWrite(led_pin, LOW);
	}
}

Рекомендуемые ссылки:
Arduino Mercury Tilt Switch Module KY-017 – Wiring & Code
KY-017 Tilt switch – SensorKit
Using the Mercury Open Optical Module KY-017 with Arduino – Phipps Electronics
Arduino and Keyes KY-017 Mercury Tilt Sensor
Arduino – Switching Light On/off With Mercury Switch Module KY-017 – Instructables
2C16 Mercury tilt switch module for Arduino KY-017 – Blue PCB Electronics

Вернуться на страницу библиотеки модулей