DIY Microcontroller Projects for Hobbyists: The ultimate project-based guide to building real-world embedded applications in C and C++ programming
A practical guide to building PIC and STM32 microcontroller board applications with C and C++ programming
- Discover how to apply microcontroller boards in real life to create interesting IoT projects
- Create innovative solutions to help improve the lives of people affected by the COVID-19 pandemic
- Design, build, program, and test microcontroller-based projects with the C and C++ programming language
We live in a world surrounded by electronic devices, and microcontrollers are the brains of these devices. Microcontroller programming is an essential skill in the era of the Internet of Things (IoT), and this book helps you to get up to speed with it by working through projects for designing and developing embedded apps with microcontroller boards.
DIY Microcontroller Projects for Hobbyists are filled with microcontroller programming C and C++ language constructs. You’ll discover how to use the Blue Pill (containing a type of STM32 microcontroller) and Curiosity Nano (containing a type of PIC microcontroller) boards for executing your projects as PIC is a beginner-level board and STM-32 is an ARM Cortex-based board. Later, you’ll explore the fundamentals of digital electronics and microcontroller board programming. The book uses examples such as measuring humidity and temperature in an environment to help you gain hands-on project experience. You’ll build on your knowledge as you create IoT projects by applying more complex sensors. Finally, you’ll find out how to plan for a microcontroller-based project and troubleshoot it.
By the end of this book, you’ll have developed a firm foundation in electronics and practical PIC and STM32 microcontroller programming and interfacing, adding valuable skills to your professional portfolio.
What you will learn
- Get to grips with the basics of digital and analog electronics
- Design, build, program, and test a microcontroller-based system
- Understand the importance and applications of STM32 and PIC microcontrollers
- Discover how to connect sensors to microcontroller boards
- Find out how to obtain sensor data via coding
- Use microcontroller boards in real life and practical projects
Who this book is for
This STM32 PIC microcontroller book is for students, hobbyists, and engineers who want to explore the world of embedded systems and microcontroller programming. Beginners, as well as more experienced users of digital electronics and microcontrollers, will also find this book useful. Basic knowledge of digital circuits and C and C++ programming will be helpful but not necessary.
Table of Contents
- Introduction to Microcontrollers and Microcontroller Boards.
- Software Setup and C Programming for Microcontroller Boards
- Turning an LED On or Off Using a Push Button
- Measuring the Amount of Light with a Photoresistor
- Humidity and Temperature Measurement
- Morse Code SOS Visual Alarm with a Bright LED
- Creating a Clap switch
- Gas sensor
- IoT Temperature-Logging System
- IoT Plant Pot Moisture Sensor
- IoT Solar Energy (Voltage) Measurement
- Covid-19 Digital Body Temperature Measurement (Thermometer)
- Covid-19 Social Distancing Alert
- COVID-19 20-Second Hand Washing Timer
DIY Microcontroller Projects for Hobbyists Contributors About the authors About the reviewers Preface Who this book is for What this book covers To get the most out of this book Download the example code files Code in Action Download the color images Conventions used Get in touch Share Your Thoughts Chapter 1: Introduction to Microcontrollers and Microcontroller Boards Technical requirements Introduction to microcontrollers Microcontroller boards An overview of analog and digital electronics necessary for carrying out the book's projects Basic electronic components The diode The solderless breadboard Description of the Blue Pill and Curiosity Nano microcontroller boards Installing the IDEs Your first project – a blinking LED Running the blinking LED example with the Blue Pill board Running the blinking LED example on the Curiosity Nano board Summary Further reading Chapter 2: Software Setup and C Programming for Microcontroller Boards Technical requirements Introducing the C programming language The basic structure of the C language Introducing Curiosity Nano microcontroller board programming Introducing Blue Pill microcontroller board programming Example – Programming and using the microcontroller board's internal LED Programming the Blue Pill's internal LED Summary Further reading Chapter 3: Turning an LED On or Off Using a Push Button Technical requirements Introducing push buttons Understanding electrical noise from push buttons Debouncing a push button via hardware Debouncing a push button via software Connecting an LED to a microcontroller board port and using an internal pull-up resistor Debouncing a push button via software connected to the Blue Pill Turning an LED on or off with a push button on the Curiosity Nano Testing out the push button Summary Further reading Chapter 4: Measuring the Amount of Light with a Photoresistor Technical requirements Understanding sensors Defining sensors What are sensor modules? Introducing photoresistors Connecting a photoresistor to a microcontroller board port Connecting a photoresistor to a Blue Pill board Coding the photoresistor values and setting up ports Connecting a photoresistor to a Curiosity Nano board Connecting a photoresistor sensor module to the microcontroller boards Testing out the photoresistor Summary Further reading Chapter 5: Humidity and Temperature Measurement Technical requirements Introducing the DHT11 humidity and temperature sensor module What is relative humidity? The DHT11 pins and their values Connecting a DHT11 sensor module to the microcontroller boards Connecting the DHT11 to the Blue Pill board Connecting an LCD to the Blue Pill Connecting an LM35 temperature sensor to the Curiosity Nano board Coding to get data from the sensor module Programming the DHT11 sensor for the Blue Pill board Coding the sensor module and the 1602 LCD Programming the LM35 sensor on the Curiosity Nano board Showing the humidity and temperature data results on the serial port monitor Plotting the data Summary Further reading Chapter 6: Morse Code SOS Visual Alarm with a Bright LED Technical requirements Understanding Morse code and the SOS message Introducing super-bright LEDs and calculating their necessary resistors Connecting the resistor and the super-bright LED to the microcontroller board Connecting the super-bright LED to the Curiosity Nano Coding the SOS Morse code signal The SOS message code for the Curiosity Nano Testing the visual alarm Summary Further reading Chapter 7: Creating a Clap Switch Technical requirements Connecting a microphone to a microcontroller board port Understanding the electret microphone module Connecting the components Coding your clap switch sketch Coding a clap switch with two clapping sounds Coding a clap switch with a timer between claps Improving the project performance Summary Further reading Chapter 8: Gas Sensor Technical requirements Introducing the MQ-2 gas sensor Connecting a gas sensor to the STM32 microcontroller board Interfacing for digital reading Interfacing for analog reading Writing a program to read the gas concentration over the sensor board Coding for digital reading Coding for analog reading Testing the system Summary Further reading Chapter 9: IoT Temperature-Logging System Technical requirements Connecting a temperature sensor to the Blue Pill board Introducing the DS18B20 temperature sensor module Connecting the components Coding a temperature reading system Learning to connect the ESP8266 module An introduction to the ESP8266 Wi-Fi module Connecting an ESP8266 Wi-Fi module Coding a program to send the sensed temperature to the internet Connecting the STM32 Blue Pill board to the internet Summary Further reading Chapter 10: IoT Plant Pot Moisture Sensor Technical requirements Connecting a soil moisture sensor to the Blue Pill board Introducing soil moisture sensors Connecting the components Reading data from the soil moisture sensor module Coding a program to send the sensed data to the internet Showing sensor data results over the internet Summary Further reading Chapter 11: IoT Solar Energy (Voltage) Measurement Technical requirements Connecting a solar panel to the Blue Pill board Introducing the solar panel The B25 voltage sensor Connecting the components Reading data from a voltage sensor module Coding a program to send the sensed data to the internet Showing sensor data results over the internet Summary Further reading Chapter 12: COVID-19 Digital Body Temperature Measurement (Thermometer) Technical requirements Programming the I2C interface The I2C protocol I2C coding Coding the Arduino Uno software (peripheral) Coding the Blue Pill software (controller) Connecting an IR temperature sensor to the microcontroller board The MLX90614 IR sensor The GY-906 sensor module Connection of the IR sensor to an Arduino Uno Connecting the Blue Pill to the Arduino Uno Showing the temperature on an LCD Testing the thermometer Summary Further reading Chapter 13: COVID-19 Social-Distancing Alert Technical requirements Programming a piezoelectric buzzer Connecting the components Connecting an ultrasonic sensor to the microcontroller board Connecting the components Writing a program for getting data from the ultrasonic sensor Testing the distance meter Summary Further reading Chapter 14: COVID-19 20-Second Hand Washing Timer Technical requirements Programming the counter (timer) Showing the timer on an LCD Connecting an ultrasonic sensor to the microcontroller board What is an ultrasonic sensor? How does an ultrasonic sensor work? Putting everything together – think of a protective case for the project! Testing the timer Summary Further reading Why subscribe? Other Books You May Enjoy Packt is searching for authors like you Share Your Thoughts
How to download source code?
1. Go to:
2. In the Find a repository… box, search the book title:
DIY Microcontroller Projects for Hobbyists: The ultimate project-based guide to building real-world embedded applications in C and C++ programming, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.