Edu-Right, learn about electrical electronics, space science, and science fact. We provide the Right Education and Develop technical Skills only on Edu-Right

Full width home advertisement

Science Fact

Electrical&Electronics

Space Science

Post Page Advertisement [Top]

How to do Basic Arduino Programming 

Edu-Right

Arduino is an Open Source electronic prototyping platform based on flexible easy to use hardware and software..... Read More

Basic of Arduino Programming

  1. setup:  It is called only when the Arduino is powered on or reset. It is used to initialize variables and pin modes.
  2.  loop:  The loop functions run continuously until the device is powered off. The main logic of the code goes here. Similar to while (1) for micro-controller programming.

Pin Mode Of Arduino

  1. A pin on Arduino can be set as input or output by using pinMode function.
  2. pinMode(13, OUTPUT); // sets pin 13 as output pin 
  3.  pinMode(13, INPUT); // sets pin 13 as input pin
  4. digitalWrite(13, LOW); // Makes the output voltage on pin 13, 0V 
  5.  digitalWrite(13, HIGH); // Makes the output voltage on pin 13, 5V 
  6.  int button state = digitalRead(2); // reads the value of pin 2 in button state

What are the Libraries?

Libraries are a collection of code that makes it easy for you to connect to a sensor, display, module, etc. For example, the built-in LiquidCrystal library makes it easy to talk to character LCD displays. There are hundreds of additional libraries available on the Internet for download.

How to use Normally led blink with Arduino Uno

Edu-Right
Buy Arduino Uno Amazon
you're an hour ready to make your first are to when a project we're going to a very simple project blinking and lead you don't really need you this project because the are do we know has a small and building but it helps to have one if you're using and you'll notice how one lead is longer than the other the longer lead is the positive and the shorter one in is the negative place to positive really didn't in thirteen on our to we and the many deathly into the can write all to G and the reason we use pen thirteen as because it has a building resist or so you don't need to had one the lead us in place connect the arduino to your computer and right this code noticed have some lines of the text have to slack is before it you don't need to write these days are gets out in the are do we know code anything with two slash because before it is a new this define text tells that are doing of that they and he isn't pen thirty this tax year avoid setup could genes all the code that tells the are do we know what to do before runs the program the only code within void set up its payload which tells the are do we actually use the one output below you will sign the void loop which contains all the code that the argue we now we'll drowned over and elvers code inside tells the arduino to turn on the lead weight one second turned off the lead weighed another second and then repeat remember to at the empty parentheses after and avoid set up and void loop and make here that you have the curvy brackets in the right place the number signed before define and the semi cool and after each line i've code within voice set up in loop you can also copy and pace the code from the box below once all of your code is entering click to verify done if any era show up in the box below check your code and compare it to the code below this the idea once the verification box only has this white text you're all set go ahead and click the upload but and your or do we now should be blinking away so congratulations you just made you first are do we know project move on to the next to media and things will get a little more interesting

Code for Led Blinking

#define led 13

void setup()
{
  pinMode(13,OUTPUT);
}


void loop()
{
  digitalWrite(led,HIGH); //led on
  delay(2000);
  digitalWrite(led,LOW);
  delay(2000);
  }


How to use an RGB LED with Arduino Mega

Edu-Right

What is RGB LED?

The RGB light-emitting diode will emit totally different colors by mixing the three basic colors red, inexperienced and blue. thus it truly consists of three separate LEDs red, inexperienced and blue packed in an exceedingly single case. That’s why it's four leads, one lead for every one of the three colors and one common cathode or anode looking on the RGB light-emitting diode sort. during this tutorial, I'll be employing a common cathode.
Edu-Right

The cathode is connected to the bottom and also the three anodes are connected through 220 Ohms resistors to three digital pins on the Arduino Board that may offer PWM signal. we are going to use PWM for simulating analog output which can offer totally different voltage levels to the LEDs thus we will get the required colors. 
We will use PWM for simulating analog output which can offer totally different voltage levels to the LEDs thus we will get the required colors.
Now let’s see the Arduino sketch. I'll use the pins range seven, six and five and that I can name them red Pin, green Pin, and blue Pin. within the setup section, we want to outline them as outputs. At the all-time low of the sketch, we have got this tradition created to perform named setColor() that takes three totally different arguments red price, inexperienced price, and blue price. These arguments represent the brightness of the LEDs or the duty cycle of the PWM signal that is made exploitation the analogWrite() perform. These values will vary from zero to 255 which represents a 100% duty cycle of the PWM signal or most light-emitting diode brightness.
Edu-Right

Arduino Mega code for RGB LED

int redPin= 7;
int green in = 6;
int blue pin = 5;
void setup() 
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}
void loop() 
{
  setColor(255, 0, 0); // Red Color
  delay(1000);
  setColor(0, 255, 0); // Green Color
  delay(1000);
  setColor(0, 0, 255); // Blue Color
  delay(1000);
  setColor(255, 255, 255); // White Color
  delay(1000);
  setColor(170, 0, 255); // Purple Color
  delay(1000);
}
void setColor(int redValue, int greenValue, int blueValue) {
  analogWrite(redpin, redValue);
  analogWrite(greenPin, greenValue);
  analogWrite(bluePin, blueValue);
}
So currently within the loop perform, we are going to create our program which can modify the color of the light-emitting diode every second. to urge the red light-weight on the light-emitting diode, we are going to decide the setColor() perform and set the worth of 255 for the worth argument and zero for the 2 others. severally we will get the 2 different basic colors, inexperienced and blue. For obtaining different colors we want to combine the values of the arguments. thus for instance, if we set all three LEDs to most brightness we get the White color we will get a purple color if we set the subsequent values to the arguments: a hundred and seventy redValue, zero inexperienced price, and 255 blue prices. Here’s the demonstration of the sketch.

No comments:

Post a Comment

Thank You!!

Bottom Ad [Post Page]

| Designed by Colorlib