Experiment 4 Using OLED to Display the State of Tilt Switch

Share for us

Description: In this routine, we will let OLED display the state of tilt switch. When the tilt switch remains level, the bulb displayed on the OLED will remain off; when the tilt switch tilts, the bulb will light up.

Components:

SunFounder Uno R3 * 1

0.96 Inch OLED * 1

Tilt Switch* 1

USB Cable * 1

Jumper Wires

Steps:

First, connect the circuit

    SunFounder Uno                        OLED

    SCL -------------------------------------- SCL

    SDA ------------------------------------- SDA

    3.3V ------------------------------------- VCC

    GND ------------------------------------ GND

One end of the tilt switch is connected to GND on SunFounder Uno, and the other end is connected to digital port 5 on SunFounder Uno, as shown in figure 23:

Figure 23

Second, program (please go to our official website www.sunfounder.com to download the example code by clicking LEARN -> Get Tutorials)

Third, compile the program

Fourth, burn the program into SunFounder Uno R3 board

After all the above steps, when you lay the tilt switch horizontally, the bulb displayed on the OLED will remain off; when you tilt the tilt switch, the bulb will light up.