Это видео недоступно.
Сожалеем об этом.

Tutorial 09: How to read voltages with analogRead(): Arduino Course for Absolute Beginners (ReM)

Поделиться
HTML-код
  • Опубликовано: 18 авг 2024
  • 🤩 FREE Arduino Crash Course 👇👇
    bit.ly/get_Ard...
    **If you like this, I think you'll like the premium Arduino training we offer. Check it out here** bit.ly/3nSBPUs
    We designed this circuit board for beginners!
    Kit-On-A-Shield: amzn.to/3lfWClU
    SHOP OUR FAVORITE STUFF! (affiliate links)
    ---------------------------------------------------
    We use Rev Captions for our subtitles
    bit.ly/39trLeB
    Arduino UNO R3:
    Amazon: amzn.to/37eP4ra
    Newegg: bit.ly/3fahas8
    Budget Arduino Kits:
    Amazon:amzn.to/3C0VqsH
    Newegg:bit.ly/3j4tISX
    Multimeter Options:
    Amazon: amzn.to/3rRo3E0
    Newegg: bit.ly/3rJoekA
    Helping Hands:
    Amazon: amzn.to/3C8IYXZ
    Newegg: bit.ly/3fb03X1
    Soldering Stations:
    Amazon: amzn.to/2VawmP4
    Newegg: bit.ly/3BZ6oio
    AFFILIATES & REFERRALS
    ---------------------------------------------------
    ►Audible Plus Free trial: amzn.to/3j5IGrV
    ►Join Honey- Save Money bit.ly/3xmj7rH
    ►Download Glasswire for Free:bit.ly/3iv1fql
    FOLLOW US ELSEWHERE
    ---------------------------------------------------
    Facebook: / programmingelectronics...
    Twitter: / progelecacademy
    Website: www.programmin...
    Click Below to Read About This Topic on Our Website
    www.programmin...
    Description:
    Arduino Course for Absolute Beginners
    In the last lesson you learned about using the analogRead() function to collect data from a sensor connected to one of the Arduino' analog pins. The range of data we received from the analogRead() function, was mapped from 0 to 1023. What if we wanted to know the actual voltage being applied at the pin?
    You Will Need
    Potentiometer (any resistance range will work)
    Jumper Wires - at least 3
    solder-less breadboard
    Persian Rug
    Step-by-Step Instructions
    Place your potentiometer into your breadboard.
    Run a jumper wire from the 5-Volt pin of the Arduino either one of the outside pins of your potentiometer.
    Run another jumper wire from one of the ground pins on your Arduino (labeled GND) to the other outside pin of your potentiometer.
    Run the final jumper wire from pin A0 on your Arduino to the middle pin of the potentiometer.
    Plug your Arduino into your computer.
    Open up the Arduino IDE.
    Go to File, Examples, 01.Basics, ReadAnalogVoltage
    Click the Verify button on the top left side of the screen. It will turn orange and then back to blue once it has finished.
    Click the Upload button (next to the Verify button). It will turn orange and then back to blue once it has finished.
    On the menu bar, go to Tools, Serial Monitor - this will open the Serial Monitor window - you should see numbers rolling down this screen.
    Now adjust the knob of your potentiometer and watch the serial monitor window, the numbers should adjust between 0 and 5.
    This sketch does the exact same thing the last lesson covered except for one important change. It takes the reading provided by the analogRead() function and converts it into the actual voltage value at the respective analog pin. Let's start from the top just to review what is taking place...
    We have no variable to declare and initialize at the beginning of the sketch so we jump right into the setup() function. Inside the curly braces of setup() we begin serial communications by setting the baud rate. This is done using the function Serial.begin(9600).
    That is all there is to the setup of this sketch. the next block of code is loop(). Inside the curly braces of loop() the first thing we do is read the value at analog pin A0 and assign it to an integer variable called sensorValue.
    int sensorValue = analogRead(A0);
    Once we have recorded this value, we now want to convert it to an actual voltage. You will recall that the range returned by the analogRead() function is between 0 and 1023. We want this to reflect the actual voltage at the pin - which is between 0 and 5 volts depending on where we have our potentiometer turned to. So lets take a look at how we might accomplish this...
    float voltage = sensorValue * (5.0 / 1023.0);
    The first thing we encounter is a new data type - called float. A float is just a number with a decimal point; say for example 3.14 or 2.17781778. Floats, also called floating point numbers, can be huge in value, and take much more time for the Arduino to churn through than integers - this is why they are avoided unless necessary.
    We want a float in this case because it will give us more resolution than an integer.
    So what is that calculation anyway - it looks kind of confusing. The numbers on the right are just a conversion factor. We want to convert one scale to another.

Комментарии • 212

  • @programmingelectronics
    @programmingelectronics  3 года назад +2

    ****If you like this, I think you'll like the premium Arduino training we offer. You can check it out here**** bit.ly/3lHyzcB

    • @robwilton9539
      @robwilton9539 2 года назад +1

      Surely there are 1024 values in 0-1023 ?

  • @mron-2617
    @mron-2617 4 года назад +22

    These were made in 2013 and are still useful. Thank you so much. You really helped me learn Arduino.

  • @joshualewis3932
    @joshualewis3932 8 лет назад +20

    These tutorials are absolutely amazing, great job!

  • @sflow15
    @sflow15 9 лет назад +3

    Great video tutorials. Thank you for taking the time and for making this public and free! Re: Tutorial #9: I think it would help some less experienced folks such as myself if you explain why the float number changes with voltage. Like most, I experimented and found you don't need to change the code to get the 3.3v readings (well... more like 3.27), but I got stuck on the "why" this is the case until I read your response to a comment about 9 months ago explaining the float number is around 675 instead of 1023 with 3.3 volts.

  • @jonhughes7264
    @jonhughes7264 9 лет назад +6

    Thank you for a brilliant series of tutorials. You are a great teacher. I can't praise this series enough.
    The tutorials are really clear and easy to understand for a complete novice like myself. I feel like I have learnt something and will now be able to go on to develop my skills.
    Cheers! :)

  • @ginajung2023
    @ginajung2023 5 лет назад +1

    I wish I had found your tutorial earlier. But still I'm very glad that I found them. Thank you a million.

  • @dikshitadesai
    @dikshitadesai 8 лет назад +4

    amazing....thank you so much....you make things so simple to understand.....i watched all your videos from this playlist and i loved all of them....will always be thankful as you are the reason behind my basics of arduino ... thanks a ton!!!

  • @lake2788
    @lake2788 8 лет назад

    Entire series well done...You're not just an instructor; but a teacher. Thanx...

  • @steve-si3oz
    @steve-si3oz 4 года назад +1

    Thank you! This is great. I'd been placing the Pot's middle wire on a digital
    pin instead of an analog (A0) and getting weird results. Figured it out right
    away after watching this tutorial.

  • @programmingelectronics
    @programmingelectronics  10 лет назад +3

    Hi +Vishnu Das - According to the Arduino Reference for Serial.print -> "Floats are printed as ASCII digits, *defaulting to two decimal places*.
    I didn't realize this until you asked and I checked! Thanks for that. Also, if you use the command:
    Serial.println(1.23456, 4); it should display "1.2346" on the serial monitor. The second number passed is specifying how many digits to display.
    Here is a link to the Serial.print reference arduino.cc/en/Serial/Print
    Great comment - thanks for your thoughts!

    • @pronoy91
      @pronoy91 8 лет назад

      Hi. can serial print or software SPI (for OLED with U8glib) intefere with Analog reading. I have this Pro Mini which is essentially Atmel Mega328P, whose analogRead() for all A0 to A7 produces 1023 output (digital i/o is still functional on these pins). I've tried setting pinMode(A*,INPUT) and then digitalWrite(A*,LOW) just incase the pullups were activated. I'm thoroughly confused

  • @101pokemasters
    @101pokemasters 10 лет назад +1

    I love these videos, very understandable, and so far, its making arduino very exciting and easy. Thanks for these videos!

  • @CraigMansfield
    @CraigMansfield 5 лет назад +2

    I like your style of teaching 👍👏

  • @ammarkiani6018
    @ammarkiani6018 4 года назад

    1.yes we have to change 5 volt to 3.3 volt to get the accurate value.
    2: we have to change the value of volt in conversion formula.

  • @behnamrasooli8801
    @behnamrasooli8801 8 лет назад

    Just a quick tip here: (5.0 / 1023.0) always stays the same, so you don't need to do this computation over and over again in loop() method. You can simply do it once in the setup() method and store the result in a variable and then use it in the loop().

  • @umairshift
    @umairshift 6 лет назад +1

    awesome teaching and learning .. loved it so much

  • @hatani
    @hatani 10 лет назад +3

    I might be very likely off here, but isn't it supposed to be divided by 1024? 0 being first step and 1023 being 1024th step? It won't affect the result by significant bit though :)

  • @tojotaco3822
    @tojotaco3822 4 года назад +3

    Awesome! Who needs to buy a voltage reader when you can build one!

  • @ricardrinaldo4791
    @ricardrinaldo4791 3 года назад +1

    Outstanding videos, thank you so much.

  • @lordof7seas
    @lordof7seas 10 лет назад +15

    when i was coding C and C++, the float had 6 decimal points,
    And you specified that in the videos as well.
    But why does the serial monitor shows only 2 decimal points

    • @robv.7644
      @robv.7644 4 года назад

      @akashic seer the trick to print more decimals: Serial.print(voltage, 2)
      You van change number behind to the decimals you want

    • @robv.7644
      @robv.7644 4 года назад +1

      Pretty old comment btw

    • @kodexe3298
      @kodexe3298 4 года назад

      @@robv.7644 So by 2 we will get a float value upto 2 decimal digits??

    • @robv.7644
      @robv.7644 4 года назад

      @@kodexe3298 yes

  • @thurlravenscroft2572
    @thurlravenscroft2572 Год назад +1

    I am a big fan of your work! Say, how would you read a voltage from a sensor on one pin, then output a different, but corresponding voltage to a different pin?

    • @programmingelectronics
      @programmingelectronics  Год назад

      Thanks Thurl and great question! You could use a voltage divider circuit where you the read the incoming voltage with an analog pin (do a simple conversion in your code), and then use PMW on a digital pin to output.
      If you look at the Arduino IDE > Examples > Basics > ReadAnalogVoltage
      And also check out the PWM examples -that should help - best of luck!

  • @4blue6
    @4blue6 8 лет назад +1

    Amazing video bro, helped me a lot. Keep up the awesome vids.

  • @IoTLearner
    @IoTLearner 6 лет назад

    For range output in between 0-100 volts...You have to adjust the formula as:
    float voltage= sensorValue*(100.0/1023.0);
    For Aurduino 3.3V pin....The formula changes as:
    float voltage= sensorValue*(3.3/1023.0);

    • @christiansalway7140
      @christiansalway7140 5 лет назад

      The pin input will not take more than 5V so DON'T try to connect 100 Volts in to it! Use a voltage divider to bring the 100V down to 5V!

  • @EladLending
    @EladLending 4 года назад

    Correct me if I'm wrong, please, but I think that the code should read: float voltage = sensorValue * (5/1024.0) ! There are in fact 1024 units, since 2^10=1024. It does not matter that the count begins at zero and not at one! (0-1023)>>1024 units. (1-1024)>> 1024 units. Granted: the difference is tiny, but I think the statement in the code example: float voltage = sensorValue * (5/1023.0) is inaccurate!

  • @MerleCox
    @MerleCox 4 года назад +1

    I tell you what, you make this so simple. Thanks!

  • @mrgrupp
    @mrgrupp 8 лет назад +1

    0-1023 is 1024 values. The formula should be "float voltage = sensorValue * (5.0 / 1024);"

  • @ramakrishnadesala7631
    @ramakrishnadesala7631 8 лет назад

    clear & crisp expalnation. tyu

  • @algya2016
    @algya2016 9 лет назад

    changed the float and used unsigned long and did not get any decimal numbers but just the whole numbers. so if using float gets you to 2 decimal isn't better but slows down things than using unsigned long which gives you whole numbers well rounded off i guess

  • @johnanderson9619
    @johnanderson9619 2 года назад

    5 volts divided 1023 times is 0.0048875855, which is the voltage per 1 of 1023 divisions, or resolution. Double data type ftw.

  • @cupbowlspoonforkknif
    @cupbowlspoonforkknif 9 лет назад +7

    The extra challenges are good because I usually mess something up and have to problem solve which is where the real learning happens. I forgot to put the pin back to 5V from 3.3V when I went to change the range to 100... LOL

    • @programmingelectronics
      @programmingelectronics  9 лет назад +5

      David D So true! It seems that problems (and solving them - or even just pondering them) are at the heart of learning.

  • @Darkmatter321
    @Darkmatter321 7 лет назад +2

    13:30 so what determines the number of the decimal points? in this case it's 2

  • @soosaisteven3984
    @soosaisteven3984 5 лет назад +2

    Excellent video. But how if i want to use all 6 analog input channels and read them individually in serial monitor, ? I cannot extrapolate the code for 6 channels. Pls help. Thank you.

    • @Ryuuken24
      @Ryuuken24 5 лет назад

      Of course you can, you can add interrupts or call function to show each value by using the reset button on the arduino.

  • @yuvigerstein
    @yuvigerstein 9 лет назад +1

    Wonderful tutorial. Thanks so much!

  • @MikesPikes
    @MikesPikes 6 лет назад +2

    This is worth subscribing to

  • @tipko1863
    @tipko1863 5 лет назад +2

    Could you explain why the program doesn't output the voltage on the serial monitor if you use 5 and 1023 instead of 5.0 and 1023.0 ?

    • @Ryuuken24
      @Ryuuken24 5 лет назад +4

      Because float doesn't display real numbers, you need a decimal value.

  • @cordelhenson
    @cordelhenson 10 лет назад +1

    Thanks for the tutorial; if the 5v is being divided by 1023 and the float can have 7 digits why does it return to two decimal places? can you you return more decimal place with different code?

  • @udon5691
    @udon5691 7 лет назад +1

    Amazing!,this help me a lot!

  • @marcussommer6951
    @marcussommer6951 6 лет назад

    You can get the same results by just multiplying by 0.0048875855327(which is the product of 5/1023) in the Serial.println command, in the same code from the last tutorial. Like this
    void setup()
    {
    //Initialize serial com at 9600 bit/s baud rate
    Serial.begin(9600);
    }
    void loop()
    {
    //Declare variable for the value of analog pin (A0)
    int voltageValue = analogRead(A0);
    //Print voltageValue (A0) to serial monitor
    Serial.println(voltageValue * 0.0048875855327);
    //1 millisecond delay for readability
    delay(1);
    }

  • @RaymondSamuray
    @RaymondSamuray 7 лет назад +1

    Answer no.1 nope. no code changing needed
    answer no.2 change {sensorValue * (3.3 / 1023.0)} to {sensorValue * (100 / 1023.0)}
    What's my mark? 0,50, or 100?

    • @agriperma
      @agriperma 5 лет назад

      To get the serial monitor to display on a scale from 0-100 using the 3.3V source. I changed the 1023 to 675.18
      How did I come to that number? 1023/5 = 204.6 now I just multiply that by the max voltage 204.6 X 3.3 = 675.18
      Anyway your question is a year old, so you probably know all this stuff and a lot more by now,

  • @JUANITO2859
    @JUANITO2859 4 года назад

    Thanks a lot for your time and willing to share this video
    I would like to ask you,why when I run this program and runs fine but I get the time of the day also with the readings,any ideas how to get rid of the time?Thanks for your advice..Victor

  • @ramosedizamaea.1736
    @ramosedizamaea.1736 3 года назад

    How to read voltages from sensors sir? I really need it for my research. Thank you so much

  • @bradyscher7224
    @bradyscher7224 4 года назад

    I had some trouble on this one and the one before, as the elegoo starter set had some potentiometers that were pronged like mewtwo's hands, so if anybody else has those issues, just alligator clip them.

  • @mediverse
    @mediverse 7 лет назад

    Loving these ! good work !

  • @mediverse
    @mediverse 7 лет назад

    These tutorials are superb

  • @snaprollinpitts
    @snaprollinpitts 10 лет назад +5

    hey Mike, when do I use the juice cup?!

  • @Online.Alias.69
    @Online.Alias.69 5 лет назад

    Use the basic conversion formula he showed in the video, 3.3 / x units = 5 / 1023 units.

  • @arunboddu5415
    @arunboddu5415 8 лет назад +1

    can you please tell me how can i write code to get voltage change per time for this analog read

  • @MinecraftsAssassin
    @MinecraftsAssassin 3 года назад

    Is there a limit to how many lines are saved before the values converted are dumped out of memory? I'm trying to set up a way to record voltage for an undetermined amount of time, and have that data available in a csv or similar format. Alternatively in the worst case, i'd be able to copy and transfer those lines on the serial monitor if there is a very high "limit" for how many lines there are if that makes sense.

  • @Falney
    @Falney 7 лет назад

    I am guessing that this method will not be a viable option for reading a thermocouple then? since it would need to read

  • @hibahamidozair
    @hibahamidozair 8 лет назад

    Amazing tutorials!keep it up!

  • @naeemullah7744
    @naeemullah7744 7 лет назад

    very helpful.... do u have tutorial on micro controller?

  • @bigheat86
    @bigheat86 5 лет назад

    Hi. Nice video. How to measure voltage of another source? Like an voltmeter (e.g. internal 3v,measures external 50v).hint would be great. Greetings

  • @FrankLopezx
    @FrankLopezx 9 лет назад

    another thing when we do the 5.0 / 1023.0 can we do 12v so 12.0? as i would be using DC small motors 12v capable who i will power the arduino thru the VIN which i think is for max voltage 12v ? and do the math
    SensorValue * (12.0 / 1023.0) = map(Sensor Value, 0, 255);
    so now we can match/map the lowest volt to the min motor to the max motor voltage to max pot range?

  • @sarkarsalam1601
    @sarkarsalam1601 3 года назад

    I have discovered some relation between the sensor value and the input voltage, but I just wonder why (204.6) must be the basic number of this relation? is there someone to give us some information about it?
    as I pointed, if we use (3.3V), we need to multiply 3.3 by 204.6 which is equal to 675.18.

  • @alfredappel6993
    @alfredappel6993 7 лет назад +2

    i get 1023 when nothing is plugged in aswell
    or just all the time...

  • @akshaanmazumdar2364
    @akshaanmazumdar2364 8 лет назад

    great video ! extremely helpful
    but i need to know can i measure power consumed by a load using arduino?????

  • @chrysvel5150
    @chrysvel5150 8 лет назад

    Is it also possible when a power supply will be connected to the arduino. Will it know the applied voltage when you turn the potentiometer?

  • @b0bings0n
    @b0bings0n 8 лет назад +1

    Took me a little while but I got the thing to read from one to one hundred by changing the 1023 to 51.15.

    • @EmpiricalPenguin
      @EmpiricalPenguin 7 лет назад

      But, you just needed to change the 5.0 to 100.0

  • @OlivierLopezCh
    @OlivierLopezCh 7 лет назад

    I have a question. Is it really necessary to hook up the voltage to be measured to the Analog Pin 0, and why? Can I just any of the other 2, 3, 4 or 5 pins? Or is PIN 0 the only ADC pin on an arduino?

  • @E-BikingAdventures
    @E-BikingAdventures 8 лет назад +1

    No delay needed because of the float slowing it down?

  • @pugglez4798
    @pugglez4798 6 лет назад

    Why isn’t there a delay(1); in the loop for stability? Do you only need the little delay if you use a digitalWritw()?

  • @jimscobie6646
    @jimscobie6646 7 лет назад

    would someone please post a video about programming for midi electronic drums?! everyone uses the LED sketch as a demostration.

  • @domiinnno
    @domiinnno 3 года назад

    Hello, how can i measure this output voltage in javascript ? It is possible from standardFirmata ? thanks.

  • @rotanakchhean3913
    @rotanakchhean3913 7 лет назад

    Hi, could you please tell me why you use 1024 or (2^(10) value? how can I find the maximum value of analog input if my controller voltage range is 0 to 10V?

  • @RamjetX
    @RamjetX 10 лет назад

    Did this searching a while ago and wish I stumbled on this message weeks ago... By default the float value will limit to 2 decimal places unless told otherwise with the ,x number of decimal places.

  • @FrankLopezx
    @FrankLopezx 9 лет назад

    my arduino shuts off if i bring the knob to the far left, why is that ? im not using a resistor in place just small servo 5g reused pot it does this in 3.3v and 5v as well and the LED gets brighter the higher i go 1023 but back down or far left and the LED dims till it shut off im using a nano newest ver or arduino ide

  • @muhammadnoumankhan9735
    @muhammadnoumankhan9735 6 лет назад

    What will happen if i apply negative voltage on analoge pin i mean if i changed the polarity of dc voltgae which are given on analog input pin?

  • @rishi4997
    @rishi4997 5 лет назад

    why is there no delay for stability, and why did the float not have total 7 digits with 6-digit precision to the right of the decimal?

  • @Bulgdoom
    @Bulgdoom 10 лет назад

    I dont get it, I coded it a lil differently tho still the same end, where instead of using int and float i just had it for void loop:: analogRead (AO), and then Serial.println(A0*(5/1023). All i get is 0.7 over and over. Even when changing small things such as deleting int sensorValue and making a float integer for voltage. I was just playing around to see how much I could shorten the code while still functional.

  • @balancinggargoyle
    @balancinggargoyle 10 лет назад

    why no delay for stability? would you have longer delays for complex math?

  • @sporeofdeath
    @sporeofdeath 7 лет назад

    I have a question. I have a trimpot and i dont know exactly what pin is what. It keeps giving me random values between 1.something and 3.something. Did I burn my GND?

  • @asharjamal9664
    @asharjamal9664 6 лет назад

    Why is there no delay method in this code as in the previous video

  • @Strez1miroljubislav
    @Strez1miroljubislav 7 лет назад

    Great tutorial. From Slave Unknown With Love!

  • @747airmech
    @747airmech 10 лет назад +2

    ok i did the challenges when i swapped the voltage to 3.3 it worked as advertised when i went from 0-100 worked as advertised but for fun i tried to change the code to read 3.3 volts in the equation and it only read a maximum of 2.18. why?

    • @programmingelectronics
      @programmingelectronics  10 лет назад

      Whats your code look like?

    • @747airmech
      @747airmech 10 лет назад

      Open Source Hardware Group the code I used
      void setup() {
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);
      }
      // the loop routine runs over and over again forever:
      void loop() {
      // read the input on analog pin 0:
      int sensorValue = analogRead(A0);
      // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 3.3V):
      float voltage = sensorValue * (3.3 / 1023.0);
      // print out the value you read:
      Serial.println(voltage);
      }
      and I changed the wire to the 3.3v output on the board

    • @programmingelectronics
      @programmingelectronics  10 лет назад +6

      Trying changing
      float voltage = sensorValue * (3.3 / 1023.0)
      to something like...
      float voltage = sensorValue * (3.3 / 675)
      The most that analogRead is going to return when only connected to 3.3V is something like 675ish.

  • @saraahmed1654
    @saraahmed1654 4 года назад

    Thank you very much sir

  • @ideelahmed9024
    @ideelahmed9024 7 лет назад

    Great Tutorial, love it!!
    is it possible to read voltage by just using a positive and negative terminal? i have a PH probe and only two wires (anode and cathode) come out of it.
    in this case what would be my wire configuration?
    Thanks in advance!

    • @pierre-de-standing
      @pierre-de-standing 3 года назад

      I know this was a while ago now but I guess you would attach the cathode to ground and the anode to an analog(ue) input such as A0. What is needed is a potential difference applied across ground and an analogue input.

  • @starcitizenmodding4436
    @starcitizenmodding4436 7 лет назад

    why do i not get full range on my potentiometer. i get 0 and 5 v way before i have gone the whole distance of the pot? im very new to all this

  • @ICOD73
    @ICOD73 6 лет назад

    The voltage only reads one value before the decimal point so it only shows 0.00 when it should show 100. How can I change that?

  • @mrghostdlm1386
    @mrghostdlm1386 8 лет назад

    Sorry but I've got a problem, I've done the same thing but I've got an oscillating signal in the serial monitor varying from 0 to 5 and back, I've used a 50k pot.

  • @rahularunkumar8707
    @rahularunkumar8707 4 года назад +1

    Great videos..

  • @danielliberty7559
    @danielliberty7559 7 лет назад

    i did the try on you own challenge but in the first challenge the maximum value output for the voltage in the serial monitor was 2.3 and not 3.3, aby idea why? please help.

  • @binarybox.binarybox
    @binarybox.binarybox 8 лет назад

    Thanks for the tutorial. I got it going , no prob, and changed the voltage to read 0 to 100.
    However , I need to read 2 pots. Checking on arduino forum didn't give a straight answer. I've no idea what I need to declare etc to add another analogue port eg analogue(1).

    • @binarybox.binarybox
      @binarybox.binarybox 8 лет назад

      +binarybox After several attempts, I have used voltage1 and pot1 and voltage2 and pot2 and got it working by copy and pasting the code in the void loop. .... 8-)

  • @antoinegpp
    @antoinegpp 5 лет назад

    Hello !
    I need to create a "switch" between a 12V lead acid battery and a 5V dc power supply.
    I want the system to switch to the dc power supply when the battery voltage drops under 11V. How can I do ?
    thanks

  • @Mixbag
    @Mixbag 9 лет назад

    would you be willing to help me with some code ? code works perfectly on a arduino pro micro however i now want the code on a arduino uno. the temperature readings are incorrect and its due to the voltage reference not working.
    on the pro micro pin D9 Connected to VCC (5v) and this made temperature readings correct.
    on the arduino uno i have AREF and OIEF and D9 connected to vcc (5V)
    But will not work. really hope you can help as i cant figure it out im sure its a code problem im just not very experienced

  • @havefunbesafe
    @havefunbesafe 7 лет назад

    What if I wanted to have the word "volts" attached to the output as read in the serial screen? What would be the code. thx

  • @snaprollinpitts
    @snaprollinpitts 7 лет назад +1

    hey Michael, is it possible to measure voltages above 5 volts. I need to make a battery charger and would like to use an arduino to set a voltage reference between 10 to12 volts, any ideas thanks mike

    • @brucesmith9144
      @brucesmith9144 5 лет назад

      snaprollinpitts you will need a resistor divider network to accomplish that. You can also use the potentiometer; however, because the pot is variable, it is possible to accidentally present a voltage exceeding 5 Volts to the analog input. A fixed resistor-divider network will guard against that.

  • @saadkibriya1425
    @saadkibriya1425 4 года назад

    why there is no delay function included here ?

  • @abhishekmishra5833
    @abhishekmishra5833 6 лет назад

    in my code when i tried the calculation as "float voltage = sensorValue*(5/1023);" (and not 5.0 or 1023.0) i get serial prints of only 0s no matter what the position on the potentiometer. If a variable is float, its input numbers must have a decimal point in it? whats happening here?

  • @taranagnew436
    @taranagnew436 6 лет назад

    if I press a button on a LCD shield, how do I get the select button to run the loop after I press it, I am trying to make a digital dice to play catan with. heres what I have so far #include
    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
    int button;
    int btnselect_button;
    int randNumber;
    int lastButtonState;
    void setup() {
    lcd.begin(16, 2);
    lcd.setCursor (5, 0);
    lcd.println ("catan" );
    button = analogRead(A0);
    }
    void loop() {
    randNumber = random(1, 7);
    Serial.println(randNumber);
    if(analogRead(btnselect_button) == 0 && lastButtonState == 1) //if button is pressed and was released last change
    if(analogRead(btnselect_button) == 1 && lastButtonState == 0) //if button is not pressed, and was pressed last change
    lastButtonState = 1; //record the lastButtonState
    }

  • @AChadi-ug9pg
    @AChadi-ug9pg 5 лет назад

    but please sir, how about negative voltage ?? how can we get a alternating voltage via analog read

  • @alexandrugroza839
    @alexandrugroza839 5 лет назад

    Great series !!:))

  • @VivekGupta-si9he
    @VivekGupta-si9he 10 лет назад

    How come you have to initialize output / input pins for the digital pins (in the Void Setup) but you don't have to do that for the analog pins?
    Also, am I correct in saying you never have to initialize the ground and voltage (5V and 3.3 V) pins?
    Thanks!

    • @programmingelectronics
      @programmingelectronics  10 лет назад

      Vivek Gupta More great questions.
      By default, the Arduino will *automatically* set the modes of all pins to INPUTS unless you specify otherwise.
      On a side note: You will see me specifying pins as INPUTS, I do this because to me it is more *explicit* to me when reading the program - it helps remind me that a pin has been set to an input.
      ( Also, If you are not using pins in a program/project, then you don't have to worry about initializing them. )
      You are correct, you do not need to initialize the ground and/or 5V/3.3V pins.
      Have a good one!

  • @spot2be
    @spot2be 9 лет назад +1

    If I put the analog signal line in the other analog pins (A1 to A5) I get analog reading of 269 which means there is approx 1.3V on those pins. Should that be the case or is something wrong with my Arduino?

    • @programmingelectronics
      @programmingelectronics  9 лет назад

      Hi Tommy Productions , just out of curiosity) did you change the code in the Arduino sketch to sample at the other pins? Ie., did you change analogRead() to look at pin A1 for example? If not, then the Arduino is still looking at Pin A0, even if you don;t have the signal attached.

    • @spot2be
      @spot2be 9 лет назад +1

      Thanks for the reply. I did change the sketch to read A1 and moved the connection from the middle pot pin to A1. As expected it read 0-5V. Out of curiosity I checked the other pins that were not connected to the middle pin. I expected to read 0V but consistently read a voltage on the non connected (non declared) pins. Not critical .. just hunting and pecking as you suggested. Great (very understandable) tutorials! Thanks

  • @JOCHYZATION
    @JOCHYZATION 9 лет назад +2

    Hi Open Source, I'm learning with your tutorials, they are awesome! Now I tried the homework changing the pin and code from 5.0V to 3.3V, and the highest number the potentiometer gives me in the serial monitor is 2.29... could that happen because I am using INFIDUINO (chinese clone) instead of Arduino...? or could it be another reason?

    • @programmingelectronics
      @programmingelectronics  9 лет назад

      Hi Jorge, that is great question. In the first challenge, you don't need to change any code - just voltage from pin from 5 to 3.3, and you the output at the serial monitor should change to about 3.3V

    • @JOCHYZATION
      @JOCHYZATION 9 лет назад

      Thanks!

    • @racerx1326
      @racerx1326 9 лет назад +2

      Open Source Hardware Group Hi! Thanks so much for your videos. I really learned a lot. I thought you needed to modify the code to 3.3 / 1023. Can you please explain why this is not necessary?

    • @claytonbinns7679
      @claytonbinns7679 5 лет назад +1

      @@racerx1326 It's because 5V is logic high even if you are using the 3.3V supply pin. So the conversion factor doesn't change. I know your comment is old but it helps anyone else reading along

    • @SQERS3
      @SQERS3 5 лет назад

      @@claytonbinns7679 thanks i was wondering that, and thanks for answer

  • @dheerajkumar-wy8ds
    @dheerajkumar-wy8ds 5 лет назад

    why u not use the delay in the program

  • @zx001961
    @zx001961 9 лет назад

    I have a problem just wondering if you could help ....) these can be adjusted up and down Variable2 Variable1 and I'm trying to get analog.pin A0 to recognize these two
    so it will shut off or on pin6 can you help.;;;;

  • @69juggler69
    @69juggler69 8 лет назад

    I believe I am missing something...
    So, we use and ADC pin to read an analog value (between 0 and 5V). Then, we use analogRead which will give us a discrete value... after that we convert to analog again with a mathematical operation.... Why didn't we read the original value in the first place? Is this always necessary? Thanks!!!

    • @69juggler69
      @69juggler69 8 лет назад

      Oh, and congratulations for these tutorials!!

    • @kaylanipimp1
      @kaylanipimp1 8 лет назад

      Each of the analog inputs has a 10 bit analog to digital converter (ADC). What does that mean?
      It means that the input will take a refence value (5V unless you change it in the sketch) and compare to your imput value (the voltage on the middle of the potentiometer). Then it will take that value and turn into a 10 bit number and send to your monitor (10 bits = 2^10 = 1024 possible values). So we have to turn this number back into a voltage value to print it on the screen.

  • @eliashousseini9534
    @eliashousseini9534 6 лет назад

    it's a nice move to tell that the setup was made using fritzing. Since they only get money from donations.

  • @rajdhonde4492
    @rajdhonde4492 7 лет назад

    i cannot compile this project error comes while compiling .
    i have not connected my arduino and potentiometer so this problem occurs? or some other?
    the code written are correct then also i cannot copile please help

  • @jonwinfield9428
    @jonwinfield9428 6 лет назад

    Why no wait function? Is the delay not necessary?

  • @44mod
    @44mod 6 лет назад

    Ok I did the challenge at the end changing from 5.0v to 3.3v no problem. I changed the divider from 5.0 volts to 3.3 volts everything worked fine moved my connector to 3.3 power hole code float voltage = sensorValue * (3.3 / 1023.0);. Then i used the 100.0 divider for 5.0 volts of current and i got value up to 100.00. I then set my current to 3.3 volts and the max i could get for my float voltage was 37.25 is that right answer. float voltage = sensorValue * (100.0 / 1023.0);