Reader small image

You're reading from  DIY Microcontroller Projects for Hobbyists

Product typeBook
Published inJul 2021
Reading LevelBeginner
PublisherPackt
ISBN-139781800564138
Edition1st Edition
Languages
Right arrow
Authors (2):
Miguel Angel Garcia-Ruiz
Miguel Angel Garcia-Ruiz
author image
Miguel Angel Garcia-Ruiz

Miguel Angel Garcia-Ruiz is an Associate Professor of Computer Science at the School of Computer Science and Technology, Algoma University, Canada. He has taught microcontroller programming and interfacing, human-computer interaction, and interaction design courses. Miguel has a PhD in Computer Science and Artificial Intelligence from Sussex University, England. He has published articles on tinkering with technology applying microcontroller boards. Miguel has conducted research projects funded by Canada's Northern Ontario Heritage Fund (NOHFC), Algoma University, and the Mexican Ministry of Education.
Read more about Miguel Angel Garcia-Ruiz

Pedro Cesar Santana Mancilla
Pedro Cesar Santana Mancilla
author image
Pedro Cesar Santana Mancilla

Pedro Cesar Santana Mancilla is a research professor at the School of Telematics at the University of Colima in Mexico. His research interests focus on human-computer interaction, ICT for elderly people, Internet of Things, and machine learning. He is currently serving as president of the Mexican Association on Human-Computer Interaction (AMexIHC). He is a Senior Member of the IEEE, and ACM and serves as Chair of the Mexican ACM SIGCHI Chapter (CHI-Mexico). Pedro is a member of the Mexican Academy of Computing (AMexComp) and the Mexican Society of Computer Science (SMCC).
Read more about Pedro Cesar Santana Mancilla

View More author details
Right arrow

Chapter 14: COVID-19 20-Second Hand Washing Timer

This chapter describes a useful project where you will make a touchless timer by waving at an ultrasonic sensor. This timer will count the minimum time of 20 seconds recommended by health authorities for properly washing our hands for preventing contamination from viruses such as SARS-CoV-2 that produces COVID-19 symptoms. The project involves an inexpensive ultrasonic sensor that detects when a user waves at the sensor by measuring the distance between the user and the circuit, triggering the counting. This application must be enclosed in a waterproof container to avoid soaking the circuit while the user washes their hands and damaging it. We explain at the end of the chapter how to do this.

In this chapter, we will cover the following main topics:

  • Programming the counter (timer)
  • Showing the timer on an LCD
  • Connecting an ultrasonic sensor to the microcontroller board
  • Putting everything together – think...

Technical requirements

The software tool that you will be using in this chapter is the Arduino IDE for editing and uploading your programs to the Blue Pill microcontroller board.

The code used in this chapter can be found in the book's GitHub repository:

https://github.com/PacktPublishing/DIY-Microcontroller-Projects-for-Hobbyists/tree/master/Chapter14

The Code in Action video for this chapter can be found here: https://bit.ly/3gQZdPf

In this chapter, we will use the following pieces of hardware:

  • One solderless breadboard.
  • One Blue Pill microcontroller board.
  • One micro-USB cable for connecting your microcontroller board to a computer and a power bank.
  • One USB power bank.
  • One ST-INK/V2 electronic interface, needed for uploading the compiled code to the Blue Pill. Bear in mind that the ST-LINK/V2 requires four female-to-female DuPont wires.
  • One HC-SR04 ultrasonic sensor.
  • One 1602 16x2 LCD.
  • One 2.2k ohm resistor, 1/4 watt. This is for...

Programming the counter (timer)

This section shows you how to code the 20-second timer. Programming a timer like this one is not trivial, since a user could activate the timer many times by waving at the ultrasonic sensor more than once while the counter is on. The program should not take into account those multiple activations if the 20-second counting is going on; otherwise, the counter will re-start multiple times and the counting will not be accurate. We also need to consider saving energy by turning off the LCD when not in use.

We should code our 20-second timer application by following these steps:

  1. Read values from the ultrasonic sensor.
  2. Check whether the user is waving at the sensor within 15 centimeters of the sensor. If this happens, do this:

    a) Turn on the LCD light.

    b) Show the Lather hands message and show the 20-second counting on the LCD.

    c) When the counter finishes, show this message on the LCD: Rinse your hands.

    d) Wait for 4 seconds and then turn off the...

Showing the timer on an LCD

In this section, we explain how to connect and use the 1602 LCD to show the timer on it. Figure 14.1 shows the Fritzing diagram similar to the one explained in Chapter 5, Humidity and Temperature Measurement:

Figure 14.1 – The LCD connected to the Blue Pill microcontroller board

Figure 14.1 – The LCD connected to the Blue Pill microcontroller board

The following are the steps for connecting the LCD to the Blue Pill, following the diagram from Figure 14.1:

  1. Connect the Blue Pill's GND (also labeled as G) pins to the solderless breadboard rails.
  2. Connect the Blue Pill's 5V pin (providing 5 volts) to the breadboard rails.
  3. Connect the USB cable to the Blue Pill and then to your computer or a USB power bank.
  4. Insert the LCD's 16 pins into the solderless breadboard.
  5. Connect the LCD's VSS pin to ground (the lower breadboard rail).
  6. Connect the LCD's VDD pin to 5 volts (the lower breadboard rail).
  7. Connect the 2.2k ohm resistor to the LCD&apos...

