• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Build Electronic Circuits

Build Electronic Circuits

Electronics explained in a simple way

  • Start Learning
    • Basic Electronics
    • Digital Electronics
    • Circuits
    • Practical Skills
      • Printed Circuit Boards
    • Microcontrollers
      • Arduino
    • Maker Lifestyle
      • Podcast
  • About Me
  • Blog
  • Products
  • Contact
You are here: Home / Mail Archive / How to use analog sensors on Arduino

How to use analog sensors on Arduino

February 1, 2016 By Øyvind Nydal Dahl 1 Comment

8x8x8_arduino_10These sensors are usually cheap.

And really easy to use!

An analog sensor is a sensor that gives you a voltage value that represents the measured value.

For example 2V could mean 25 degrees celsius from an analog temperature sensor.

You can find a lot of different sensors that are analog:
temperature light
sound rain
humidity +++

The Arduino has analog inputs that can be used to read these values.

Use the analogRead(pin)-method to read from an analog input pin.

STEP 1: CONNECT YOUR SENSOR

Some sensors come as modules with a pin you can connect directly to the analog input on the Arduino.

Others come as resistive sensors that you need to combine with a resistor to read out it’s value like this:

STEP 2: UPLOAD TEST CODE

Upload test code to test your sensor:

int analogPin = 0; // The analog pin your sensor is connected to
int val = 0; // variable to store the value read

void setup() {
Serial.begin(9600); // setup serial communication
}

void loop() {
val = analogRead(analogPin); // read the input pin
Serial.println(val); // Write value to serial console
}

STEP 3: READ VALUES

Use the “Serial Monitor” under the “Tools” menu to see the sensor readings.

The analog values will be in the range from 0 to 1023:
0 means 0 volts on the analog pin 1023 means 5 volts on the analog pin

STEP 4: CONVERT VALUES

To figure out the reading in a format you know, such as Celsius for temperature, check the datasheet of your sensor and make the necessary calculations in your code.

HOW TO GET STARTED WITH ARDUINO:

Arduino is a really fun board for creating powerful projects such as cell phones, remote controls or fire-breathing ponies.

I wrote a quick intro to Arduino that is available in the «Curious Beginner» and «Dedicated Learner» packages here:
https://www.build-electronic-circuits.com/products/ebook-2nd-edition

Keep on Soldering!
Oyvind

PS! Thank you for all your input on my new membership site. I’m really happy to see all the positive feedback! I still have a job to do going through them all, but I will. And I’ll take every suggestion into account.

Filed Under: Mail Archive

Reader Interactions

Comments


  1. Andrew says

    February 4, 2016

    Thanks for the clear explaination! I just got into PCBA and such things, since I started working at a company concerned with PCBA (I don’t have a position concerning the technology though). I started researching for a bit, and found out you can do such cool stuff with PCBs! This artice helped me grasp how Arduino circuits work, thank you! I’ll keep reading your blog :)

    Andrew

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Search:

Footer

Topics

  • Basic Electronics
  • Digital Electronics
  • Circuits
  • Practical Skills
  • Microcontrollers
  • Maker Lifestyle
  • Newsletter Archive

Social:

  • Facebook
  • Twitter
  • YouTube

Copyright © 2021 · Ohmify AS · Terms and Conditions · Privacy Policy