Technoon Tutorials
Arduino MicroController


Written by Rajesh V

Preface

Arduino is an open-source electronics platform that can acknowledge and interact with its environment through a variety of sensor types. It’s great for hardware prototyping and one-off projects. Arduino is a tool for making computers that can sense and control more of the physical world than your desktop computer. There are many other microcontrollers and microcontroller platforms available for physical computing. Arduino stands top of those platforms. More details can be found in arduino.cc.

PIN configuration in Ardunio Leonardo

MicrocontrollerATmega32u4
Operating Voltage5V
Input Voltage (recommended)7-12V
Input Voltage (limits)6-20V
Digital I/O Pins20
PWM Channels7
Analog Input Channels12
DC Current per I/O Pin40 mA
DC Current for 3.3V Pin50 mA
Flash Memory32 KB (ATmega32u4) of which 4 KB used by bootloader
SRAM2.5 KB (ATmega32u4)
EEPROM1 KB (ATmega32u4)
Clock Speed16 MHz


How to program an Arduino ?

Arduino provides an software to write a sketch (software program using wiring language) and burn into the flash memory of the microcontroller board. There are quite few examples prepackaged in the sketch editor under the examples menu.


Using these program sketches, variety of sensors can be controlled and the output from these sensors can also be read.


Reading a value from the Potentiometer (POT)

Let's see how can the output value from a potentiometer can be read and logged into serial monitor. Required Accessories: Arduino Uno / Leonardo, 10K POT, Bread board, 220 ohm resistor & Jumper wires

Step 1: Connect the Arduino board to the computer thru USB 

Step 2: Connect the potentiometer to the bread board. Pot has 3 pins, ground, 
power & output. Connect the ground pin to Arduino's ground pin, power pin to 
5V pin using 220 ohm resistor and output pin to the analog pin 2

Step 3: Write a program sketch as below and upload it to Arduino board through USB

Step 4: Open the serial monitor from the menu and you will see the output values
coming in from the POT.  Turn the pot knob to get different readings.


Note: Using this incoming value from the POT, you can control the brightness of an LED or reduce the rotation speed of a DC motor or control the direction of a SERVO motor. Options are plenty.

Example code

/*
  Reads an analog input on pin 2, prints the result to the serial monitor.
*/
// the setup routine runs once when you press reset:
void setup() { 
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 2:
  int sensorValue = analogRead(A2);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);
}


Happy Coding !