Phipps Electronics

Order within the next 

FREE SHIPPING OVER $199

50,000+ ORDERS

WORLDWIDE SHIPPING

SSL SECURED

Using the Mercury Open Optical Module KY-017 with Arduino

Contents

Introduction

In this tutorial, we will learn about the KY-017 module, what is a mercury switch and we will build a simple project to detect if the KY-017 module is tilted using an Arduino.

Mercury Open Optical Module KY-017

The KY-017 Module will be our main component for this tutorial. This module has a mercury switch and mounted on a breakout board with an LED and resistor. Figure 1 shows the module as seen in fritzing.

Figure 1: KY-017 Mercury Open Optical Module

Pinout

The KY-017 module has three pins.

Component PinDescription
(-)GND
middle+5V
SSignal

What is a Mercury Switch?

A mercury switch has a mercury blob as a means to close its internal contacts. If the switch is level, the mercury bridges the 2 contact points. But if the switch is tilted, the mercury moves on one side and the contact points are open.

Project - Arduino Tilt Indicator

After learning about the KY-017 module and the mercury switch, it is now time to build a project using the module. Our project will be a visual indicator when the KY-017 module is tilted.

Components

For this project, we need the following components:

  • Arduino Uno board (1 pc.)
  • KY-017 Mercury Open Optical Module (1 pc.)
  • Jumper wires

Wiring Diagram

Figure 2: Connection Diagram

Figure 2 shows the connection between the Arduino Uno and the KY-017 Mercury Open Optical Module.

The KY-017 module pins are connected to the Arduino Uno board as follows:

Component PinArduino Uno board Pin
(-)GND
middle+5V
S8

The Code

Below is the Arduino sketch for our project. I have added comments to explain important parts of the code. Save the code as KY-017.ino and upload it to your Arduino board.

				
					// Arduino and KY-017 module
void setup() {
  pinMode(8, INPUT);  // module is connected to pin 8
  pinMode(13, OUTPUT);  // built-in LED
}
void loop() {
  if (digitalRead(8) == HIGH) { // if module is tilted, pin 8's state is HIGH
    digitalWrite(13, HIGH);     // switch On LED
  }
  else {
    digitalWrite(13, LOW);     // switch On LED
  }
}
				
			

Project Test

Apply power to your Arduino Uno board. The Arduino’s built-in LED will light up when KY-017 is tilted.

SUBSCRIBE FOR NEW POST ALERTS

Subscribe to be the first to know when we publish a new article!
List Subscriptions(Required)

POPULAR POSTS

Scroll to Top