Friday, March 16, 2018

Working with Arduino

Image result for arduino
          Arduinos is a single board micro-controller that functions as a miniature computer. They can be used for many things, including turning on and off lights in a precise manner, as well as working with sensors. In this post, I will give a brief introduction to Arduinos and how to use them.
Image result for arduino wire         Arduinos need to be plugged into a computer to receive code, however they can run the code on their own if connected to a power source. They should be connected to the computer through a standard USB wire attached to the Arduino by the black box in the lower left corner of the image to the right.

          There are two main uses for the Arduino: output and input. Output is when the Arduino supplies power to something else, such as an LED light or a motor. Input is when the Arduino takes in information, such as from buttons or levers.
           To use an Arduino with a computer, first you need to install a chrome add on that can be found here. This allows you computer to interact with the Arduino.
          Code with Arduino is done is three parts. First, variables are defined outside of any functions at the beginning. Then, put anything you want to run once at the beginning of the program in the 'setup' function. Lastly, put anything you want to run continuously is the 'loop' function.
          A good starting point for working with Arduinos is to turn a light on and off. This requires coding with the Arduino. Arduino uses a modified version of C++. First, go to this site to code. Next, you will need to create a variable to define what port the light is in. This is done with the code 'int led = 13;'
          Next, you will need to define the pin as output, which is what tells it to power the light. This is done with the code 'pinMode(led, OUTPUT);'
          Finally, now that everything is set up, we need to turn the light on and off. To turn the light on, we turn the power to 'high'. This is done with the code 'digitalWrite(led, HIGH)' to turn the light off, we do the same thing as before, but replacing 'high' with 'low', like so: 'digitalWrite(led, LOW');'
          This should turn the lights on and off, however Arduinos do not have a built in delay, so the light will turn on, and then immediately turn itself off. To stop this, we will manually add a delay. This is done with the code 'delay(1000);' This will tell the Arduino to wait for 1000 milliseconds, or one second.
          This is a brief tutorial on how to use an Arduino computer. Arduinos are extremely versatile, and can do many impressive and interesting things. Though, previous knowledge of coding certainly helps, it is possible to learn along the way and achieve great things with Arduino.

No comments: