BLOG > Tutorial Series for Arduino: It begins.

This video was featured on the Adafruit Blog on 01/06/11
This tutorial was featured on the official Arduino blog on 3/9/2011
This video was featured on the DIYFilm Blog on 03/19/11

Arduino UnoThanks to a generous sponsorship from element14, I’m putting together a tutorial series on using the arduino microcontroller platform!  The arduino is a platform that I’ve done several projects with, and I think it is the best possible way for beginners to get acquainted with electronics.  This tutorial series will be aimed at beginner users, but I’m hoping to keep it going with some more advanced topics a few episodes into the future.    This first episode will get you acquainted with the arduino uno (the current “flagship” arduino), introduce the programming language, and help you get your first program running!


You can download the files associated with this episode here:

GNU GPL License Distributed under the GNU General Public (Open-Source) License.

Please Attribute and Share-Alike.


Arduino Project Contest!  Start getting your projects together!

Start thinking about your arduino projects, because element14 will be sponsoring a contest where you can win a prize if your arduino project gets the most votes.  More info coming soon!

129 comments

  1. Just as the comments in the program indicate, the tutorial is AWESOME as well. Long-time user of microcontrollers, just found the Arduino and have way too many things i want to do with it. Thanks for taking the time to start on a great series of videos describing a great idea! Thanks Jeremy – Keep On ECE’ing!

      1. I’m a newbie here i enjoy your tutorial hope i can learn a lot from you please give me some recommendation on how do i start

  2. hi,
    good job man.
    i’m new on arduino and i’m askink if this tutorials can work with arduino adk (with android)?

    thanks.

      1. I was refered to your arduino tutorials by my Dutch robotics friend, Niek Blankers. He told me he used your tute’s when he was first learning arduino, and he highly reccommended them to me. Thus far I am most impressed with your presentations. I have been trying to self-teach myself for about the last 3 months. Your efforts have offered me a great deal. It gives one hope about our society because of caring and giving people like yourself.
        FYI: I am 64 y.o. I live in central Florida. I’ve been interested in robotics for about a year now. I recently suffered a second stroke, but am more determined now to learn and use robotics as an aid; to myself, and perhaps to others with disabilities. My current work is centered on a microcontroller developed by Mr. D.J. Sures ( from EZ-Robot.com) that does not require programming skills. You should visit the web site and see what he has developed. I am , however; wanting to learn how to program the arduino. It will offer me more alternatives for robot development.
        Warmest regards,
        Lloyd

        1. Loyd,
          I’m 20 and am as new to this tech stuff as you are. My goal right now (though lofty with my given skillset) is to create a bionic hand like those that amputees have begun to use with crazy controllability*.

          Wish you the best with your health and all…
          It’d be AWESOME if you could start touring florida to speak to people about how to prevent strokes. you might give someone an additional decade of life with your knowledge!

          jR

  3. I got something wrong here. I run my arduino program on ubuntu 11.10, and when i try to upload your tutorial’s program to arduino board, it says:

    In file included from /usr/lib/gcc/avr/4.5.3/../../../avr/include/util/delay.h:44:0,
    from /usr/lib/gcc/avr/4.5.3/../../../avr/include/avr/delay.h:37,
    from /home/arttu/programs/arduino/arduino-0022/hardware/arduino/cores/arduino/wiring_private.h:30,
    from /home/arttu/programs/arduino/arduino-0022/hardware/arduino/cores/arduino/WInterrupts.c:34:
    /usr/lib/gcc/avr/4.5.3/../../../avr/include/math.h:426:15: error: expected identifier or �(� before �double�
    /usr/lib/gcc/avr/4.5.3/../../../avr/include/math.h:426:15: error: expected �)� before �>=� token

    Help me??? :(

    1. Ok i got it, there is something wrong with the ubuntu things or some files in the system. I’m not very good with linux but i found the answer in here:

      http://groups.google.com/group/linux.debian.bugs.dist/browse_thread/thread/f44eb01346f9c22c

      How did i fix it?

      I searched my system for a file called wiring.h . I have no idea what it is, but i opened it with a text editor, and took one line away inside the file by writing // before it. In the other words, i made the line into a comment, so the system skips it. It seems that there is some error on the syntax of that line.

      in the file called
      wiring.h

      The line is:
      #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))

      i changed the line to:
      //#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))

      Now everything just works! Dont ask me why :)

      Hope that the nerds who are responsible for maintaining this file, can fix the problem in the future…

  4. Hey Jeremy,
    great stuff so much so that I wish I had been an electrical engineering major. I’m 29 now, got excited about this. I seriously convinced my godmother to get me an arduino for christmas because of these tutorials. hope you don’t stop posting stuff after you graduate… but then life calls so won’t blame you either way.

    1. Hi Sherif,
      I’m a Mech.E who dabbled in electronics (and aero, and ballistics and boat stuff, etc, you know how it is) – but still ended up working as a semiconductor applications engineer, giving microcontroller training courses by the time I was 35. There’s a chip or so from TI that has my name on it too. So don’t give up!
      There are so many more resources out there today, not least the Arduino.
      If you want to bring your existing training to an electronics career, it’ll be a bonus.
      And vice versa, too – some of my friends have been bringing electronics to the arts.
      I’m retired now, been retired most of this century, and boy, is it ever fun playing with Arduinos.
      Go for it!

  5. Great tutorials you have made!!
    I am curious on the RC servo code.
    How can you get the servo to go with smaller steps than 1 degree steps?
    Best regards and happy new year from Karl

  6. Hi, Jeremy
    I am completely new to the ARDUINO, and electronics indeed…
    I have some ideas on how to work with it for some home projects.
    My major concern, based on the sample projects I have seen in the internet, is that 100% of the times the items involved in the projects are packed very close together.
    Is it possible to use sensors (temperature, angle/potentiometers, gas, distance, etc.) far from the ARDUINO board? how far? could you please make some comments/ideas to work in the range of 50m, with different sensor types? the signal loss, resistance of cables effects, etc..
    Thank you

    1. I wouldn’t recommend using traditional means if you want to put sensors to far away. Use twisted-pair cables like ethernet, and maybe consider using a differential protocol like RS-485. You could also consider placing the sensors remotely and transmitting data wirelessly with an XBee.

      1. Thanks Jeremy.
        I understand it may be difficult to cover different types of sensors in a single answer. I had already the idea of using CAT5 cables for cost and interference tolerance. I think it will be a matter of experimenting a little bit. One of my ideas it to use potentiometers (angle) to monitor water reservoirs levels as well as temperature sensors for the the same reservoirs (backyard and house roof). If you have any sample projects in which you used such sensors or even other with a long distance from Arduino, it would be nice to know more about it. Thanks again,

          1. hello sir is it possible to make a line following robot using arduino uno????

          2. Posting the same question repeatedly with more question marks each time is not necessary. Yes, you can make a line following robot with the arduino. Google it – there are lots of examples.

  7. Hi there,

    im becoming a fan of your ECE stuff. Obviously its helpful, it amaze and encourage me to do that stuff also. unfortunately i’m not that knowledgeable on electronics, and i just started trying this early this year. im an Information technology student, and therefore we are expected to produced systems. just like home automation or security system and i admit it will have to use a device. unaware of what device to use, make me depend on the net and search for something. luckily, it ended up, with the Arduino. my hope for developing my projects has become broader thanks to your tutorials and arduino. i’ve already seen several of your tutorials, but after watching i always agonizing on a same problem – i dont know what specifications of the materials you used, like the wires and resistors, etc, because when i try to buy it from the store they offer me several types and, i dont know what particular wire or resistor or LED, etc to buy. i have an arduino uno R3 and my PC is running on w7. Im not an ECE dude but im willing to try to be one. thanks a lot men. more power and support. Hope you can address my issue.

  8. Hi Jeremy

    Excellent and well explained Arduino tutorial, your heads and tails above the other ‘geeks’ when it comes to making these things constructive and easy to understand!!

    However, whilst I appreciate you’ve provided a parts list for each episode, it seems a bit dispersed, some on your site, some on element 14.

    Could you provide one list of all the parts used and the link to the appropriate page to avoid hunting around? Thanks.

    All the best buddy.

  9. Thanks for the great tutorials Jeremy,

    As a 42 year old geek, new to Arduino but absolutely fascinated with it, I find your video’s easy well explained and easy to understand. Kepp up the great work.

    JohnB

  10. Very good job thank you. I’m new user of the arduino and I studied all the tutorial and have helped me immensely.

  11. Hello Jeremy

    I saw video that you upload and i like it, thank you for all of the information it was very interesting and helpfull its leave me with couple of questions about arduino’s abilities. i have history with microchip microcontroller (PIC family) and their products (mplab icd2) but i am not interesting to build the circuit and also it seems that the arduino makes the work much easier and for that i want to ask :
    1)i want to connect the arduino 2 communecation modules (RFID,GSM) and for that i need to define band rate,priority ,frame in the serial communication ,i saw in video number 5 that you upload that you define just the band rate (9600) with arduino’s command,so can i define all of the serial parameters?
    2)can the arduino run a code without to be connected to the computer,i mean can you burn the code on the chip with vertify it ?
    3)do the arduino have a clock function?

    Thanks
    Tomer Yahav

  12. Jeremy Blum.
    hi
    i can enable serial communication. without connected usb to arduino mega. i want use serial1 port

    help me

  13. Jeremy your videos are awwwwwsssommmee… i love your utube videos…. but am not that great with knowing what goes where when it comes to the wiring … am kinda like monkey see monkey do …. could you give me instructions or pictures on how to do the gps in video # 9… again … your videos are awwwwssssssssoooommmmeeeee .. subscribed and liked ………

    1. Hi, I do not reply to comments like this. If you need help, you have to try it yourself first, then ask for help with a specific problem. Writing in all caps and demanding that I write code is not the right way to ask somebody for assistance.

  14. i will start to watch your videos about arduino cause i don’t know any thing about it
    but i need your advice (i will make robotic arm and want to use robotic arm in control so will it be good ??? and if you can help me by giving me good sites and links help me in that and thanks
    i saw first video and it’s awesome and i think i will learn more from you :)

    i hope you add me on facebook i think it will be good than here plz
    [email protected]

  15. Hi Jeremy

    I was wondering if you could help me with a little project I am working on. I have two 125att panels on the roof of my boat which I would like to tilt to follow the sun. For the past year I have been doing this manually at intervals during the day when im at the boat.
    I have looked into automated tracking systems but they are quite expensive, and then I discovered the arduino and the many fantastic tasks/projects people have used them for. My plan is to mount two small 6v panels on the side of one of my existing panel frames and then use the arduino to identify if the position of my panel could be improved by either angling upwards or downwards.
    The reason for me using the 6v panels as sensors instead of ldr’s is because I’m planning on using them to charge a battery pack that powers the arduino and servos, also I believe the panels will give me increased accuracy as they will be tracking the suns uv rays not just light levels. I am fairly good at mechanics and electrics but am additively very stumped by the code I will need for my arduino project.
    Here is a list of things I’m trying to get the arduino to do.

    * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    EQUIPMENT I WAS PLANNINF TO USE. !!!
    * ARDUINO UNO. – Unless you can recommend a more power efficient arduino
    * TWO SERVOS – one for each of my solar panel assemblies
    * TWO 6V 200ma SOLAR PANALS – one angled upwards one downwards to identify the best direction of travel to track the sun vertically.

    WHAT I AM TRYING TO GET MY ARDUINO TO DO. !!!

    1* The range of the servos should be no greater than 90deg so that’s 45degs in either direction when the servos are in there middle position.
    – (watching your tutorial no5 I have been to replicate the sort of range of travel I require by allowing my servos to travel between 45 and 135)
    2* The time between movements and voltage readings should be about every 10 minutes.
    3* If (TopPanel1) has the same voltage as (BottomPanel2) within a tolerance of 0.2volts then the servos should not move.
    4* If (TopPanel1) has a greater voltage than (BottomPanel2) outside a tolerance of 0.2volts then the servos should move 2deg cw.
    5* If (TopPanel1) has a lesser voltage than (BottomPanel2) outside a tolerance of 0.2volts then the servos should move 2deg ccw.
    6* If either of the panels don’t read a value greater than 1&1/2 volts the servos should return to its rest/home position (90deg/middle).
    – once resting in the home position is it possible to put the arduino in sleep mode or something so it uses less power, until either of the panels read a voltage greater than 1&1/2 volts – in which case the above loop would apply.

    Also if possible
    * When the arduino gets powered up would it be able to do a one off action outside of the above loop.
    – Where after a small pause, about 5 seconds – (just enough time to get clear of the panel). The same actions as (above 3*,4* and 5*) are taken but without the 10 minute intervals. – Instead 5 second intervals and a total of 20 or 30 moves before going to the above loop..
    As this would save the unit from spending an hour or so first locating the sun.

    CONNECTIONS & OIN ASSIGNMENTS. !!!

    PIN 9 = SERVO1
    PIN 10 = SERVO2
    PIN ? = TOPSPANEL1 (I’m not sure how to wire the panels, does the positive just got to an input pin)
    PIN ? = BOTTOMPANEL2 (I’m not sure how to wire the panels, does the positive just got to an input pin)

    * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    I would be grateful of any advice or input you might have on my project.

    Many thank

    Emma

    1. Emma-

      This project is very doable. Essentially, you just need to run a bunch of analogReads() in a loop to get panel voltage and adjust servos accordingly. Your servos will have to be geared, or very strong to moved solar panels, but that’s another story. I’d recommend mounting an accelerometer to the panels so you don’t have to dead-rekon their orientation. You should checkout my heliowatcher project if you haven’t already – http://www.heliowatcher.com.

      1. hi Jeremy, Ive checked out the heliowatcher and was impressed. I have already made a start on my project. Ive managed to meet all of the requirements I determined, If you have the time could you identify any mistakes or problems you might see.

        my code:
        * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
        #include

        int TopSolar = 1; //L0000 – Top Sensor Pin
        int BottomSolar = 5; //L0010 – Bottom Sensor Pin
        int ServoOut = 9; //L0020 – Servo pin9
        //L0030 –
        int TopSolReading = 0; //L0040 – Top Sensor Value
        int BottomSolReading = 0; //L0050 – Bottom Sensor Value
        //L0060 –
        int Tolerence = 70; //L0070 – Tolerence Range Value of 100 is about 0.5 VOLT TOLERENCE – So each panel can be 1Volt different
        int MinimumSolRead = 300; //L0080 – When Both Panels Together Are Making Less Than 1.5V Averaged, Tracking Stops And Instead Panel Returns To Home Position
        int RotationAng = 5; //L0090 – Degree Of Roation Taken Each Movement When Tracking
        int HomingAng = 5; //L0100 – Degree Of Roation Taken Each Movement When Returning To Home Position
        int TimeLong = 5000; //L0110 – Loop Delay Time – Continuous After Rapid
        int TimeShort = 500; //L0120 – Loop Delay Time – During Loop Start Rapid Mode
        int RapidCounter = 99; //L0125 – Loop Delay Period/Counter For Rapid Movements At Start Of Loop
        //L0130 –
        Servo myservo; //L0140 – The Servo object
        int pos = 90; //L0150 – pos to write out
        //L0160 –
        int BottomPos = 60; //L0170 – Bot pos min
        int TopPos = 120; //L0180 – Top pos max
        int HomePos = 90; //L0190 – Middle Pos Home
        //L0200 –
        float output = 90; //L0210 – Start output pos redefined in loop
        float HomingDir = 0; //L0220 – Start HomingDir pos redefined in loop
        float TravelTime = (TimeShort); //L0230 – Start TravelTime pos redefined in loop – Loop Delay Time – Will Be Either TimeLong or TimeShort
        void setup() //L0240 –
        { //L0250 –
        myservo.attach(ServoOut); //L0260 –
        //L0265 –
        delay(TimeShort); //L0270 –
        } //L0280 –
        //L0290 –
        void loop() //L0300 –
        { //L0310 –
        TopSolReading = analogRead(TopSolar); //L0320 –
        BottomSolReading = analogRead(BottomSolar); //L0340 –
        //L0350 –
        float RapidCountdown = (RapidCounter – 1); //L0360 –
        //L0370 –
        if (RapidCountdown 1) //L0430 –
        { //L0440 –
        TravelTime = TimeShort; //L0450 –
        } //L0460 –
        else //L0470 –
        { //L0475 –
        TravelTime = TimeLong; //L0480 –
        } //L0485 –
        //L0490 –
        float NewPosition = output + RotationDir(); //L0495 –
        delay(TravelTime); //L0500 –
        //L0505 –
        if (NewPosition > TopPos) //L0510 –
        { //L0515 –
        NewPosition = TopPos; //L0520 –
        } //L0525 –
        else //L0530 –
        { //L0535 –
        if (NewPosition HomePos) //L0595 –
        { //L0600 –
        HomingDir = -1; //L0605 –
        } //L0610 –
        else //L0620 –
        { //L0630 –
        if (output (BottomSolReading + Tolerence)) //L0780 –
        { //L0790 –
        return (RotationAng * -1); //L0800 –
        } //L0810 –
        else //L0820 –
        { //L0830 –
        if (TopSolReading (((TopSolReading + BottomSolReading) / 2) – Tolerence)) //L0900 –
        { //L0910 –
        return (HomingDir * HomingAng); //L0920 –
        } //L0930 –
        else //L0940 –
        { //L0950 –
        return (RotationAng * 0); //L0960 – No movement within tolerence and when both reading the same
        } //L0980 –
        } //L0990 –
        } //L1000 –
        }
        * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
        code in short form
        * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

        #include

        int TS = 1;
        int BS = 5;
        int SO = 9;

        int TR = 0;
        int BR = 0;

        int T = 70;
        int MR = 300;
        int RA = 5;
        int HA = 5;
        int TLg = 5000;
        int TSt = 500;
        int RC = 99;

        Servo myservo;
        int pos = 90;

        int MIN = 60;
        int MAX = 120;
        int HOME = 90;

        float output = 90;
        float HD = 0;
        float TT = (TSt);
        void setup()
        {
        myservo.attach(SO);

        delay(TSt);
        }

        void loop()
        {
        TR = analogRead(TS);
        BR = analogRead(BS);

        float RD = (RC – 1);

        if (RD 1)
        {
        TT = TSt;
        }
        else
        {
        TT = TLg;
        }

        float NP = output + DIR();
        delay(TT);

        if (NP > MAX)
        {
        NP = MAX;
        }
        else
        {
        if (NP HOME)
        {
        HD = -1;
        }
        else
        {
        if (output (BR + T))
        {
        return (RA * -1);
        }
        else
        {
        if (TR (((TR + BR) / 2) – T))
        {
        return (HD * HA);
        }
        else
        {
        return (RA * 0);
        }
        }
        }
        }

        * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

        It seems to work the way I intended.

        The only things I have to solve know are.
        -When the arduino/servo powers on for the first time it for some reason goes out of the range that I have defined. I guess it something all servos do. I dont know if to use a motor instead.
        -I also need to learn a bit more about ultracapacitors as I intend to use four in series to act as a buffer and powersource for my little project.

        It took me a whole day to work out, as its my first arduino program and I havn’t attempted making a program since I was at school doing qbasic or something.
        I’m very proud of myself, and looking forward to working on further arduino projects.

        Id like to thank you for replying to me and also introducing me via you tutorials to this fantastic product.

        Many thanks

        Emma

        1. If you’re going to ask someone to review all your code, you could ask for a PayPal link to pay for their time.

          Remember, you haven’t even specified what your project is supposed to do, and what goals you want to achieve.
          That makes it “how long in a piece of string” question.

          10 years since your post I can only assume you’ve either
          1/ found the answer
          2/ given up whatever project it was

          For anyone reading this I would suggest you ask Jeremy how much he will charge to review specific code.
          Otherwise, how can you expect him to decipher your code, and it’s intended purpose, for zero fee?

          Who knows, if approached in a polite manner, away from public forums, he may be inclined to consider it, and give a list of options, and payments, for specific services.

          I was a programmer for many years pre/post/Windows.
          My knowledge and expertise has been accumulated over years, and thousands of lines of code.
          I’m happy to point someone in the right direction, to find the solution for themselves, but beyond that is an expectation that my time and expertise is not worth paying for.

  16. sorry for some reason my codedump/paste didnt work out. My actual code looks nothink like that. I will send it via your contact page.

    thanks again

    emma

  17. Hi,
    Keep your good work up….Can you upload a tutorial on using ADC in arduino..I have been trying to do it with avr studio but there aren’t good tutorials online and in most cases the coding is not explained properly…..So please upload one….

  18. really thank you for your great effort ….. but do you know a way for learning the programming lang. for arduino

  19. Hi Jermy,

    I have a question about the debounce function you made in this tutorial.

    boolean debounce(boolean last)
    {
    boolean current = digitalRead(switchPin);
    if (last != current)
    {delay(5);
    current = digitalRead(switchPin);
    }
    return current;

    debounce is the name of the function?
    current is the output of the function?
    last is the input?

    so in this tutorial last will be changed out with lastButton and current will be replaced by currentButton when you use the function in the program?

    What does actual the return command do?

    thanks for any answer, regards Pelle

  20. HI, i’m having a problem. I have the Arduino Uno board, i folowed the instructions about the settings in Device Manager as you explained in your tutorial. I go to write my scetch and in the right bottom corner sais COM4 but when i go to load my programm to the arduino board it shows a message that COM4 is not found. I tried again and again, i reinstalled it several times but i have the same result.

  21. Sir, i have a problem regrading my weather station project i have written the code to log the data into a csv format using gobetwino software as follow.I need your help to modify the code so that I can log the output data to a txt or csv file so that the code automatically form a file for each day to save the data. I think to use Processing sktech but i cant able to write the code.Plz help me…….
    the code is..
    #define uint unsigned int
    #define ulong unsigned long

    #define PIN_ANEMOMETER 2 // Digital 2
    #define PIN_RAINGAUGE 3 // Digital 3
    #define PIN_VANE 5 // Analog 5

    // How often we want to calculate wind speed or direction
    #define MSECS_CALC_WIND_SPEED 10000
    #define MSECS_CALC_WIND_DIR 10000
    #define MSECS_CALC_RAIN_FALL 10000

    volatile int numRevsAnemometer = 0; // Incremented in the interrupt
    volatile int numDropsRainGauge = 0; // Incremented in the interrupt
    ulong nextCalcSpeed; // When we next calc the wind speed
    ulong nextCalcDir; // When we next calc the direction
    ulong nextCalcRain; // When we next calc the rain drop
    ulong time; // Millis() at each start of loop().

    // ADC readings:
    #define NUMDIRS 8
    ulong adc[NUMDIRS] = {26, 45, 77, 118, 161, 196, 220, 256};

    // These directions match 1-for-1 with the values in adc, but
    // will have to be adjusted as noted above. Modify ‘dirOffset’
    // to which direction is ‘away’ (it’s West here).
    char *strVals[NUMDIRS] = {“W”,”NW”,”N”,”SW”,”NE”,”S”,”SE”,”E”};
    byte dirOffset=0;

    //=======================================================
    //For Humidity sensor
    //=======================================================
    float humid,tempcel,tempfar,tempkel,dewp,dewpfst;
    float reqhumid,reqtempcel,reqtempfar,reqtempkel,reqdewp,reqdewpfst;
    float sumhumid=0;
    float sumtempcel=0;
    float sumtempfar=0;
    float sumtempkel=0;
    float sumdewp=0;
    float sumdewpfst=0;
    //Celsius to Fahrenheit conversion
    double Fahrenheit(double celsius)
    {
    return 1.8 * celsius + 32;
    }

    //Celsius to Kelvin conversion
    double Kelvin(double celsius)
    {
    return celsius + 273.15;
    }

    // dewPoint function NOAA
    // reference: http://wahiduddin.net/calc/density_algorithms.htm
    double dewPoint(double celsius, double humidity)
    {
    double A0= 373.15/(273.15 + celsius);
    double SUM = -7.90298 * (A0-1);
    SUM += 5.02808 * log10(A0);
    SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
    SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
    SUM += log10(1013.246);
    double VP = pow(10, SUM-3) * humidity;
    double T = log(VP/0.61078); // temp var
    return (241.88 * T) / (17.558-T);
    }

    // delta max = 0.6544 wrt dewPoint()
    // 5x faster than dewPoint()
    // reference: http://en.wikipedia.org/wiki/Dew_point
    double dewPointFast(double celsius, double humidity)
    {
    double a = 17.271;
    double b = 237.7;
    double temp = (a * celsius) / (b + celsius) + log(humidity/100);
    double Td = (b * temp) / (a – temp);
    return Td;
    }

    #include

    dht11 DHT11;

    #define DHT11PIN 6

    //=======================================================
    // Initialize
    //=======================================================
    void setup() {
    Serial.begin(9600);
    pinMode(PIN_ANEMOMETER, INPUT);
    digitalWrite(PIN_ANEMOMETER, HIGH);
    digitalWrite(PIN_RAINGAUGE, HIGH);
    attachInterrupt(0, countAnemometer, FALLING);
    attachInterrupt(1, countRainGauge, FALLING);
    nextCalcRain = millis() + MSECS_CALC_RAIN_FALL;
    nextCalcSpeed = millis() + MSECS_CALC_WIND_SPEED;
    nextCalcDir = millis() + MSECS_CALC_WIND_DIR;
    }

    //=======================================================
    // Main loop.
    //=======================================================
    void loop() {
    unsigned long currentMillis = millis();
    if(currentMillis – previoushumidMillis > intervalhumid) {
    previoushumidMillis = currentMillis;
    calcHumidity();}

    time = millis();

    if (time >= nextCalcSpeed) {
    calcWindSpeed();
    nextCalcSpeed = time + MSECS_CALC_WIND_SPEED;
    }
    if (time >= nextCalcDir) {
    calcWindDir();
    nextCalcDir = time + MSECS_CALC_WIND_DIR;
    }
    if (time >= nextCalcRain) {
    calcRainFall();
    nextCalcRain = time + MSECS_CALC_RAIN_FALL;
    }

    }

    //=======================================================
    // Interrupt handler for anemometer. Called each time the reed
    // switch triggers (one revolution).
    //=======================================================
    void countAnemometer() {
    numRevsAnemometer++;
    }

    //=======================================================
    // Interrupt handler for rain gauge. Called each time the reed
    // switch triggers (one drop).
    //=======================================================
    void countRainGauge() {
    numDropsRainGauge++;
    }

    //=======================================================
    // Find vane direction.
    //=======================================================
    void calcWindDir() {
    int val;
    byte x, reading;

    val = analogRead(PIN_VANE);
    val >>=2; // Shift to 255 range
    reading = val;

    // Look the reading up in directions table. Find the first value
    // that’s >= to what we got.
    for (x=0; x= reading)
    break;
    }
    //Serial.println(reading, DEC);
    x = (x + dirOffset) % 8; // Adjust for orientation
    Serial.print(” Dir: “);
    Serial.print(“#S|RAIN|[“);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(strVals[x]);
    Serial.print(“,”);
    Serial.println(“]#”);
    }

    //=======================================================
    // Calculate the wind speed, and display it (or log it, whatever).
    // 1 rev/sec = 1.492 mph = 2.40114125 kph
    //=======================================================
    void calcWindSpeed() {
    int x,y, iSpeed;
    // This will produce kph * 10
    // (didn’t calc right when done as one statement)
    long speed = 24011;
    speed *= numRevsAnemometer;
    speed /= MSECS_CALC_WIND_SPEED;
    iSpeed = speed; // Need this for formatting below

    Serial.print(“Wind speed: “);
    x = iSpeed / 10;
    Serial.print(‘.’);
    y = iSpeed % 10;
    Serial.print(“#S|RAIN|[“);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(itoa((x
    ),buffer,10));
    Serial.print(“,”);
    Serial.print(itoa((y
    ),buffer,10));
    Serial.print(“,”);
    Serial.println(“]#”);

    numRevsAnemometer = 0; // Reset counter
    }

    //=======================================================
    // Calculate the rain , and display it (or log it, whatever).
    // 1 bucket = 0.2794 mm
    //=======================================================
    void calcRainFall() {
    int a,b iVol;
    // This will produce mm * 10000
    // (didn’t calc right when done as one statement)
    long vol = 2794; // 0.2794 mm
    vol *= numDropsRainGauge;
    vol /= MSECS_CALC_RAIN_FALL;
    iVol = vol; // Need this for formatting below

    Serial.print(“Rain fall: “);
    a = iVol / 10000;
    Serial.print(‘.’);
    b = iVol % 10000;
    Serial.print(“#S|RAIN|[“);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(itoa((a
    ),buffer,10));
    Serial.print(“,”);
    Serial.print(itoa((b
    ),buffer,10));
    Serial.println(“]#”);

    numDropsRainGauge = 0; // Reset counter
    }

    void calcHumidity()
    {
    n=sensorValue;
    int chk = DHT11.read(DHT11PIN);
    humid=(float)DHT11.humidity, 6;
    tempcel=(float)DHT11.temperature, 6;
    tempfar=Fahrenheit(DHT11.temperature), 6;
    tempkel=Kelvin(DHT11.temperature),6;
    dewp=dewPoint(DHT11.temperature, DHT11.humidity);
    dewpfst=dewPointFast(DHT11.temperature, DHT11.humidity);
    Serial.print(“#S|RAIN|[“);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(“,”);
    Serial.print(itoa((humid
    ),buffer,10));
    Serial.print(“,”);
    Serial.print(itoa((tempcel
    ),buffer,10));
    Serial.print(“,”);
    Serial.print(itoa((tempfar
    ),buffer,10));
    Serial.print(“,”);
    Serial.print(itoa((tempkel
    ),buffer,10));
    Serial.print(“,”);
    Serial.print(itoa((dewp
    ),buffer,10));
    Serial.print(“,”);
    Serial.print(itoa((dewpfst
    ),buffer,10));
    Serial.print(“,”);
    Serial.println(“]#”);
    }
    //done

  22. Thank you so much for your tutorials. 3 down, and I plan to watch them all. I’m just getting back into component level electronics as a hobby and find this fascinating. You have a real talent for explaining these concepts in an easy to understand manner.

    I just ordered my first Arduino Uno from Ebay. Was that a mistake? I realized you have a sponsor, but from a purely technical point of view, is that a problem?

    Thanks again!
    Marc

  23. Thank you for your efforts. I like to do stuffs like interfacing harware with pc or real time applications. Practically I am new to microcontroller, but I hav a few theoretical background. So my doubt is: which Arduino board i hav to choose, and where could i get it from (purchasing). if any website links please do share.. Thanks again…

  24. First of all, i must congratulate you for this job, it is a great work helping people who want to try this, there are not to many tutorials on the net so explicit like yours . Now my question is very simple, i want to start learning programing but i do not know with what program to start C, C++, JAVA ? Please help me decide. Thank you and excuse my english.

  25. Thanks, Jeremy! Your tutorials are fantastic.

    I downloaded some of your sketches, but it unzips into a format my pc can’t open. Is there a way to open it in the Arduino program.

    I’m a total novice, so please forgive my ignorance.

    Thanks again!

  26. hi can any one help me with Multi-Function 4WD Arduino Robot Car Kit I cant find the code for it. arduino uno + arduino sensor shield v4.0 + pig hc-sr04 + keyes ir remote control + Arduino Line Hunting Sensor Module. can sum one help me please please

  27. thanks for your tutorials jeremy sir, really you have done great job..can you upload megaADK tutorials??
    (i just want to know how its communicate with android mobile)

  28. thank you for your tutorials sir, really you have done fantastic job..and please upload mega ADK tutorials
    (i want to know how mega ADK communicate with android phones)

  29. Hi Jeremy
    I’m a computer science student and I’m making a project with arduino
    I went trought all of your tutorials and I really need your help !!!
    I bought arduino UNO and wifi shield but couldn’t find how to make a light turn on using a wifi shield and arduino (went trough many tutorials but nothing works!)
    the shield I bought it this one:
    https://www.sparkfun.com/products/9954

    Thanks for your attention

  30. thanks so much jeremy, these tutorials are really helpful, especially for beginners because you explain why as well as how. good luck with your work.

  31. Pingback: Arduino Tutorial 02: Buttons, PWM, and Functions | Ayarafun
  32. Pingback: Must-See Beginner Tutorials For Arduino | dev.SquareCows.com
  33. Pingback: The Arduino Has Landed : DIYfilm
  34. Pingback: Arduino Introductory Course | t00bl1pp3
  35. Pingback: H4H Arduino Course Resources | House 4 Hack
  36. Pingback: Learn arduino - From noob to Ninja - video series

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisement