8-Bit MCU Marries Ultra Low Power and Rich Analog I/O

STMicroelectronics has announced STM8L050, a low power 8-bit MCU that embeds rich analog peripherals, a DMA controller and separated data EEPROM—all in an inexpensive SO-8 package with up to six user I/Os. Built around ST’s STM8 core running at up to 16 MHz, the STM8L050 is well suited for resource-constrained products like industrial sensors, toys, access cards, e-bike controllers, home-automation or lighting products, smart printer cartridges or battery chargers.

The integrated DMA (Direct Memory Access) controller speeds application performance by streamlining data transfers between peripherals and memory, or from memory to memory, ultimately saving power consumption. The 256 bytes of separated EEPROM allows applications to store important program data when the MCU is powered down, while allowing maximum utilization of flash for code storage.

Alongside two comparators, the STM8L050 has a 4-channel 12-bit analog-digital converter (ADC) and a low-power real-time clock (RTC) with programmable alarm and periodic wakeups, allowing designers to minimize external analog components. In addition, support for either an external or internal clock at up to 16 MHz further enhances flexibility to balance performance with bill-of-materials (BOM) savings.

Other features include 8 KB of on-chip flash memory, 1 KB of RAM, two 16-bit timers, one 8-bit timer, and popular connectivity and debug interfaces including SPI, I2C, UART and SWIM. The STM8L050 provides power-saving modes that cut current to as little as 350 nA, and operates over a wide voltage range from 3.6 V down to 1.8 V. The MCUs are fully specified from -40°C to 125°C, ensuring robustness and reliability in demanding applications such as industrial controls or lighting products.

The STM8L050J3 is in production now, and available in the SO-8 package, priced from $0.25 for orders of 10,000 pieces.

STMicroelectronics | www.st.com

IoT Door Security System Uses Wi-Fi

Control Via App or Web

Discover how these Cornell students built an Internet-connected door security system with wireless monitoring and control through web and mobile applications. The article discusses the interfacing of a Microchip PIC32 MCU with the Internet, and the application of IoT to a door security system.

By Norman Chen, Ram Vellanki and Giacomo Di Liberto

The idea for an Internet of Things (IoT) door security system came from our desire to grant people remote access to and control over their security system. Connecting the system with the Internet not only improves safety by enabling users to monitor a given entryway remotely, but also allows the system to transmit information about the traffic of the door to the Internet. With these motivations, we designed our system using a Microchip Technology PIC32 microcontroller (MCU) and an Espressif ESP8266 Wi-Fi module to interface a door sensor with the Internet, which gives the user full control over the system via mobile and web applications.

The entire system works in the following way. To start, the PIC32 tells the Wi-Fi module to establish a connection to a TCP socket, which provides fast and reliable communication with the security system’s web server. Once a connection has been established, the PIC32 enters a loop to analyze the distance sensor reading to detect motion in the door. Upon any detection of motion, the PIC32 commands the Wi-Fi module to signal the event to the web server. Each motion detection is saved in memory, and simultaneously the data are sent to the website, which graphs the number of motion detections per unit time. If the security system was armed at the time of motion detection, then the PIC32 will sound the alarm via a piezoelectric speaker from CUI. The alarm system is disarmed at default, so each motion detection is logged in the web application but no sound is played. From both the web and mobile application, the user can arm, disarm and sound the alarm immediately in the case of an emergency.


The PIC32 acts as the hub of the whole system. As shown in Figure 1, each piece of hardware is connected to the MCU, as it detects motion by analyzing distance sensor readings, generates sound for the piezoelectric speaker and commands the Wi-Fi module for actions that pertain to the web server. The distance sensor used in our system is rated to accurately measure distances of only 10 to 80 cm [1]. That’s because motion detection requires us only to measure large changes in distances instead of exact distances, the sensor was sufficient for our needs.

Figure 1
The schematic of the security system. Note that the door sensor runs on 5  V, whereas the rest of the components run on 3.3 V

In our design, the sensor is facing down from the top of the doorway, so the nearest object to the sensor is the floor at idle times, when there is no movement through the door. For an average height of a door, about 200 cm, the sensor outputs a miniscule amount of voltage of less than 0.5 V. If a human of average height, about 160 cm, passes through the doorway, then according to the datasheet [1], the distance sensor will output a sudden spike of about 1.5 V. The code on the PIC32 constantly analyzes the distance sensor readings for such spikes, and interprets an increase and subsequent decrease in voltage as motion through the door. The alarm sound is generated by having the PIC32 repeatedly output a 1,500 Hz wave to the piezoelectric speaker through a DAC. We used the DMA feature on the PIC32 for playing the alarm sound, to allow the MCU to signal the alarm without using an interrupt-service-routine. The alarm sound output therefore, did not interfere with motion detection and receiving commands from the web server.

The Wi-Fi module we used to connect the PIC32 to the Internet is the ESP8266, which has several variations on the market. We chose model number ESP8266-01 for its low cost and small form factor. This model was not breadboard-compatible, but we designed a mount for the device so that it could be plugged into the breadboard without the need for header wires. Figure 2 shows how the device is attached to the breadboard, along with how the rest of the system is connected.

Figure 2
The full system is wired up on a breadboard. The door sensor is at the bottom of the photo, and is attached facing down from the top of a doorway when in use. The device at the top of the figure is the PIC32 MCU mounted on a development board.

The module can boot into two different modes, programming or normal, by configuring the GPIO pins during startup. To boot into programming mode, GPIO0 must be pulled to low, while GPIO2 must be pulled high. To boot into normal mode, both GPIO0 and GPIO2 must be pulled high. Programming mode is used for flashing new firmware onto the device, whereas normal mode enables AT commands over UART on the ESP8266. Because we only needed to enable the AT commands on the module, we kept GPIO0 and GPIO2 floating, which safely and consistently booted the module into normal mode.


Before interfacing the PIC32 with the Wi-Fi module, we used a USB-to-TTL serial cable to connect the module to a computer, and tested the functionality of its AT commands by sending it commands from a serial terminal. …

Read the full article in the December 341 issue of Circuit Cellar

Don’t miss out on upcoming issues of Circuit Cellar. Subscribe today!

Note: We’ve made the October 2017 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.