JeremyBlum.com

v3.1

Tutorial 4 for Arduino: Analog Inputs

| 95 Comments

This tutorial was featured on the official Arduino blog on 3/9/2011

This week is all about analog inputs for the arduino. I’ll show you how you can use a voltage divider circuit (see episode 3) and a variable resistor to make an analog sensor. We’ll also use a Sharp IR distance sensor as an analog input to detect distance and movement (with some clever programming). By the end of this episode, you will be able to create your own emergency lighting system! Without further adieu, check out this week’s tutorial on analog inputs for the arduino…

One more thing: You only have 1 more week to submit your arduino projects and win a soldering station – get going!


You can download the files associated with this episode here:

GNU GPL License Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.


95 Comments

  1. Pingback: Tutorial 11 for Arduino: SD Cards and Datalogging | JeremyBlum.com

  2. hello …. I like to do new project in arduino to control the home and must using new technology and new ideas …….. so if you have the new ideas and can help me to do it …. please contact to me at engawm2020@yahoo.com thanks

  3. I need your help;; in my project simply i have to read analod values ,amplify it and have to display on the lcd but my serial monitor and lcd are showing different values..please help.

  4. I don’t know why but mine does the opposite when I put my hand over it it turns off, and I copyed and pasted your code. I also used different pins to see if my board was defective.

    • Eko, I’m new at this stuff but excited to tinker and learn, I had the same problem, here’s what I did, under the “if” and “else” lines reverse the high and low and it will work.

  5. Hi Jeremy,

    I followed your video several times, why does my project work backwards, when there is light the led lights up and when it is dark it turns off. I’ve reversed the lines in the “If” and “else” statements from high to low to get it to work however, when I implemented the dimmer program, it goes back to being backwards. what am I doing wrong? or what can I do to get this right….

  6. Hi,
    Ur tutorial videos are awesome for beginners. I would like to get some code for arduino to transmit wireless messages to a remote user. Can u just help me?

  7. hii,
    how to connect a negative voltage to arduino board, like a ph sensor which starts with -414 mv to 414 mv

  8. I appreciated your video. I am trying to get my Arduino to turn on WS 2801 LED pixels whenever a person walks past an IR detector at the top or bottom of the stairs. I have the code from Adafruit to run the LED’s, and I can run a sketch to read the values of an IR detector. Most example codes I have found show that if a condition is true then the Arduino turns on or off a digital output. What I need is for my Arduino to run the LED code or loop back to monitoring the IR sensors, depending upon what the IR sensors read. How do I code the sketch to continue the program or keep reading the sensors?

    • use a state variable to track the state of the IR sensor. If changes by a certain threshold between two passes, then execute a separate function to controls the LEDs. once that function is done running, the code will continue in the loop() and start checking the IR sensor again.

  9. Hey Jeremy, just wondering if there’s an alternative to the photoresistor that you are recommending? It’s currently out of stock.
    Thanks!

  10. Hey Jeremy, is it compulsory to use 150 ohm resistor?
    Actually am not getting it in the market .
    So, please suggest which alternate resistor can be used.

  11. And what are those values that we see on the serial monitor when we darken or brighten above photo resistor?
    are they the values of analog o/p voltage?

  12. how to connect cfl lamp instead of that led

  13. Hi everyone!
    I’m trying to connect temperature sensor TMP36 to my Arduino Uno. I’ve found that output range of the sensor: from 0.1V (-40°C) to 2.0V (150°C). I also found sample sketch that get value from analog input and convert it to voltage using following code:
    return (analogRead(pin) * .004882814);

    But this line of code assumes that sensors’s output range is up to 5V (5/1024 = 0.004882814). Is it correct? How should I get correct voltage value from sensor output? Thanks for answer!

  14. Hello,

    I just created the nightlight but am having two problems: First, my photo resistor values are less than 100 and are between 0 and 100.

    Second, I have noticed that my led stays on even though I entered the correct code.

    Can you please help?

    Thanks,

Leave a Reply

Required fields are marked *.