Connecting an ultrasonic sensor to the microcontroller board

This section explains how an ultrasonic sensor works, and it describes how to connect the HC-SR04 sensor to the Blue Pill microcontroller board, describing how to use its four-pin functions. The ultrasonic sensor will be used to check whether the user waves at it to initiate the 20-second counting.

What is an ultrasonic sensor?

Ultrasonic waves are sound waves that have a frequency that is higher than the frequencies that most human beings can hear, which is above 20,000 Hz. Ultrasonic sounds, or ultrasound, can have different applications, including something called echolocation, used by animals such as bats for identifying how far their prey is using reflected sounds. The same principle is applied in ultrasonic sensors.

An ultrasonic sensor is a dedicated electronic component that generally contains a number of electronic parts such as resistors, transistors, diodes, a crystal clock, a special microphone, and a...

Putting everything together – think of a protective case for the project!

This section shows how you can place the electronic circuit with the ultrasonic sensor inside a protective case. The section also shows some suggestions on how to fit everything in a plastic or glass container, because if you use the 20-second counter in a bathroom or in a place close to a hand washing sink, you will need to protect the circuit against water spilling and soap stains that can damage the electronic components used in this 20-second counter project. We do not recommend you connect the Blue Pill board to a wall USB adapter for security reasons. It is best to connect the Blue Pill to a USB power bank.

If you can't fit the whole 20-second counter circuit (including its solderless breadboard) in a plastic or glass container, try connecting the Blue Pill on a smaller solderless breadboard such as a half breadboard. Detach the ultrasonic sensor and the LCD from the breadboard and position...

Testing the timer

This section shows how to test out the 20-second timer.

Once you insert the electronic circuit with the sensor, the Blue Pill, and the LCD in a protective case, try it in a bathroom. Carefully place it close to a hand washing sink if you can, to facilitate activating it and seeing the counting while you wash your hands. See whether you can fix it to a wall or a surface so it won't move and that no one accidentally knocks it over while waving at it. Safety first!

You should connect the Blue Pill to a portable power bank that has a USB socket. This is to avoid connecting the Blue Pill to a wall USB adapter to make it safer to use in an environment such as a bathroom, as shown in Figure 14.11:

Figure 14.11 – A power bank connected to the Blue Pill microcontroller board

Figure 14.11 – A power bank connected to the Blue Pill microcontroller board

You can test out everything with a small power bank, such as the one shown in Figure 14.11.

Try activating the timer by waving at the sensor numerous...

Summary

In this chapter, we learned the basics of coding an easy-to-read 20-second counter. This count is recommended by many health authorities for properly washing our hands during that time in an attempt to destroy some viruses such as the one that causes COVID-19. The chapter also explained how the HC-SR04 ultrasonic sensor works for activating the counter. One major skill that you gained on completing the project from this chapter is that you learned how to connect a practical LCD to a microcontroller board, and how we could show the counting on an LCD. You can use the LCD in other projects that require showing numeric or text data from a microcontroller board.

We have covered in this chapter a practical way to obtain data from a sensor, process it on the microcontroller board, and do something about it such as showing results on an LCD. Obtaining data from sensors and processing it is one of the main applications of microcontrollers, leveraging their simplicity for connecting...

Further reading

Why subscribe?

  • Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
  • Improve your learning with Skill Plans built especially for you
  • Get a free eBook or video every month
  • Fully searchable for easy access to vital information
  • Copy and paste, print, and bookmark content

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
DIY Microcontroller Projects for Hobbyists
Published in: Jul 2021Publisher: PacktISBN-13: 9781800564138
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.
undefined
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 $15.99/month. Cancel anytime

Authors (2)

author image
Miguel Angel Garcia-Ruiz

Miguel Angel Garcia-Ruiz is an Associate Professor of Computer Science at the School of Computer Science and Technology, Algoma University, Canada. He has taught microcontroller programming and interfacing, human-computer interaction, and interaction design courses. Miguel has a PhD in Computer Science and Artificial Intelligence from Sussex University, England. He has published articles on tinkering with technology applying microcontroller boards. Miguel has conducted research projects funded by Canada's Northern Ontario Heritage Fund (NOHFC), Algoma University, and the Mexican Ministry of Education.
Read more about Miguel Angel Garcia-Ruiz

author image
Pedro Cesar Santana Mancilla

Pedro Cesar Santana Mancilla is a research professor at the School of Telematics at the University of Colima in Mexico. His research interests focus on human-computer interaction, ICT for elderly people, Internet of Things, and machine learning. He is currently serving as president of the Mexican Association on Human-Computer Interaction (AMexIHC). He is a Senior Member of the IEEE, and ACM and serves as Chair of the Mexican ACM SIGCHI Chapter (CHI-Mexico). Pedro is a member of the Mexican Academy of Computing (AMexComp) and the Mexican Society of Computer Science (SMCC).
Read more about Pedro Cesar Santana Mancilla