t r o n i x s t u f f

fun and learning with electronics

Getting Started with Arduino! – Chapter One

Please note that the tutorials are not currently compatible with Arduino IDE v1.0. Please continue to use v22 or v23 until further notice. 

This is part of a series titled “Getting Started with Arduino!” – A tutorial on the Arduino microcontrollers, to be read with the book “Getting Started with Arduino” (Massimo Banzi). The first chapter is here.

Welcome back fellow arduidans!

I hope you have been enjoying your new-found skills with the Arduino system, and enjoying Massimo’s book. There are many interesting tasks for you to complete in this week’s instalment: finish chapter four and five of the book, which contains some vital information about electricity; we’ll look at a new command or two for your sketches that will save you time and a lot of sketch memory; take a look at pulse width modulation (huh?); go random!; receive inputs from analogue sources; make some decisions; and finally – complete a project as an exercise for you to test your new knowledge.

First of all, please continue on from page 38 until the end of chapter four. This contains excellent instuctions on how to deal with “switch-bounce”, which is vital for future use. See you soon!

Hello again.

Recall from the previous instalment that your exercise involved a lot of repeated commands to light each LED in sequence – for example:

digitalWrite(2, HIGH);   // turn on LED on pin 2
delay(del);              // wait (length determined by value of ‘del’)
digitalWrite(2, LOW);    // turn it off
digitalWrite(3, HIGH);   // turn on LED on pin 3
delay(del);              // wait
digitalWrite(3, LOW);    // turn it off
digitalWrite(4, HIGH);   // turn on LED on pin 4
delay(del);              // wait
digitalWrite(4, LOW);    // turn it off
digitalWrite(5, HIGH);   // turn on LED on pin 5
delay(del);              // wait
digitalWrite(5, LOW);    // turn it off
digitalWrite(6, HIGH);   // turn on LED on pin 6
delay(del);              // wait
digitalWrite(6, LOW);    // turn it off
digitalWrite(7, HIGH);   // turn on LED on pin 7
delay(del);              // wait
digitalWrite(7, LOW);    // turn it off
digitalWrite(8, HIGH);   // turn on LED on pin 8
delay(del);              // wait
digitalWrite(8, LOW);    // turn it off
digitalWrite(9, HIGH);   // turn on LED on pin 9
delay(del);              // wait
digitalWrite(9, LOW);    // turn it off

That seemed repetitive and time consuming – the nemesis to the reasoning for the existence of Arduino! However the solution can be found by using the for command. The purpose of the for command is to repeat a section of your sketch a number of times (of course this number is an integer – you cannot repeat a loop 3.141 times!).

Below is a very basic example that blinks an LED on pin 9 five times: (download)

/* Example 1.1 – using the ‘for’ command

Created 02/04/2010 ---  CC by-sa v3.0 Share the love!
By John Boxall --- http://tronixstuff.wordpress.com
Blinks LED on digital port 9 five times...
Based on an orginal by H. Barragan for the Wiring i/o board
*/
void setup()
{
pinMode(9, OUTPUT);     // initialise the digital pin 9 as an output
}
void loop()
{
for (int wow = 1; wow <= 5;  wow++)
{
digitalWrite(9, HIGH); // turn on digital pin 9
delay(1000);         // wait a moment
digitalWrite(9, LOW); // turn off digital pin 9
delay(1000);         // wait a moment
}
delay(10000); // wait 10 seconds, then the whole thing will start again
}

What is happening here is this:

  • the integer “wow” is set to have a value of one
  • the code in the curly brackets is executed
  • the code checks to ensure “wow” is less than or equal to five, then increments “wow” by one

You can also use “wow–” to subtract one from the value of wow, or another variable. Anyway, if wow <=5  the looping continues; and if wow>5 it stops and the sketch moves on.

Hopefully by this stage you have recognised how this can simplify the code for exercise 0.1 from the last instalment. No? Let’s try that now. So instead of that huge block of code to light the LEDS in order up and down, rewrite it to use two loops – one for the up direction, and one for the down.

How did you go? Here’s what we came up with: (download)

/*
exercise 1.1 - using the 'for' command in exercise 0.1
Created 02/04/2010 ---  CC by-sa v3.0 Share the love! - By John Boxall --- http://tronixstuff.wordpress.com
Based on an orginal by H. Barragan for the Wiring i/o board
*/
int del=100; // sets a default delay time, 1000 milliseconds (one second)
void setup()
{
// initialize the digital pins as outputs:
for (int i = 2; i<=9 ; i++)
{
pinMode(i, OUTPUT);
} // end of for loop
} // end of setup
void loop()
{
for (int i = 2; i<=9; i++) // blink from LEDs 2 to 9
{
digitalWrite(i, HIGH);
delay(del);
digitalWrite(i, LOW);
}
for (int i = 8; i>=3; i--) // blink from LEDs 8 to 3
{
digitalWrite(i, HIGH);
delay(del);
digitalWrite(i, LOW);
}
}

Well, wasn’t that better? Those for loops saved us a lot of time, and the use of variables also allows for sketch modifications to be much easier that hunting for each value to change within the sketch.

Groovy. Time for a quickie:

Hey, do you need a random integer? Easy!

random(x) returns a random integer between 0 and x-1. For example, if you need a random number between 0 and 255, use random(256). However, using random() is not entirely random, you need to seed the random number generator inside your Arduino chip. Use randomSeed(analogRead(0)); or another open analogue pin. You can also specify a range, for example random(10,20) will produce a random number between 10 and 19 (the minimum of the range is inclusive, the maximum exclusive – that is why the range is 10~19.

Next on the agenda is pulse-width modulation. Instead of reinventing the wheel, you will now work through chapter five of the book until the end of page 62.

Now that you have emulated a popular cult’s computer, it’s time to have some real fun with PWM and colours. Massimo mentioned about using red, green and blue LEDs to make any colour in the spectrum. This can be done quite easily (like most things) with your Arduino! When you were in school in art classes, you may remember that red + yellow = orange, red + green = blue, and so on. You can achieve the same effect using LEDs, and also vary the brightness between them to create the entire colour spectrum.

First, let’s look at how the primary colours can be used to create all sorts of colours. This example demonstrates briefly the possibilities of experimenting with red, green and blue.

You will need:

  • Your standard Arduino setup (computer, cable, Uno or compatible)
  • A diffused (not clear plastic) common-cathode RGB light emitting diode. A diffused LED will shine like a light bulb, where a clear one will just look like a 5mm dot.
  • 2 50 ohm 0.25 W resistors. They are to reduce the current to protect the green and blue LED section
  • 1 150 ohm 0.25W resistor. This is to reduce the current to the red LED section
  • a breadboard and some connecting wire
  • a camera (optional) – to document your success!

The circuit is quite simple, however the pins of the LED can be tricky. Here is the explanation of their layout:

The resistors are between the PWM output pins and the colour anode of the LED. See the board layout below:

And here is the code… oops sketch: (download)

/*
example 1.2 - fun with PWM and RGB LED -  Created 07/04/2010 ---  CC by-sa v3.0 Share the love!
By John Boxall --- http://tronixstuff.wordpress.com
*/
int red = 11; // the pins for the LED
int green = 9;
int blue = 10;
int i = 0; // for loops
int j = 0;
void setup()
{
pinMode(red, OUTPUT); // tell Arduino LED is an output
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}
void loop()
{
// first, cycle up each primary colour twice
for (j = 1; j < 6; j++)
{  // loop 5 times
for (i = 0; i < 255; i++)
{ // loop from 0 to 254 (fade in)
analogWrite(red, i);      // set the LED brightness
delay(20); // Wait 10ms because analogWrite isn't instant
}
analogWrite(red,0);
delay (20);
for (i = 0; i < 255; i++)
{ // loop from 0 to 254 (fade in)
analogWrite(green, i);      // set the LED brightness
delay(20); // Wait 10ms because analogWrite isn't instant
}
delay (20);
analogWrite(green,0);
for (i = 0; i < 255; i++)
{ // loop from 0 to 254 (fade in)
analogWrite(blue, i);      // set the LED brightness
delay(20); // Wait 10ms because analogWrite isn't instant
}
delay (20);
analogWrite(blue,0);
}
// psychadelic time
for (j = 1; j < 10000; j++)
{
analogWrite(red,random(255)); // set red at random brightness between 0 and 254
delay (random(10,31));           // wait for a random duration between 10 and 30 milliseconds
analogWrite(green,random(255));
delay (random(10,31));
analogWrite(blue,random(255));
delay (random(10,31));
}
}

And here it is in action! Mesmerising…

Wasn’t that fun? I hope you enjoyed that as much as I did writing about it for you.

Don’t stare at the LED for too long though… we’re moving on to analogue sensors! Follow the book until the end of page 69.

Now for something completely different. It is time to learn about a new command: if…else

More often than not your sketch will need to make a decision. Is a switch on? Or is it off? If the variable ph equals 8657309 I will send that number to the GSM module to dial the number! Once again, with Arduino – it’s ardueasy! :)

Example: if the value of temperature is greater than 100, turn off pin 13, otherwise turn it on.

if ( temperature > 100 )
{
digitalWrite(13, LOW); // turn off kettle
}
else
{
digitalWrite(13, HIGH); // leave kettle on
}

You can also extend this with else if…

Example: if the value of temperature is greater than 100, turn off pin 13; otherwise if value of humidity > 80, turn on pin 7.

if ( temperature > 100 )
{
digitalWrite(13, LOW); // turn off kettle
}
else if (humidity > 80 )
{
digitalWrite(7, HIGH); // turn on pin 7
}

With the if…else statement you have a choice of six operators:

  • == equals
  • > greater than
  • < less than
  • >= greater than or equal to
  • <= less than or equal to
  • != not equal to

At this point go and have a break and some fresh air. Because after that, it’s time for…

Exercise 1.1

Now we want to put together all the things learned so far and make something that has analogue inputs, digital outputs, and lots of LEDs… a voltmeter! Imagine a bar graph of ten LEDs, each one represents a voltage range. The range of the voltmeter will be between 0 and 10 volts DC – ideal for testing batteries and cells before they head to the garbage bin.

That sounds like a lot of work (the sketch, not throwing away batteries), but it isn’t when you break it down into smaller tasks. Let’s have a think about it…

We know that analogRead() can measure between 0 and 5 volts, and return an integer between 0 and 1023 relative to the measurement. Ah, but we want to measure up to 10 volts. Easy – use a voltage divider. (Need a refresher? Check this post here). Use two small resistors of equal value (e.g. 560 ohm 0.25 watt).

Next, how to convert that analogRead() value to represent a voltage we relate to an LED. We know that it will return a value between 0 and 1023, in our case that relates to 0~10 volts. So each LED will relate to one-tenth of the maximum reading. So the first LED will need to be illuminated if the analogRead() returns between 0 and 102.3 (actually 102 as it returns integers, not real numbers). The second LED will need to be illuminated if analogRead() returns between 103 and 205. Etcetera.

Now the rest should be easy… use your new sketch decision-making skills to decide which LED to light up (and don’t forget to turn it off as well) and you’re away…

You will need:

  • Your standard Arduino setup
  • ten LEDs of your choice. Standard ones are fine, or perhaps a mixture of colours?
  • 3 x 560 ohm 0.25 W resistors. One to reduce the current to protect the LED indicator in use, and two for the voltage divider
  • 1 x 10k ohm 0.25 W resistor. For use with the analogue input
  • a breadboard and some connecting wire
  • a camera (optional) – to document your success!

So here is our layout diagram:


And here it is in real life:

… and the action movie! We connected a variable power output to the voltmeter for the sake of the demonstration …

… however due to resistor tolerance and other analogue electrical problems caused by using a breadboard, our voltmeter was a little overenthusiastic. So like any quality piece of test equipment, it required some calibration. There are two ways this could be achieved:

  • put a variable resistor in the voltage divider. Then feed a known source, such as 5V from an LM7805 regulator, then adjust the variable resistor until LED 5 was constantly on;
  • put another voltmeter (e.g. a multimeter) over the voltage input to measure the voltage being measured by our voltmeter; use the serial.begin and serial.println() functions (from page 69) to send the value of voltage to the screen. Adjust the voltage being measured until you hit 1, 2, … 10V – noting the serial output. Then substitute these values into the if…then decision tree for the LEDs.

The second method is more accurate and easier to accomplish, so I have inserted the serial code into the example sketch below.

Here is a clip showing the results of the second calibration option:

So how did you go? Did it work first time? It’s ok if it didn’t, as you learn by doing and fixing your mistakes. Remember – if you have any questions, leave a comment at the bottom of this post and I will get back to you. But to save you time, here is the sketch. So there you have it. Today you have learned many more useful things to help you on your Arduino journey.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

April 10, 2010 - Posted by | arduino, microcontrollers | , , , , , , , , , , , ,

56 Comments »

  1. Hello John

    You have done a really great job, after I have look and read at your web pages, I became interested in start with Arduino too.

    I have a little question about Arduino Duemilanov board, there is a 8pin chip near the Atmega168/328 IC, but I can not see this 8pin chip at same boards schematic!
    Would you please tell me what is this chip about and why I
    can’t find it at board’s schematic.
    Thank you
    Keep the Good work

    Comment by Reza | June 8, 2010 | Reply

    • Hello Reza
      Thank you for your kind words. The IC you are looking for is the LM358D dual op-amp. That is why it is hard to locate on the schematic, as the individual amplifiers are on separate parts of the schematic – but it is there! If you download this .pdf file – http://arduino.cc/en/uploads/Main/arduino-duemilanove-schematic.pdf – and open it up. Look for the triangles at the top, labelled IC5A and IC5B – that’s your chip. :)
      We have a Google Group for discussion, please feel free to use it: http://groups.google.com/group/tronixstuff.
      Take care
      John

      Comment by John Boxall | June 8, 2010 | Reply

      • Hello John,

        Thaks a lot for your quick reply, sure I’ll join the Google
        Groupe, there would be a great place to ask about the
        electornic and Arduino’s issue and get some qualified advices from advanced user like your self.

        Best regards
        Reza

        Comment by Reza | June 9, 2010

  2. I am a fan of your work. Beginners like me need a lot more help with programming and your explanations have been a lot of help. I still have great difficulty getting my head around the for() command.

    To get this code to print to the serial port I had to add an extra line in the loop of the sketch “Serial.println (voltage);” Was this needed?

    Please keep up the good work and don’t touch those lethal voltages

    Mark

    Comment by mark | June 17, 2010 | Reply

    • Hello Mark
      Thank you for your comments and kind words, they really made my day :)
      You are right – some more code was needed. I forgot to put it in. However, I have updated the sketch so it writes the voltage to the serial port, which you can watch with the serial monitor box. Please have a look at this file: http://tronixstuff.files.wordpress.com/2010/04/exercise1p1.pdf
      Have fun, and yell out if you have any more questions.
      Cheers
      john

      Comment by John Boxall | June 17, 2010 | Reply

  3. Hi John,

    Awesome stuff! I love these tutorials and I am learning a ton. Thank you SO much for putting these out here.

    The code/comments in your “example 1.2 – fun with PWM and RGB LED” could use some sprucing up, though. I’m worried about the folks who might be new to coding. For example:

    1) “for (j = 1; j < 2; j++) { // loop 5 times"
    This loops once, not 5 times.

    2) "delay (random(21)+100); // wait for a random duration between 10 and 30 milliseconds"
    I don't think this generates a random number between 10 and 30. If I understand the random() method, you're generating a time delay of 100 and 120 ms, inclusive. Please correct me if I am wrong.

    Thanks,
    Phil Hutchinson

    Comment by Phil | June 19, 2010 | Reply

    • Hello Phil
      Thank you very much for your comments and suggestions, I really do appreciate it. So many people are reading this but few actually say anything or point out the odd errors – so thanks again. I have fixed up the errors that you have pointed out as well.

      I really enjoy writing these, and it makes my day when people enjoy reading them. Good on you!
      Have a great and safe weekend
      Cheers
      John

      Comment by John Boxall | June 19, 2010 | Reply

  4. Hi Carl
    Thanks for picking up the error for me.
    Cheers,
    john

    Comment by John Boxall | December 5, 2010 | Reply

  5. My RGB LEDs all had a common +5 with the R-G-B color lines to GND. This means that 0 is bright and 255 is off. Maybe its just me but I read your directions/code to be the opposite and it drove me nuts until I figured it out.

    BTW the wiring diagrams could be a little more clear in your tutorials. You can’t really tell what pins are connected to what in the pix.

    Comment by John E | January 25, 2011 | Reply

    • Hello John
      Thank you for your feedback. When I first started writing the articles, they were more of a personal notebook than anything, plus I am a fan of the old Forrest Mims books, so though hand-drawn would be ok. But now I am (slowly) reviewing each chapter and updating some of the diagrams and so on. However at the moment I don’t have enough time for everything I want to do! :)
      In the meanwhile if you have a question about anything published here don’t hesitate to ask me.
      cheers
      john

      Comment by John Boxall | January 26, 2011 | Reply

  6. Dear John

    Your idea of following the Getting Started with Arduino book is great.This way I can learn in depth at the same time there is no repetition of stuff.

    Comment by wowmir | March 28, 2011 | Reply

    • Yes, it is a good book, and gives something back to Massimo Banzi and the Arduino team.
      Plus I didn’t see any sense in re-inventing the wheel.
      Have fun!
      cheers
      john

      Comment by John Boxall | March 28, 2011 | Reply

  7. hello, i’m using the ADH8066 GSM Module and i would like to ask if there is any help with that module ? and can i work with the Arduino with that they of module ?

    Comment by Abdullah Al Abbas | May 5, 2011 | Reply

  8. Where do the voltage values you are reading come from?

    Comment by Sander | June 17, 2011 | Reply

    • A separate variable power supply

      Comment by John Boxall | June 18, 2011 | Reply

      • Oh, ok. Thanks for the quick reply! :D

        Comment by Sander | June 20, 2011

      • No worries

        Comment by John Boxall | June 20, 2011

  9. i want to know about PWM pin function??

    Comment by hemu | August 5, 2011 | Reply

    • See chapter one, example 1.2
      john

      Comment by John Boxall | August 5, 2011 | Reply

  10. John,

    Fun to read this. Yet, all the videos have no sound so far.

    Comment by jin | September 22, 2011 | Reply

    • Thanks. I don’t put sound in the videos.

      Comment by John Boxall | September 22, 2011 | Reply

  11. Why does the red section of the RGB led need a 150ohm resistor and the others only need a 50ohm?

    Comment by John Wood | December 3, 2011 | Reply

    • At the time of writing the RGB LED used required such values. If in doubt use higher values or check the data sheet of your LED to determine the required current for each colour. Then use this http://led.linear1.org/1led.wiz to determine the correct resistor to use.

      Comment by John Boxall | December 4, 2011 | Reply

  12. Great Work John..Keep it up….

    Comment by Nadsa | December 13, 2011 | Reply

  13. Hi, John!

    I went ahead and wired my board up pretty much as the diagram shows, without the 10k Resistor on the input. It seemed to work fine, and the two voltage divider resistors just happened to be exactly the same value, so I skipped doing the fine tuning… it’s still not exact, but I’m sure that neither my DVM nor my Power Supply are exact, either.

    Anyway, I used a somewhat different approach to the coding, and instead of a series of if/else statements, I used the map() function to divide the value from the input pin into values from 0 to 10 (actually 11, but the map() function won’t ever return the highest number). Then I used the returned values to index an array corresponding to the output pins, with a 0-index handled so that all the LEDs are off.

    My code for this is copied below (just the setup() and void loop() parts)…

    void setup() {
    for (int i=0; i<10; i++) {
    pinMode(ledPin[i],OUTPUT);
    digitalWrite (ledPin[i], LOW);
    }; // end of for
    pinMode(inVolt, INPUT);
    } // End of Setup

    // now for the main loop…

    void loop() {
    inVal = analogRead(inVolt); // we read the input voltage on pin A0
    newLedIndex = map(inVal, -51,1079,0,11);

    /* since newLedVal is used as an array index to show which LED to light
    I have to map the reading of the input pin into 11 values that correspond
    to the respective LED lamps. Because of integer math, the map function
    will never return the value "11", so returned values are from 0 to 10.
    I still have to deal with a slight mismatch between this set of 11 indices
    and an array that has only 10 elements.
    */

    if (newLedIndex != oldLedIndex) {
    digitalWrite (ledPin [oldLedIndex - 1], LOW);
    // subtracting 1 from the oldLedIndex corrects the mismatch between the index and
    // number of pins to be lit.
    if (newLedIndex == 0) {
    ;// do nothing, as we've already written the previous oldLedIndex pin to LOW
    // and by handling the event of the index being zero, we avoid having to
    // deal with a negative array index in the following else statement

    } else {
    digitalWrite (ledPin [newLedIndex - 1], HIGH);
    }} //end of else and end of "if (newLedIndex != oldLedIndex)"

    oldLedIndex = newLedIndex; // resets the index comparison

    } // end of the void loop

    Anyway, that's how I approached it, and the code turned out reasonably small, about 1.4k. However, I'm sure there are other approaches that could be even more efficient.

    Comment by DaveK | December 31, 2011 | Reply

    • Hi David
      Thanks for your input. Apologies for not replying to your comments sooner, I am currently between houses so a little pressed for time. Good to see you working things out though.
      Happy New Year
      John

      Comment by John Boxall | December 31, 2011 | Reply

  14. Hi John ,
    First thanks for your tutorials it’s awesome ..
    second I’m beginner at microcontroller and i’ve bought ARDUINO UNO kit … i want to know the difference between the analog and the digital inputs !??? thanks

    Comment by Billy Kamil | February 1, 2012 | Reply

    • Digital inputs read either ‘high’ (~5V) or ‘low’ (~0V), whereas analogue inputs read varying voltages between 0 and 5V between 1024 steps. See chapter one.

      Comment by John Boxall | February 1, 2012 | Reply

  15. Hi John ,
    can i connect my arduino uno to an android phone to control through it or i’ve to get another arduino kit to be done !??
    thanks

    Comment by Billy Kamil | February 5, 2012 | Reply

  16. Hi John, thanks for your tutorials.
    I am a real beginner with Arduino and Processing :) . I’m designing a structure that will reacts to the changes of wind and I’m finding myself a bit stuck right now. I’m trying to connect the wind sensor so that when air is blown, it will generate a sort of output, even just lit an LED. Do you have any idea where can I find more help on the topic? Codes and schematics? Deadline is getting close and any help will be a great help! Thanks.

    Comment by Fabio | February 12, 2012 | Reply

  17. Hi John! i’m not exactly new to electronics but I am indeed new to Arduino and I find it fascinating to be able to easily program things through this, also with the help of your tutorials. But I don’t seem to get something. How does dividing 1024 into 10 parts translate to having to measure 1 volt per part, say 0-102 is equal to 1 volt? what if its 20 volts? will it also be dividing 1024 to 20 parts and like 0-60 is 1 volt?

    Comment by Alvin | February 15, 2012 | Reply

    • Hello
      The measured voltage is halved using the voltage divider (the two resistors) which allows us to measure only up to 10V instead of the normal 5V possible by an Arduino’s analogue input pin.

      Comment by John Boxall | February 16, 2012 | Reply

  18. hi…..i made a led cube and want to give it as a gift to my friend….for this i can’t give the cube as arduino attached because its cost me more…so what should i do? is there any way that i can program the atmega chip in my board and then remove it and attache to the cube using some circuit?

    Comment by srideep nayak | March 4, 2012 | Reply

  19. hi John !!
    pls give me a code to generate 20Khz pwm pulse using arduino uno

    Comment by Saleem Basha | March 30, 2012 | Reply

    • Start here – http://arduino.cc/en/Reference/AnalogWrite

      Comment by John Boxall | March 31, 2012 | Reply

      • yeah i have seen this article .
        and i am able to generate pulse, but its only 500hz.
        but my requirement is 20khz.

        Actually my project is to drive a DC drive in four quadrant system(motoring,breaking,regenerative mode and regenerative breaking ).

        i am using mosfet(IRF540) as a switch. to which i have to generate 20khz pwm pulse..

        wat is the code…?? to get it.

        thanking you…….Mr JOHN.

        Comment by Saleem Basha | March 31, 2012

      • You will need to use an external function generator circuit with an Arduino, or use a MCU that is a lot faster.

        Comment by John Boxall | March 31, 2012

  20. Mr John,
    i am using arduino uno (atmega328p) board,
    by changing the timer register can get higher frequency pwm pulsese, ??

    becoz (o/p frequency)= 16Mhz/(N*256);
    i guess we have to change th prescalar value N; in our normal code,

    so, i guess there is a scope to generate 20khz pwm pulses using arduino only,

    now i am facing prblm how to update tat timer in ma code,

    thanking john !!

    Comment by Saleem Basha | March 31, 2012 | Reply

    • Possibly, however you may need to program in raw assembler, C etc and not use the Arduino IDE/bootloader system. At this point your question is outside the scope of my experience.

      Comment by John Boxall | March 31, 2012 | Reply

  21. thank u Mr John..:) for ur kindly reply’s !!
    i love ur blog …
    keep rocking !!

    btw i got my answer in the below link.

    http://arduino.cc/playground/Code/PwmFrequency

    Comment by Saleem Basha | April 1, 2012 | Reply

  22. I am trying to use the multi colored diode mentioned above.

    I can’t get it to light up. The single colored diodes work fine.

    The kit came with three clear diodes (not diffused).

    I am using pin 12 from the Arduino Uno Board and then going into a resistor (orange orange brown silver?) – 328 ohms (reading on ohm meter at 2000)

    I then go to the short pin (at the end) next to the long pin. Then the long pin to ground.

    Any ideas or suggestions?

    Comment by Jon Gel | April 2, 2012 | Reply

    • One more thing, when I tried testing the diode with the multi-meter it lit up.

      Comment by Jon Gel | April 2, 2012 | Reply

      • Yes, a multimeter on diode test function sends a small current through the diode.

        Comment by John Boxall | April 2, 2012

    • Arduino Uno digital pin to resistor to long LED pin – short LED pin to GND.
      have fun
      John

      Comment by John Boxall | April 2, 2012 | Reply

  23. Thank you. Starting to get there, but still having trouble.

    1. Short pin – blue
    2. medium pin green
    3. longest pin – common
    4. short pin – red

    The diode lights blue when I put the digital pin 12 to a resistor and then the longest pin and connect the short pin to the ground

    The diode lights green when I put the ground to the medium pin 2.

    The diode lights red when when I put the ground to the short pin 4.

    What I don’t understand is how to wire it. I would think that the longest pin should be the ground so that I would be able to chose where to put the current to generate the color. What am I missing?

    I appreciate your help!!!

    Comment by Jon Gel | April 2, 2012 | Reply

    • Oh sorry, in your previous question I thought you were asking about single LEDs. Ok for your RGB the long lead goes to ground, and the others connect to digital outputs via the resistors.

      Comment by John Boxall | April 2, 2012 | Reply

      • still having trouble.

        With the RGB, It works if the power goes to the long pin and then changes color if I move the ground to the other three pins based on the color of the pin. If I put the long lead to ground and the red pin to the digital pin 12, it doesn’t light up. What am I doing wrong?

        Thank you for your quick responses.

        Comment by Jon Gel | April 2, 2012

      • Sounds like you have a common-anode RGB LED. You’ll need a common-cathode one.

        Comment by John Boxall | April 2, 2012


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 2,588 other followers