Mercury Switch

Mercury switch is a Switch that looks like an LED bulb, but instead of a diode, it just has two poles and mercury inside the switch. Because mercury is liquid under ambient temperature, it will roll around inside and trigger the switch as the two poles have different heights(Fig. 1). This type of switch is most useful for tilt sensing devices. More information can be found here.

Fig1

Fig. 1

Fig2

Fig. 2 Shows the mercury switch in disconnected mode.

Fig3

Fig. 3 Shows the mercury switch in connected mode.

Click here for information on where to buy it.



HAZARDOUS!

Be extra cautious with such devices as mercury is EXTREMELY TOXIC.


Hello World Example

The following example shows a mercury switch in action. Once the user tilts the switch, the Led1 on the mbed will go on.

Fig4

mercury_switch_Hello_World

#include "mbed.h"

DigitalOut led(LED1);
DigitalIn  mercury(p5);
int main() {
    
    while(1) {
        if(mercury == 1)
            led = 0;
        else
            led = 1;
    }
}

mercury_switch_hello_world_lpc1768.bin - has the compiled code. Save it on the mbed flash drive and hit reset.




Demo 2

This demo utilizes two mercury switches bent in the opposite directions. The code counts the number of tilting occurred in each direction to control the speed and direction of the motor. LED1 (fast) and LED2 (slow) on the mbed indicate that the motor is running in forward mode, and LED3 (slow) and LED4 (fast) indicate the motor is running in reverse mode. All LEDs are off when the motor is not running. It requires a H-bridge motor driver(TB6612FNG), a DC motor and an external power supply that can support the motor.

mbedTB6612FNG5V external powerswitchDC motor
p5pull-up side
p6pull-up side
p11AIN2
p12AIN1
p21PWMA
VOUTVCC, STBY
GNDGNDGND
VM5V
A01+
A02-



main.cpp

#include "mbed.h"
#include "Motor.h"

//DigitalOut led(LED1);
DigitalIn sw1(p5);
DigitalIn sw2(p6); 
BusOut led(LED1,LED2,LED3,LED4);
Motor m(p21, p11, p12); // pwm, fwd, rev

int main() {
    led = 0;
    m.speed(0);
    int count = 3;
    float speed = 0;
    while(1) {
    
        if(sw1 == 0 && count < 5)    
        {   
            count ++;
            speed +=0.5;
            m.speed(speed);
            if(count == 3)
                led =0;
            else if (count == 1)
                led = 0x1;
            else if (count == 2)
                led = 0x2;
            else if (count == 4)
                led = 0x4;
            else if (count == 5)
                led = 0x8;
            wait(1);
            
        }
        
        else if(sw2 == 0 && count>0  )
        {
            count --;
            speed -=0.5;
            m.speed(speed);
            if(count == 3)
                led =0;
            else if (count == 1)
                led = 0x1;
            else if (count == 2)
                led = 0x2;
            else if (count == 4)
                led = 0x4;
            else if (count == 5)
                led = 0x8;
            
            wait(1);
        }    
    }
}


mercuryswitchmotorcontrol_lpc1768.bin - has the compiled code. Save it on the mbed flash drive and hit reset.



Author : Hank Sun(Pangkai Sun), Soobum Kim


Please log in to post comments.