Apr 21, 2025
Learn to Read from Analog Inputs like Temperature Sensors with this fun Arduino Beginner project!!
If you want to follow along with this project exactly and need the same hardware kit, you can grab it here from Amazon!
https://amzn.to/3Tgfj6i
Check out the full Arduino Tutorials Playlist on the channel for more automation and electronics content!
https://www.youtube.com/playlist?list=PLsFyHm8kJsx0wNcgdb9mSZHqwQoC9HBlc
Consider becoming a super supporter of the channel and helping us grow into bigger and better projects!!!
https://www.patreon.com/LeMasterTech
The name may seem a bit silly, but there are classic old-time arcade games where you grip metal poles with your hands and it would light up a series of lights saying how 'romantic' you were, usually based on how warm your hands are. These games were called love-o-meters or love testers and today we will be using that as the basic premise for our Arduino project!
The circuit build is pretty straightforward, with just a few resistors, some jumper wires, a few multi-colored LED lights and a temperature sensor called a TMP 36. Then the code really just boils down to reading the data in, processing the raw signal into a useable format, and then controlling the state of our LEDs based on heat!
We also sneak a pretty good lesson in there on how to read the resistance of a resistor based on their bands!
Thanks for watching, don't forget to like the video and subscribe to the channel, and see you next time!
TIMESTAMPS:
00:00 Intro and Description
01:06 Quick Science-y Lesson - How to Read Resistor Values
02:23 Circuit Build - LED and Temperature Sensor Setup
04:13 Programming the Love-O-Meter, Setup
05:43 Arduino Commands to Read Analog Input Temperature
06:50 Scale Raw Value for Volts and Degrees
07:51 Control the LEDs based on Sensed Temperature
08:40 Testing and Outro
welcome back to the Master Tech and in
today's video we're going to learn how
to read from analog inputs with the
Arduino by recreating the classic and
only slightly cringy lovometer it's a
funny name but it represents a cool
beginner project using temperature
sensing to light up an increasing number
of LEDs based on heat
[Music]
so this project builds right off the
first two Arduino tutorials we just did
on the channel leave a link to the
playlist in the description of this
video and a card at the top of the
window right now the kit we're using in
these initial few projects is the
official Arduino starter kit I got it
from Amazon I'll put a link to it in the
description if you'd like to get the
same kit follow along exactly for this
project I'm assuming you have the
programming software installed and your
Arduino and breadboard ready to go this
will be our first project reading from a
varying range sensor called an analog
input so for this project in addition to
your Arduino and a breadboard you'll
need some jumper wires a TMP 36
temperature sensor four 220 ohm
resistors and some LEDs before we dive
into the physical circuit build we're
going to take a look at a quick sciency
lesson thing
lesson thing so one of the very most
common electrical components is a
resistor virtually every electrical
circuit that does anything useful or
interesting needs a lot of these but if
you know what resistor you need how do
you know that you have the right
resistor the numbers aren't exactly
printed on them well the system is based
on the total number of bands on the
resistor they have either four five or
six bands or strips of color on them
let's start with the four band rules the
first two bands are your tens place and
your ones place each band has a value of
zero to nine using an almost rainbow
scale that you may just want to memorize
and you can kind of think of it as the
rainbow plus neutrals the third band is
the multiplier which uses a very similar
number code and can be thought of 10 to
this power the fourth and final band on
these is tolerance which has a few
common ratings the rules for the Five
band resistors are exactly the same
except now you can have a three digit
number so you have a hundreds place tens
place in one's place and the multiplier
intolerance bands stay with the same
rule six band resistors have no
difference in bands one through five but
the sixth band is an additional
temperature coefficient which just tells
you how much change in resistance you
should expect when the temperature
changes there are other weird less
common scenarios out there but this hits
the most common ones quick sciency
lesson thing alright so this project is
called the love omitor and the Arduino
beginner project manual because there
was a corny old school line of arcade
games where you would hold metal poles
with your hands and a certain number of
Lights would light up to say how
romantic you were although most of the
time it was actually just measuring how
warm your hands are and this project
we'll be taking that basic concept and
remaking it with our Arduino although if
you have cold hands our project won't
condemn you to a life of loneliness
being a computer nerd has a good chance
of doing that on its own so in this
video we're going to take a look at the
physical build of the electrical
components first and then the code for
the project second let me know in the
comments if you like this order or think
code first is a better way of doing it
so let's start this circuit build by
choosing a digital pin for each LED in
my build I'll use two three four and
five normally skip zero and one because
these pins also correlate with reading
and writing through serial connections
so if you have the space elsewhere it's
better to use those hook the long leg
AKA anode of each led up to the digital
ping connection then put a 220 Ohm
resistor from the short leg or cathode
through to ground this is it for the
Loops that we'll need to control our
lights from our Arduino so now let's
check out the temperature sensor Loop a
quick online search for our tmp36
temperature sensor component will yield
the spec sheet for it also known as a
data sheet this will tell you a little
bit about how the component works as
well as its sensing range and how to
wire it up for the tmp36 to follow along
with my project have the flat side face
the Arduino and rounded side away from
it put voltage on the top pin ground on
the bottom pin and a signal wire jumper
from the middle pin back to channel a0
on the Arduino just understand the pins
are not interchangeable so you do need
to put positive voltage and ground on
the proper pins or your sensor won't
work then connect your power rail to the
5 volt and ground pins of the Arduino so
this is actually it for the physical
build we have a series of four LEDs here
that we will turn on in order as the
temperature sensor reads progressively
hotter now let's take a look at what our
Arduino program or sketch is going to
look like start by defining a couple
variables right at the top of your
program first an integer called sensor
pin will we will store which pin we have
the temperature sensor hooked up to in
this case a0 second create a float
called Baseline temp that you'll Define
to be approximately room temperature in
this case I'm using 18.5 Celsius or 65
Fahrenheit and you can play around with
this a bit later now in the setup Loop
which runs once at the beginning of your
program's initialization use the command
serial begin followed by 9600. this 9600
is known as the baud rate and is how
many bits of data are transferred
between the Arduino and PLC per second
this command is required if we want to
see what the temperature sensor is
reading while connected to our computer
next set up a for Loop to tell all our
LED pins in this case two through five
that they'll be outputs and initially
off a c plus for Loop requires an index
or variable defined with an initial
value in this case pin number equals two
then the condition for how many times to
iterate through the loop in this case as
long as the pin number is still less
than six and then what we want to do to
the index variable after each iteration
of the loop in this case add 1 to the
pin number value shown by the plus plus
command then inside this for Loop all we
have to do is set the pin mode of each
number to Output and then digital write
each pin number and off or low command
initially now let's take a look at what
to put in our Loop area of the program
which is the section that runs over and
over again while our Arduino is powered
start by reading the raw value from our
sensor pin into an integer variable
we'll call sensor valve using the
command analog read and then give it the
PIN to read from which we stored in the
variable sensor pit to display what this
raw value is on our computer use the
command serial dot print and start by
just giving it some text to tell us the
value that we're seeing in this case
it's the raw unscaled reading so we'll
just say sensor value then add a second
serial print command where we print the
actual value add a delay of just one
millisecond underneath the serial.print
to make sure the speed at which the
readings come in is manageable if you
were to upload this project right now it
wouldn't control your lights at all
other than turning them off but if you
open the serial monitor which is the
magnifying glass over some dots icon in
the top right window of your Arduino IDE
you should see a constant stream of the
text sensor value followed by the raw
reading somewhere around 130 to 150
depending on how warm your room is now
if you touch the temperature sensor or
breathe some hot air onto it you should
see the value go up this raw value is
not in terms of units of voltage or
degrees yet and to take a look at how to
turn this raw value into useful system
data let's jump back into our program
we'll calculate the voltage and
temperature the sensor is reading next
Arduino analog input channels read a
range of 0 to 5 volts over a raw signal
value of 0 to 1024 which correlates to a
10 bit integer therefore to get voltage
as a float variable divide our raw
signal by 1024 and multiply by 5. then
set up another two serial print commands
to show voltage right next to the raw
value lastly to get the actual
temperature which is what we really want
we want to check the TMP 36 data sheet
it tells us it has a minimum temperature
reading of negative 50 degrees Celsius
at 0 volts and that for every 10
millivolts or 0.01 volts of signal
increase that represents a real world 1
degree celsius increase of temperature
this means to convert from volts to
degrees Celsius subtract 0.5 from volts
and then multiply by a hundred throw in
two more serial prints so that we can
get the temperature readings right next
to voltage and raw and now let's take a
look at how to actually use this value
basically if we're chilling at around
Baseline temperature we'll say within
1.5 degrees of Baseline let's have all
our lights off we'll do this by writing
digital write commands low to all of our
LEDs now as temperature increases each
1.5 degrees Celsius span up from there
let's turn on One LED at a time so for
my program using a baseline of 18.5
we'll set up if else commands for each
scenario above 20 will give us just the
blue light above 21.5 will give us blue
and green rain above 23 will add yellow
in there and then above 24.5 we'll have
all our lights on including red this
gives us a pretty good sensing range but
you can play around with these spans as
much as you want change your Baseline
temperature and choose temperatures that
are fun for you now let's upload this
program and see what we get your board
will probably initially have no lights
on or maybe just the blue since that's
around the ambient room temperature and
if you keep an eye on your serial
monitor in your Arduino IDE you can see
the temperature and how it's
corresponding to the lights that are on
try putting a finger on the sensor and
you should see the temperatures start
creeping up and lights turning on every
time you hit that 1.5 degree increase
now if you have clammy hands or you're
just a cold fish and you can't get all
the way up with a finger try lowering
the Baseline temperature or breathing
some hot air onto the sensor feel free
to play around with this circuit and
find creative new ways to use the LEDs
to interact with our sense temperature
and that's going to be as far as we
build out this project today if you have
any questions about anything you saw
here today be sure to let me know about
them in the comments below and I will
get back to you as soon as I can if you
guys want to help me do bigger and more
complex projects in the future consider
becoming a Super supporter of my Channel
at my patreon link in the description of
this video as well hit that like button
subscribe button ring the notification
button click any other buttons you can
find and until next time good luck with
your projects and thanks for watching
[Music]