Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
DIY Microcontroller Projects for Hobbyists

You're reading from  DIY Microcontroller Projects for Hobbyists

Product type Book
Published in Jul 2021
Publisher Packt
ISBN-13 9781800564138
Pages 320 pages
Edition 1st Edition
Languages
Authors (2):
Miguel Angel Garcia-Ruiz Miguel Angel Garcia-Ruiz
Profile icon Miguel Angel Garcia-Ruiz
Pedro Cesar Santana Mancilla Pedro Cesar Santana Mancilla
Profile icon Pedro Cesar Santana Mancilla
View More author details
Toc

Table of Contents (16) Chapters close

Preface 1. Chapter 1: Introduction to Microcontrollers and Microcontroller Boards 2. Chapter 2: Software Setup and C Programming for Microcontroller Boards 3. Chapter 3: Turning an LED On or Off Using a Push Button 4. Chapter 4: Measuring the Amount of Light with a Photoresistor 5. Chapter 5: Humidity and Temperature Measurement 6. Chapter 6: Morse Code SOS Visual Alarm with a Bright LED 7. Chapter 7: Creating a Clap Switch 8. Chapter 8: Gas Sensor 9. Chapter 9: IoT Temperature-Logging System 10. Chapter 10: IoT Plant Pot Moisture Sensor 11. Chapter 11: IoT Solar Energy (Voltage) Measurement 12. Chapter 12: COVID-19 Digital Body Temperature Measurement (Thermometer) 13. Chapter 13: COVID-19 Social-Distancing Alert 14. Chapter 14: COVID-19 20-Second Hand Washing Timer 15. Other Books You May Enjoy

Reading data from a voltage sensor module

It is time to learn how to code a program that will read the information from the voltage sensor and display its reading on the serial monitor.

Let's write the program to receive the sensor data from the STM32 Blue Pill:

  1. Declare which pin of the STM32 Blue Pill card will be used as input of the sensor data:
    const int sensorPin = 0;

    The input pin will be the 0 (labeled A0 on the Blue Pill).

  2. Next, in the setup() part, start the serial data transmission and assign the speed of the transfer to 9600 bps, and indicate to the microcontroller the type of pin assigned to A0:
    void setup() {
      Serial.begin(9600);
      pinMode(sensorPin, INPUT);
    }
  3. Now, in loop(), first read the input pin's data sensor, send its value to the serial port, and wait for a second:
    void loop() {
      int sensorValue = analogRead(sensorPin);
      Serial.print("Voltage: ");
      Serial.println(sensorValue...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime