Tuesday, May 19, 2015

Controlling An LED Using a Potentiometer and An Arduino

Quick note: Sorry for the inconsistent uploads, just been very busy and also sick. I have decided to finalize the schedule so that I will post a new tutorial twice a week, One on Tuesdays and another on Thursdays. Once again sorry for that, anyways lets talk about our topic of the day which is, "Controlling An LED Using a Potentiometer and An Arduino." Now this tutorial is very similar to the one found in the Sunfounder tutorial manual.

Introduction: Today we will be looking at, how to control the brightness of an LED using a potentiometer and an Arduino board. To do this we need to know as a concept called pulse width modulation or PWM. Pulse width modulation (PWM) is essentially a type of digital signal. It has been used in many different applications from dimming an LED to motor control (where my int rests lie). On the Arduino, the digital controller creates a square wave, a signal that switches on and of. This allows the user to regulate the voltage being delivered to the circuit by the Arduino, where on is 5V and off is 0V. You can read more about is on the Arduino PWN tutorial website: http://www.arduino.cc/en/Tutorial/PWM

Equipment:
  •  An Arduino
  • A Potentiometer
  • 4 Jumper wires
  • A 230 Ohm resistor
  • An LED


Procedure:
  1. Set up the circuit as shown
Sample Code:
/******************************************/
const int analogPin = A0;//the analog input pin attach to
const int ledPin = 9;//the led attach to

int inputValue = 0;//variable to store the value coming from sensor
int outputValue = 0;//variable to store the output value
/******************************************/
void setup()
{
}
/******************************************/
void loop()
{
  inputValue = analogRead(analogPin);//read the value from the sensor
  outputValue = map(inputValue,0,1023,0,255);//Convert from 0-1023 proportional to the number of a number of from 0 to 255
  analogWrite(ledPin,outputValue);//turn the led on depend on the output value
}
/*******************************************/
Here is a video of it working:
Thanks for reading and have a great day.

Sunday, May 10, 2015

Control 3 LEDs with a Button and an Arduino


Introduction: The Arduino Uno R3 contains 13 digital pins and these pins can be configured to be   input or output pins. This will be useful in tutorial as we will be using both modes of the pins to turn on and off  3 LEDs with the use of a simple button.

Equipment:
  • Arduino UNO
  • A USB Type A male to B male Printer Cable
  • 6 Breadboard Jumper Wires
  • 3 LEDs
  • 3 230 Ohms Resistors
  • 1 1k Ohm Resistor
  • A Breadboard

Procedure:
  1. Place 3 LEDS on the breadboard, parallel to each other. *Remember to connect the shorter end of the LED to the ground
  2. Connect 3 230 Ohm resistors in series with the LEDs 
  3. Connect 3 jumper wires in series from the resistors to the pins labeled 9, 4 and 3 on the Arduino
  4. Place the button on the breadboard, so that the pins on the button are on each side of the split on the breadboard and connect one jumper wire from one pin on the button to the pin labeled 12 on the Arduino
  5. Connect one  end of a 1k Ohm resistor to the same pin the is connect to the pin 12 on the Arduino and the second end to the ground
  6. Connect a jumper cable to the other half of the button to the 5v pin on the Arduino
  7. Lastly connect one end of the usb cable to the Arduino and the other to the computer
Your final product should look a little like this:



    Now comes the Coding part of the project, Here is the Sample code:

    //Turn 3 Led one after the other with a push of a button
    /**************************/
    //Declaring the pins that will be used
    const int buttonPin = 12; 
    const int ledPin1 = 9, ledPin2 = 6, ledPin3 = 3;
    /**************************/
    void setup() {
      pinMode(buttonPin,INPUT); //set the pin to be of input type
      pinMode(ledPin1,OUTPUT); //set the pin to be of output type
      pinMode(ledPin2,OUTPUT);
      pinMode(ledPin3,OUTPUT);
    }

    void loop() 
      {
      //read the state of the key value
      //and check if the button is pressed
      //if it is,the state is HIGH, which means button is pressed 
      if(digitalRead(buttonPin) ==HIGH )
      {
        digitalWrite(ledPin1,HIGH);//turn on the led
        delay(150);        
        digitalWrite(ledPin2,HIGH);
        delay(150);         
        digitalWrite(ledPin3,HIGH);
        delay(150);       
      }
      else
      {
        delay(150);  
        digitalWrite(ledPin1,LOW);//turn off the led
        delay(150);  
        digitalWrite(ledPin2,LOW);
        delay(150);  
        digitalWrite(ledPin3,LOW);
      }
    }

    Here is a short clip of it in action:
    And there u have it our first tutorial, let me know how i did and if I have to change something, feedback is always welcome, anyways take care and happy reading.

    Monday, May 4, 2015

    The Arduino and Sunfounder Kit

    The Arduino, simply put, is a micro-controller board that takes various digital and analog inputs and produces various digital and analog outputs. It is very useful for things such as driving motors, using sensors, etc.
    The Arduino is very popular among hobbyists and do-it-yourselvers because of the huge community that surrounds it as well as the abundance of  tutorials and information regarding using the Arduino and other boards/software together.
    You can learn about the Arduino on there website: http://www.arduino.cc/. They have amazing tutorials as well as cool projects if ever need inspiration. The Arduino also comes with its own IDE which you would have to download on their website, although the compiler converts the code into C++ and send that to the board. Knowing this most experienced programmers tend to code in C++ as it is more powerful and versatile than the Arduino IDE. Personally I prefer the Arduino IDE due to the fact that is has a simple UI as well as built in example. I am however trying to learn how to code in C++ so that in the future I will be able to code the Arduino in C++.

    As a beginner Arduino user, and electronics enthusiast, I did not know much about the Arduino and also did not have a lot of parts that I could use with Arduino, thus I decided to buy myself a

    This kit gave all the parts that I would ever need to build simple circuits, and learn how to use the Arduino. The kit also includes a dvd and book that teaches you how to build different circuits with the components give and is a great way to get into learning how to use the Arduino board.
    I've been using this kit for about a couple weeks now and I'm in love with it. The book and dvd are my go to guide if I have a problem or need inspiration I would refer to those 2 items.

    This was just a brief overview of what I currently use for my projects, and i will be releasing my first tutorial this Thursday. Be sure to check that out. Remember, feed back is always appreciated. Thanks for reading and have a wonderful day.