LESSON 11: Using Arduino to Create Dimmable LED

Поділитися
Вставка
  • Опубліковано 30 лис 2024

КОМЕНТАРІ • 137

  • @gilnasty82
    @gilnasty82 2 роки тому +1

    After going through the "new" Arduino tutorials, this one I found easy. Actually, had this one done in the last lesson. Should've known this would be the next step!! 😁😁
    Anyone going through this series that hasn't done the "new" Arduino series, I highly recommend it!! Paul is an amazing teacher!

  • @dgoddard
    @dgoddard 2 роки тому

    Over the last two days I've went through starting at tutorial 1 and have made it to here. My eyes glazed over a bit on Lesson 10 when you started doing all of the math, but I chugged through it barely paying attention. Then, at the end of this video, you asked us to create a blinking LED with the pot and I freaked out. LOL I had to go back through Lesson 10 and figure it all out. I was never a math whiz and didn't take any advanced math.
    Fortunately, I am just bright enough to grasp mathmatical concepts if they're explained well. So I appreciate the time and effort you've put into these tuts. I've tried 3 times before to grasp all of this with other teachers and wasn't able to figure it out. But I did the blinking LED with the pot with minimal confusion. Thanks so much!

  • @marcods6546
    @marcods6546 8 років тому +1

    Very nice tutorials! I am taking them all one by one, and it has helped me a lot to overcome my fear over circuits that go beyond a battery, switch and light. Maybe as a simple trick to speed up the scaling relationship between numbers: I make use of a small 2by2 table. In the top right cell you write the maximum value of the one scale (say 255). In the second cell, the top left, you insert the according scaled value, which we know (1023). Now say we are interested in knowing how much 150 would translate to the second scale from 0 to 1023, write this value below 255, so the bottom right cell. All you have to do now is "draw an x": You start with the value you are interested in and jump to the diagonal cell, which is 1023 and you multiply that. And then, since you cant go diagonal anywhere except from where you came from, we must move right, to the value 255. So our previous result (150*1023) is divided by 250. This gives us the final result (602), and we finish drawing the x by writing the result in the remaining cell. Bit lengthy explanation, but I find it extremely useful and fast for calculations as simple as these.

    • @dgoddard
      @dgoddard 2 роки тому

      I appreciate the simplification of that equation. I suck at math and this does make it easier for me to remember how to get the right answer.

  • @matthewphelps8187
    @matthewphelps8187 7 років тому +2

    FYI you may want to note that with analogWrite the output voltage is always 5v from an arduino, it just turns it on and off very fast to make the led dimmer. The arduino uses Pulse Width Modulation (PWM) to simulate an analog output. The key difference is that you are not getting less voltage so you cannot use this to run anything that requires less voltage like a 3v motor without a voltage divider or transistor and a separate power circuit without something frying.

    • @midnightrizer
      @midnightrizer 4 роки тому

      Right you can use a voltage divider but current is more of an issue especially when using transistors.

  • @adriantipping
    @adriantipping 7 років тому

    Just want to say thank you so much Mr. McWhorter. I have just completed the little exercise on varying the delay time via the reading of the potentiometer. Using your point slope equation and it worked! Thank you for the lessons, I have learnt so much. A big thank you from Hong Kong:)

  • @hughpatterson1480
    @hughpatterson1480 2 роки тому

    Another great lesson Paul. Using math really helps my students understand just what is occurring when they create these programs. Thanks again.

  • @justinstraver24
    @justinstraver24 8 років тому +8

    a different way to convert analog values to any scale is to use the map function in Arduino. NewVariableName=map(oldVariableName, fromLow, fromHigh, toLow, toHigh).
    in the case of the dimmable LED: writeValue=map(readValue,0,1023,0,255);
    www.arduino.cc/en/Reference/Map

    • @paulmcwhorter
      @paulmcwhorter  8 років тому +9

      Yes, I am familiar with the map function. However, as a math teacher, the object of the lesson was to get my students to see the practical application of the Algebra I skill of working with lines. Helps them see that the math does matter, and can be used to solve important problems.

    • @McGavel1
      @McGavel1 8 років тому

      Cool, thanks! I also noticed how it's just 4 bytes vs 1 byte. Computers & electronics are so fun! Keep up the good work - peace.

    • @McGavel1
      @McGavel1 8 років тому

      Cool - thanks! As I have some coding experience and math is easy for me, I appreciate that tip on top of this lesson.

    • @randmorf
      @randmorf 8 років тому +4

      =>Justin
      You drop a few key bytes... You wrote:
      in the case of the dimmable LED: writeValue=(readValue,0,1023,0,255);
      It should be:
      in the case of the dimmable LED: writeValue=map(readValue,0,1023,0,255);
      You dropped the name of the map() function.

    • @manelserol
      @manelserol 8 років тому

      map is a great tip however it doesn't seem to work with float variables so I would suggest to use the simple equation of 1023/255=4.01 so in the code it would be writeValue=readValue/4;

  • @MrPatdeeee
    @MrPatdeeee 7 років тому

    I have just finished this lesson (and the other 10 prior to this one). You asked that we create a circuit that will allow the "pot" to control the blink rate; instead of the brightness of the LED.
    Forgetting the "syntax" for the time being, is the following correct:
    1. Connect one of the "end" connectors on the pot to a given pin (say 10).
    2. Connect the other end to pin 11.
    3. Connect the center of the pot to pin AO.
    4. Connect the resistor to a given pin (say 9).
    5. Connect the other end of the resistor to the anode of the LED.
    6. Connect the cathode of the LED to gnd.
    Assuming this is correct AND I have the programming correct; WILL the pot vary the blink "time"? IE:
    1. Pin 10 will be programmed to flash fast on and off.
    2. Pin 11 will be programmed to flash slow on and off.
    3. Pin 9 will be programmed to blink fast or slow depending on the Pot setting.
    AND the rest of the programming is correct; am I correct?
    Note: I am 85 (a 45 yrs electronic technician, now retired for 21 yrs) and I am having a problem with the syntax. Only in the fact that I forget easily. But I am determined to master this with the help of Jesus.
    Thanks so much for being a GREAT teacher and a VERY patient man.
    May Jesus richly bless you and yours always.

  • @Reach41
    @Reach41 6 років тому

    I love watching all these. Better than background music when building circuits.

  • @pinkalbhakta1955
    @pinkalbhakta1955 8 років тому +7

    hey paul. I watch your tutorial videos and i want to ask you that can you make a tutorial on how to control dc motors using motor driver shield? Thx

  • @shrenikr2602
    @shrenikr2602 5 років тому +1

    Sir shouldn't we declare the write and read values as floats. Since you are making them decimals in the calculation part?
    Please make some more informative tutorials on latest science and technology topics like AI, Cloud computing, Big data.
    It would be really helpful thank you.

  • @athienit
    @athienit 6 років тому

    There are lots ways of doing the same thing so I had a couple of thoughts:
    1. Instead of reading and writing - which is the purpose of the lesson - I am thinking that we could hook up the LED (and resistor) directly to the potentiometer, correct? I guess this is my HW.
    2. With the current setup as in the video maybe a 10k or higher setup might be more efficient for getting "read values" as the current draw for only that purpose would be lower...if running off a battery instead of plugged in.

  • @thDimension-ls3wf
    @thDimension-ls3wf 6 місяців тому

    Hello Paul
    I recently found your videos and have already learned a lot from them - thank you. I was wondering whether there was somewhere to see how to do the calculations/equations chart for the assignment you set at the end of this video? Maths was never my strong point!

  • @braydenemmerling5853
    @braydenemmerling5853 8 років тому +4

    I'm going into 8th grade and we have not covered "slopes" in 7th, so i was wondering if you could be a "math teacher" for one video. You covered the math too quick for me and I didn't understand it in your previous videos. I just took your final equation and said "sure ill take his word for it and move on." Then you mentioned it in more videos, that made me go through all the steps of making and email, account, more accounts, etc JUST so I could ask you to be a math teacher for 5 min and explain how you got to your final formula on your charts [(y^1 - y^2/x^1 - x^2) and everything else that went into your chart math with finding the slope]. And, if I didn't cover it in 7th, ill most likely cover it in 8th; That would make me ahead of the game :)
    --- An Arduino Binge Learner

  • @jayaramjonnada5855
    @jayaramjonnada5855 Рік тому

    Great video.
    Shouldn't the writevalue be defined as float, wonder why it is still working with the int Writevalue?
    May be multiplication is done before division.

  • @Wassup_its_ya_boi_mac
    @Wassup_its_ya_boi_mac 6 років тому +2

    the solution to the chalenge is =
    int pot=A0;
    int ledpin=11;
    float tim1;
    float tim0;
    int pot1;
    void setup() {
    Serial.begin(9600);
    pinMode(ledpin,OUTPUT);
    pinMode(pot,INPUT);

    }
    void loop() {
    pot1=analogRead(pot);
    tim1=(990./1023.)*pot1;
    tim0=(990./1023.)*pot1;
    digitalWrite(ledpin,HIGH);
    delay(tim1);
    digitalWrite(ledpin,LOW);
    delay(tim0);
    }

    • @kanhaiyaupreti6702
      @kanhaiyaupreti6702 5 років тому

      Why you using Serial.begin when your not using serial.println

  • @rightandleftbrain
    @rightandleftbrain 5 років тому

    Hello Paul
    I recently found your videos and have already learned a lot from them - you are a very gifted teacher.
    I am currently building a setup that involves a sip/puff switch. The sip/puff system is basically a potentiometer, so when I sip or puff (inhale or exhale) through my pressure sensor, the values change in the serial port. However, I have found one issue. As soon as I stop, either sipping or puffing, the value in the serial port goes back to 521 (neutral). This is like a potentiometer with a spring attached that would always reset itself to zero when released. I need the Arduino to freeze the value/position it has reached when I stop sipping or puffing until I give it a new command (sip or puff)
    I have tried using a while loop but it did not work as intended
    Best
    Kasper

  • @rgjoelleoj
    @rgjoelleoj 8 років тому +5

    Float is not declared to writeValue in variable declaration.

  • @DataWiseDiscoveries
    @DataWiseDiscoveries 5 років тому +1

    //to blink the led using Potmeter
    int PotPin=A0;
    int LEDPin=9;
    int readValue;
    int writeValue;
    void setup() {
    Serial.begin(9600);
    pinMode(PotPin,INPUT);
    pinMode(LEDPin,OUTPUT);

    }
    void loop() {
    readValue = analogRead(PotPin);
    writeValue =( 0.1 + (0.9/1023)*readValue)*1000;
    Serial.print(" YOUR LED IS HIGH AND LOW FOR MILLISECOND :");
    Serial.println(writeValue);
    digitalWrite(LEDPin,HIGH);
    delay(writeValue);
    digitalWrite(LEDPin,LOW);
    delay(writeValue);

    }

  • @kostasfykouras2244
    @kostasfykouras2244 7 років тому +10

    instead of the equation could we use this line of code to scale it?
    potValue=map(potValue,0,1023,0.,5.);

    • @paulmcwhorter
      @paulmcwhorter  7 років тому +29

      Yes, but the point was to get students to understand linear equations, and their importance in real world applications. Someone had to create the map function, and that was created by a person who understood linear equations.

    • @kostasfykouras2244
      @kostasfykouras2244 7 років тому +7

      Wow thanks!! I can't begin to describe to you how much i appreciate your videos!Greeting from Greece!

    • @aneeshjain905
      @aneeshjain905 4 роки тому

      Does this piece of code assume by itself that the relation is linear?

  • @MultiCheese68
    @MultiCheese68 9 років тому

    This is great. Looking for something new (electronics) to teach the kids and stumbled across this. Looks like the perfect thing I can do with them - the video tutorial was perfect; great combo of electronics, maths and programming. Have ordered a kit and will go back to lesson 1!

  • @fransdullemeijer143
    @fransdullemeijer143 3 роки тому

    I'm from Holland and follow your tutorials and my compliments for you. In this ( old) tutorial 11 however I have a question. To drive and dimming the LED pin 9 is used. This is a digital output and the signal output is a PWM output. Not analog. But it is een nice entrance to PWM. On my digital Scope it is very clear tot see how the duty cycle changes by turning the potmeter. Thankx a lot for your serie about Arduino. I learn a lot

  • @ClownWhisper
    @ClownWhisper 2 роки тому

    I could alter this code to read that value or a value I should say from and ambient light sensor and pass the sum of that math to the LED strip that I'm using and have it get brighter as it gets darker in the room. Great my project just got more complicated I've already made a fairly complex circuit board LOL. Great now my circuit works as follows. In infrared motion detector sensor when I enter the room activates and LED strip running off of 12 volts and 200 Milla amps to go Fulbright under my countertops but only when the light sensor tells the program it's below a certain value of ambient light it's really quite simple actually but it works very well I'm looking forward to deploying it but I think I might add this code then have a separate ambient light sensor measure the relative brightness of the room and adjust the lights trip accordingly. It should be very easy. I'm glad I didn't give up when I was having issues in the beginning couple of weeks ago when I first started this project hobby whatever you wanna call it LOL. I also might incorporate some soft ambient music but that might be going too far

  • @ahmedmabrouk8670
    @ahmedmabrouk8670 5 років тому +3

    the writevalue variable shold be float not int because writevalue=255(float)/1023(float)*readvalue ///thanks by the way

  • @ClownWhisper
    @ClownWhisper 2 роки тому

    Is there a step command in Arduino language for lack of a better term or step into step through etc?

  • @umangjain6759
    @umangjain6759 6 років тому

    Can you please discuss the assignment provided earlier in the video?
    And your channel rocks!!

  • @akshayshinde8573
    @akshayshinde8573 7 років тому +1

    I LIKE PAUL!, YOU ARE DOING A GREAT WORK OF CONTRIBUTION TO YOUNG MINDS...

  • @albundi2985
    @albundi2985 6 років тому

    Thanks for the neat lesson. Now I know what to show my son when he starts doing basic algebra.

  • @aryamanroongta3559
    @aryamanroongta3559 6 років тому

    Do you also teach the programming for each different type of sensor ?

  • @fvazquez64
    @fvazquez64 6 років тому

    Very interesting because now we can control an engine with the potentiometer... thanks!!

  • @oldguy8177able
    @oldguy8177able 4 роки тому

    yes i think what you are doing is making electronics fun great job

  • @jvoll7685
    @jvoll7685 10 років тому +3

    Hi Paul,
    I'm a bit confused about the use of the floating point numbers in this video. I understand why the writeValue calculation requires floating point numbers, but I don't understand why you declared the writeValue variable as an integer. Didn't you say in an earlier video that we had to declare real numbers as "float" and not "int" ? Wouldn't the result of the calculation be a float?
    By the way, I'm really enjoying your course on the Arduino. I built myself a 3d printer a couple of years ago using the Mega 2560 (following others instructions) and I've been wanting to learn how to program and use the Arduino boards myself. I'm looking forward to getting into the Python stuff you're doing with them (after I'm up to speed with this course) because I've touched on it with 3d graphics and I've heard its very powerful. The last time I got into anything like this was when PIC first came out, and the resources back then were not what they are now and I didn't get very far.
    Thanks,
    JOn

    • @paulmcwhorter
      @paulmcwhorter  10 років тому +7

      Spoofus Goofus I used an int, since I was writing it to a pin. If you are going to write a value, it should be a round number, hence an int. Since it has a floating number as part of the calculation, it will truncate the answer making it an int.

    • @jvoll7685
      @jvoll7685 10 років тому

      Paul McWhorter
      I see. Thanks.

    • @gerhardgroenewald6560
      @gerhardgroenewald6560 7 років тому

      Hi Paul
      So we can use the float " dotted " sign in calculations anywhere in the sketch if necessary knowing that it will make it an int in the end? Sorry i don't have an arduino otherwise i would have test it.

    • @khushalkapoor1716
      @khushalkapoor1716 7 років тому

      what if we use float for writeValue will it still work???

  • @charliem5b
    @charliem5b 9 років тому +1

    hi, thanks your course is pretty good, it's helping me a lot, thanks from New Zealand

  • @boowonder888
    @boowonder888 5 років тому

    I came back to this sketch after a few months to see how far I understood it. I did the math right and the programming. It didnt work. After some crrection in the code, stll didnt. Checked my connections, replaced wires. No! Now I remember the decimal floatng points in the code....
    By jove, Eureka, that must be it! Paul did expressively warn us about that, lol! If I put in the decimals in the code and it works, I will never forget to do that again!

  • @randmorf
    @randmorf 8 років тому

    ==> Paul McWhorter:
    In your solution you calculate the writeValue by multiplying the readValue by (255. / 1023.) and you are careful to have us put in a decimal point so the Arduino IDE (compiler) knows we are working with floating point numbers. My question is why doesn't the Arduino C compiler complain about the mismatch data type as it appears (I would assume) that our result is a float and we are assigning it to a variable declared as an int. That is to say, writeValue is declared an int, but when we multiply our readValue (also an int) by a float, wouldn't the system convert the result to a float, or does Arduino C do an automatic type conversion when we convert the floating point result to an int variable. Maybe it just my previous experience with less friendly C implementations that make me want to warn folks that maybe writeValue should be declared as a float (or a double) and that you will then have to covert the float value to an int value.
    Also, being more of a "quick-and-dirty tech" than a real math-oriented engineer, I'd look at the 10-bit precision of the Arduino analog inputs and the 8-bit presicion of the Arduino analog (PWM) outputs and say the difference is 2 bits or 4 (i.e. 2^2=4). So the input precision is 4 times that of the output, so just divide the input value (readValue) by 4 and you have your output value (writeValue) and you get a very close result that does not require you to use floating point math at all. My code simplifies down to:
    writeValue=readValue/4; // Instead of: writeValue = (255. / 1023.) * readValue;
    The result might be slightly off, but by so much that we as humans would be able to notice in the brightness of an LED.
    Just my 2 cents. Like your tutorial videos... Keep up the good work.

  • @BlameSomeOneUseless
    @BlameSomeOneUseless 5 років тому

    I have a 16x2 lcd screen i write to instead of the console. I've noticed that you, like i do on my lcd, get several irragularaties in the written lines as if it sometimes doesn't start on a new line before it is written even though it should be executing the same code every time. What is the reason for that and how can it be solved?

  • @longbao99
    @longbao99 4 роки тому

    can i do this lesson with 2 led?

  • @DaveGogerly
    @DaveGogerly 7 років тому

    Hi Paul, I came across something really interesting that you may want to try out, I created another variable called "ledVoltage= analogRead(ledPin);" and used the following equation to print the actual voltage of the LED Pin that is sent to the LED not the voltage that we write to the LED Pin, "Serial.println(ledVoltage * 5./1023.)" , for some reason there is a difference in the actual voltage that is put out via the LED pin or at least the reading that is sent out to the serial port. I may get a multimeter to read the actual voltage of the LED Pin to test this further , any thoughts please? by the way you are a fantastic teacher :)

  • @hahahasembarang6332
    @hahahasembarang6332 4 роки тому

    thank you for the tutorial it's very good. may I ask, why do you have to use a scale of 0 to 255, why don't you keep it from 0 to 1023?

    • @ইভানেরবাকশো
      @ইভানেরবাকশো 4 роки тому

      0-1023 is for reading or input value which indicates digital voltage 0-5. now, we use 0-255 as an analog representation of digital voltage 0-5. hope u get it

  • @arminromhanyi7669
    @arminromhanyi7669 8 років тому +1

    I managed to create a simple program that blinks and LED with the speed given in a scalde between Serial Port inputs a and b. I calculated the simple math normalizing any given value to 1023. I even added an abs() in case someone tries to switch the min and the max values...but then I was getting weird values and I crucified myself to find the mistake in my math...until I realized that I accidentally switched 2 wires on the potentiometer ...*gigantic facepalm*
    Good video, keep doing the good stuff!

  • @koshakprontix5821
    @koshakprontix5821 5 років тому

    I love that everybody is always happy

    • @paulmcwhorter
      @paulmcwhorter  5 років тому +2

      This is the happy channel

    • @koshakprontix5821
      @koshakprontix5821 5 років тому

      @@paulmcwhorter very true. Do you have an explanation to the other comment i posted yet?

  • @s.bharathpenagaram2526
    @s.bharathpenagaram2526 5 років тому

    Hello sir ! What should the value of petentiometer???

  • @MrPatdeeee
    @MrPatdeeee 7 років тому

    Paul, is the following the correct way to do the assignment? It works, but I am not sure it is the right way to do it.
    Thanks:
    int potPen=A0;
    int LEDPin=9;
    int readValue;
    int delayValue;
    void setup() {
    Serial.begin(9600);
    pinMode(potPen,INPUT);
    pinMode(LEDPin,OUTPUT);
    }
    void loop() {
    readValue = analogRead(potPen);
    delayValue=(readValue/1023.*1000.);
    digitalWrite(LEDPin,HIGH);
    delay(delayValue);
    delayValue=(readValue/1023.*100.);
    digitalWrite(LEDPin,LOW);
    delay(delayValue);
    Serial.print("Blink delay is: ");
    Serial.println(delayValue);
    }

  • @richardh568
    @richardh568 6 років тому +1

    Hello. I built the circuit and code, and checked it well, but my LED does not change brightness. It come on at 1V, and does not change as I increase the pot. Any ideas??? Yo

    • @-thesmartboard8984
      @-thesmartboard8984 5 років тому

      @Neo mine was on pin 8
      when I moved it to pin 9 it worked
      there is a small sign on the pin number and it tells you that this pin works for analog

  • @anhdo3368
    @anhdo3368 5 років тому +1

    Can I have the code for your assignment??

  • @lucamorini4072
    @lucamorini4072 4 роки тому

    Thank you for your precious work! It really helped me

  • @erygion
    @erygion 5 років тому

    Great lesson Mr. Mcwhorter, thank you. I'll be doing the homework as well.

  • @jopbag9434
    @jopbag9434 6 років тому

    Hello mister McWhorter
    I have a question about this turtorial. You are write a analogWrite to LEDPin or pin#9 but pin # 9 is a digital pin . Can you please explain me how this is posible ? Because i am a litle bit confused.

    • @jugern0t
      @jugern0t 6 років тому +2

      The use of the word analog is misleading. The pin only ever outputs 0 or 5 volts, but pins marked with the ~ on the Arduino are PWM: pulse width modulation. Every one 500th of a second can be broken up into 255 segments. You get to choose to keep the pin active anywhere from 0 of those to all 255 of them. When you dimming an LED, you don't actually raise or lower the voltage, you just turn it on and off 500 times every second. It's perceived by human eyes to be more bright the longer you keep it on, and less bright the more it's off. Although this is digital in one sense, it's analog from the perspective of a human observer, and through analog circuits, you can convert a PWM signal to an analog voltage.
      It's important to understand that the number 255 is not chosen randomly. It's the maximum unsigned value that can be stored with one byte, which is 8 bits, or 2 to the 8th power. It's better, mathematically, to think of this as 256, as 0 is included. PWM is only using 255 segments per cycle because a level of 0 is completely off and 255 is completely on. This is messy to consider for the purposes of describing PWM, as seen in the awkward chart and slope calculation, as what is actually happening is dividing the cycle into halves. Half of half of half of half of half of half of half of half is 1/256th.

  • @skyrim4713
    @skyrim4713 6 років тому

    Could you make video on programing for audio sound

  • @hajarchatoui1380
    @hajarchatoui1380 5 років тому

    hello dr., thank you for amazing video on Arduino and helpful too much thank you but dr. I have an issue my pot only display 14 and with led 3v is not working I changed it many times, in fact, it still in 14 plz help me to fix it. in the beginning, it was 1023 but now only 14.

  • @mynameisisu2000
    @mynameisisu2000 8 років тому +1

    Wont it be easier/simpler to do the calculations using Unitary method?

    • @davidprice2861
      @davidprice2861 6 років тому

      Agree, why bother with y=mx+b etc. annoying to me, we need simple ratio not slope equation ???

    • @jynclr
      @jynclr 5 років тому

      @@davidprice2861 Except the slope equation *is* a ration. When you get your final equation, you'll notice a fraction. Fractions are ratios.

  • @koshakprontix5821
    @koshakprontix5821 5 років тому

    paul, my led is not turning on at all, but the serial monitor is showing the voltage. I can't figure out what's wrong. i might've burnt my 5v pin

  • @ইভানেরবাকশো

    can someone help me understand how the circuit in this lecture is working? i m mainly facing problems with potMeter :(

  • @howardtang8720
    @howardtang8720 6 років тому

    So why couldn't you have just skipped the step of finding write value and just written analogWrite(LEDpin, readValue); ? Would it be because readValue goes to 1023 but analogWrite only accepts up to 255? I tried it out without using writevalue and it worked fine. Any ideas?

    • @quantumaxe6468
      @quantumaxe6468 6 років тому

      I think it is only for converting and printing in digital value. Maybe also for any future changes that could be done without getting into codes.

  • @91722854
    @91722854 7 років тому

    why do we use the ground from right side of the arduino instead of left like the previous video?

    • @paulmcwhorter
      @paulmcwhorter  7 років тому

      They are both the same. They are connected on the board. I do not think about which one I use because they are the same.

  • @dhavalpatel1622
    @dhavalpatel1622 7 років тому

    Hello sir do you have any lesson related to control metrix led if you have then you send me link plz

  • @vinayverma3138
    @vinayverma3138 5 років тому

    Shouldn't we declare writeValue as an float ?

  • @agentbertram4769
    @agentbertram4769 7 років тому

    Hi Paul, Here is my simple hack at the assignment you set in Lesson 11.
    I tried plotting the graph and I think that the write runs from 25 to 255 due to the '0.1 second Vs Zero analog read value'
    i.e. the graph does not pass through Zero on both scales.
    You didn't ask for the serial port to be available but it can be added back in to add functionality.
    int LEDPin = 9; //Declare LEDPin to be Arduino pin 9
    int potPin = A0; //Declare potPin to be anaolgue pin A0
    int readValue; //use this variable to read potentiometer
    int cycleTimeLED; //Declare variable for LED on period.
    void setup() { // put your setup code here, to run once:
    pinMode(potPin, INPUT); //set potPin to be an INPUT
    pinMode(LEDPin, OUTPUT); //set LEDPin to be an OUTPUT
    }
    void loop() { // put your main code here, to run repeatedly:
    readValue = analogRead(potPin); //read voltage from potentiometer
    cycleTimeLED = (230./1023.) * readValue; //calculate cycle time ###
    digitalWrite(LEDPin, 1); //write to switch on LED
    delay(cycleTimeLED); //delay by cycleTime
    digitalWrite(LEDPin, 0); //write to switch off LED
    delay(cycleTimeLED); //delay by cycleTime
    ### I'd like some advice here because it seems to work but I'm not happy with the solution
    Did you publish your solution code someplace?

  • @yunusseven
    @yunusseven 7 років тому

    Why doesn't Arduino convert the signal into volts itself? Is it necessary in any application to get the values 1023 or 255 instead of 5 volts?

    • @jugern0t
      @jugern0t 6 років тому

      Volts make sense to humans, but they're horrible for doing calculations on a microcontroller. 1023 and 255, while technically the maximum values for these particular applications, are the wing numbers to focus on. 256 is 2 to the 8th power, which makes it the total number of unique values that can be represented by a single 8 bit byte. 1024 is 2 to the 10th, which is 4 times as precise as what can be stored in 1 byte. Though this adds precision, it comes at a cost of awkward storage. 2 full bytes gives 65,536 values, which is really precise, but is beyond the ability of the microcontroller to actually measure voltage so there's no point in going there. Having the precision of 1024 values to represent voltage means being able to represent 3 digits of voltage somewhat accurately (0.00 to 5.00 is 501 decimal possibilities, and this essentially doubles up on that), and makes binary math (what the microcontroller natively performs) really quick and easy. Any program (Arduino sketch) is natively performing all calculations using binary arithmetic, so any values you work with would need to be converted into binary anyway. Using these values from the start preserves the maximum usable precision. It both eliminates waste and remains accurate. Both of these qualities would be sacrifices by focusing on the human comfort of the 0 to 5 volt range in that form.

  • @koshakprontix5821
    @koshakprontix5821 5 років тому

    i love these. they give so much information.

  • @SavageStyle77
    @SavageStyle77 7 років тому

    Amazing work! Great lessons! Thank you so much!

  • @jumbo999614
    @jumbo999614 5 років тому

    Can variable potPin=A0 be String instead of Int?

    • @boowonder888
      @boowonder888 5 років тому

      Paul, no. A string is purely for printing text on the serial.monitor..............

  • @shalithamarasinghe3421
    @shalithamarasinghe3421 4 роки тому

    Perfect. well explained....

  • @RulgertGhostalker
    @RulgertGhostalker 5 років тому

    the LED is getting brighter, and dimmer, because your varying the 5v Pulse Width, not the Voltage.....i need to vary voltage, so i am getting a DAC from adafruit.

  • @jugern0t
    @jugern0t 6 років тому +1

    So... 255 and 1023 are not random numbers, they're 2^8-1 and 2^10-1. Your ratio isn't 255/1023, it's 256/1024. That's 1/4 -- much simpler by design. Don't make the math more complicated than it is by failing to see the binary simplicity that's intended by design. Another thing that's very important is that perceived brightness of light is logarithmic. This is known as the Weber-Fechner law. A brightness of 2 is a linear step brighter than 1, but a jump from 2 to 4 is the same linear jump, as is from 4 to 8, 8 to 16, etc. This means that a jump of 1 to 2 is just as noticable as a jump from 128 to 255. If it looks like you do all your dimming at the low side of the potentiometer, it's because your are. If you want the dimming to be linear, don't use the equitation for a line: use the equation for a logarithmic curve. That is, your chart is worthless for this application.

    • @tiernanomahoney8826
      @tiernanomahoney8826 5 років тому

      It a dumbo when u have a fraction and u add or subtract both the numerator and denominator IT DOES NOT CHANGE Take 2/3 if we take 1 from top and bottom we get 1/2 Clearly not the same

    • @midnightrizer
      @midnightrizer 4 роки тому

      Logarithmic curve would be pointless it is not true analog it is PWM pulse width modulation. not a smooth log curve previously known as logarithmic taper of a pot. VS linear taper.

  • @charlesklein7232
    @charlesklein7232 6 років тому

    you said their was a way to communicate with you on your web site. i have been to your web site but saw no way to communicate with you.

  • @McGavel1
    @McGavel1 8 років тому

    Wooot - my dimmer works!!! So excited cuz I can see so much power in these preliminary lessons and I don't even know what i don't know yet - haha!
    Thanks a ton for the challenge at the end of the lesson. Gonna try that now.
    Cool, got it!
    blinkRate = -900.0 / 1023 * readVal + 1000;

    • @363rs
      @363rs 7 років тому +1

      I might sound dumb, but how did you get -900?

  • @pingspoofing3541
    @pingspoofing3541 8 років тому

    whats the potentiometer parameters?

  • @Bob-zg2zf
    @Bob-zg2zf 6 років тому

    Morning, Paul. Thanks again for these very valuable And Free lessons. I have finished Lessn 1 to Lessn 11 and the Lesson on Software Interrupt. I fully understand them.
    However, last night, when I was following this Lesson 11, I related Lesson 11 with Lesson 8, because they all involve the mapping of real world voltage to analog voltage. Fine. I get it.
    The thing is, in Lesson 8(at 4' 30"), you simply told us the upper limit of the "analog write" voltage is 255. My question is, how do you know this number? Where does it tell you it's 255?
    I'm asking this because in Lesson 11, we can visually see in the serial output window that the upper analog voltage with the potentiometer is 1023.
    So, would you please explain how we got the number 255?
    Thank you and have a great day!

  • @kushagrakantsaxena
    @kushagrakantsaxena 4 роки тому

    I created it without using potentiometer I just used Analog

  • @rafaelaprende
    @rafaelaprende 7 років тому

    Why didn't you write "float writeValue;" instead of "int writeValue;"? Isn't "writeValue" a float variable?

    • @DustinMowcomber
      @DustinMowcomber 4 роки тому +1

      It’s an int because he declared it as an int. The result of his calculation will round up or down.

  • @jackdavies3666
    @jackdavies3666 4 роки тому

    Does anyone have the solution to the assignment posed at the end of the lesson? I can figure out how to scale between 0-1023 to 10ms-1000ms.

    • @PvPparadise
      @PvPparadise 4 роки тому +3

      Yo , yes. So basically you just use the same equation that he used. Except that now: y2=100(ms), y1=1000(ms) and x2=1023 , x1=0.
      So m=y2-y1/x2-x1 , m=-900/1023. So then y-y1=m*(x-x1) which turns into y = -900/1023 * x + 1000.
      In this equation "y" is your DELAY (in miliseconds) and "x" is the READ VALUE from the potentiometer.
      So you would write:
      float blinkSpeed; //

    • @martinxp2535
      @martinxp2535 4 роки тому

      @@PvPparadise Thanks and it works. I was never a genius at maths so sorry if a dumb question. Where does the +1000 come from?

    • @ajbalidio.01
      @ajbalidio.01 2 роки тому

      @@PvPparadise thanks

    • @davidbgood2801
      @davidbgood2801 9 місяців тому

      I got Y=(900./1023.)*X+100.

    • @davidbgood2801
      @davidbgood2801 9 місяців тому

      I got to looking again at what Mr. Mcwhorter said and this may better be the correct answer y=(990./1023.)*X+10. they both work but this one blinks faster to the left but they both blink 1 time a second all the way to the right.

  • @SOME_WORDS
    @SOME_WORDS Місяць тому

    I don't understand why it is necessary to draw this graph and perform long complicated calculations that confuse the listeners, when all that needs to be done is to divide 1024 by 5, that is, to find the ratio of the scales.

    • @paulmcwhorter
      @paulmcwhorter  Місяць тому

      Because the purpose of this channel is to teach people skills they can actually use to get a good job and have a career in the engineering field. This requires skills in math. What you have described is not math, and something that only sometimes works, if the y intercept is zero. In general, people apply this short cut when the y intercept is not zero, and hence get wrong answers. This channel is about getting the right answer the right way. If this is not what you are interested in, it is not the right channel for you.

  • @tameral-rodainieh849
    @tameral-rodainieh849 5 років тому

    thank you great teacher....

  • @disappear1234
    @disappear1234 8 років тому

    im using this potentiometer when i turn the it my led turn on and off it doesnt dim

    • @paulmcwhorter
      @paulmcwhorter  8 років тому

      +wally alexandre Make sure you are using a pin with a ~ beside it.

    • @disappear1234
      @disappear1234 8 років тому

      +Paul McWhorter thank you

  • @JulianAvalos
    @JulianAvalos 7 років тому

    Can't believe I'm actually controlling the voltage sent to the led via a program in realtime..... woohoo! This is great.

    • @paulmcwhorter
      @paulmcwhorter  7 років тому +1

      Yes exciting to experience that level of control and understanding. Same principles will allow control of much more complicated devices.

  • @adsadejglanboot6543
    @adsadejglanboot6543 6 років тому

    very nice! more videos please

  • @sksarfaraz27
    @sksarfaraz27 4 роки тому

    This vedio is not visible....

  • @martinxp2535
    @martinxp2535 4 роки тому

    I got it to work but not really how you wanted it done (bit of cheating):
    int LedPin=9;//declare output to LED on pin 9
    int PotPin=A0;//declare potentiometro input
    int ReadValue; //creat a read value int
    float WriteValue; //creat a write value float
    int OnTime;
    //declare OnTime int
    int OffTime;
    //declare OffTime int
    void setup() {

    Serial.begin(9600);//activate serial comunication
    pinMode(PotPin, INPUT);//set pin mode of PotPin to an INPUT
    pinMode(LedPin, OUTPUT);//set pin mode of LedPin to an OUTPUT

    }
    void loop() {
    ReadValue= analogRead(PotPin);//read value from analog pin A0
    - read value is from 0-1023
    WriteValue=1023.-ReadValue;//calculate on time and off time

    if(WriteValue>1000.){

    WriteValue=1000.;
    //if WriteValue is more than a 100, force it to 1000 max

    }
    if(WriteValue

  • @capistor1
    @capistor1 6 років тому

    I am really ashamed to say but it's been a month since i have been constantly thinking about the homework. i didn't want to copy but just today i was forced to cause this was driving me mad. i dont have a background in math. in fact i failed math. COULD SOME ONE FOR THE LOVE OF GOD EXPLAIN HOW THIS WORKS. i am lost. i know i will never be able to figure it out cause i panicked. if you can't explain in the comments, kindly link me to a math video teaching this in detail and for full begginers so that i can use this my own way however i want.

  • @saptangshumanna9919
    @saptangshumanna9919 7 років тому +2

    I am getting very exited ;@

  • @Ozone289
    @Ozone289 5 років тому

    nice

  • @browaruspierogus2182
    @browaruspierogus2182 6 років тому

    I burned like 20 diodes already...

  • @user-popay
    @user-popay 7 років тому

    t

  • @technovan1133
    @technovan1133 5 років тому

    sir could you just please skip the math thing and get to the point, we thank you!!

    • @paulmcwhorter
      @paulmcwhorter  5 років тому +5

      Actually the math is very important. If you do not understand the math, you will never be a successful engineer or scientist. My goal is to train people to become successful, not create ignorant coders.

  • @davidprice2861
    @davidprice2861 6 років тому

    Jeez, why not just apply the ratio, 255/1023=0.249 x R(pot) ffs. why all the, y=mx+b crap !!!

    • @paulmcwhorter
      @paulmcwhorter  6 років тому +5

      Because we need to understand how lines work, not just lines with y intercept of zero. Your shortcut does not work for cases where y intercept is not zero. To be a good engineer, we must understand the underlying math, so we can solve real problems, not just ones which have short cuts.