Our Blog, Here you will find robot and Robot parts.Start build your robot from here.

 

Arduino Tutorial for Beginner

The Arduino website offers free resources and tutorials as well as a language reference to help you understand the code and syntax. In order to get started, you will at the very minimum need an Arduino board. Note that all the Arduino (and most of the clone boards) can use the Arduino software. If you are unsure what hardware to get, the Arduino USB is currently the most popular model

Windows Connection and Setup

Hardware: none

  1. Go to www.arduino.cc to download the latest version of the Arduino software (Direct link:http://arduino.cc/en/Main/Software and select your operating system; in this case we are using Windows)
  2. Save the ZIP file to your desktop (you can move or delete it later)
  3. Create a new folder called “Arduino” under “Program Files”. To do this, go to “My computer” -> “C:” (or the drive where the operating system is installed) -> “Program Files”, then left click once on “program Files” folder, then select “New”->”Folder” from the main Explorer menu.
  4. Extract the entire ZIP folder to this new “Arduino” folder
  5. To run the Arduino software, open Windows Explorer by pressing the windows key (usually between the Ctrl and Alt keys on your keyboard) and the ‘E’ character at the same time (there are other ways to access explorer as well).
  6. Go to “My computer” -> “C:” (or the drive where the operating system is installed) -> “Program Files” -> “Arduino” In this folder you will see an executable file (Blue colored icon), you can left click (once) and then right click and select “send to” -> Desktop (create shortcut) to have Arduino more easily accessible.
  7. Double click the icon to start the software. The Arduino Software is ready to use.
(more…)
 

Arduino Servo Control

In this Project, we want to control servo motor potitions from analog sensor ( potentiometer or flex sensor ).
The Hardware

As shown at picture, connect analog input to Arduino analog pin 0. don’t forget about 10K resistor. Connect an Servo motor ( yellow wire ) to Arduino Digital pin 2 and then connect the red and black wires go to +5V and ground, respectively. Refer to the picture and scheme to do this.
The Program
Here we will use 2 method to control an servo motor.
   1.   Pulse Method
This method is more complex and exposes the math and timing required to control a servo with a microcontroller.

/*  Servo control from an analog input

 The minimum (minPulse) and maxiumum (maxPulse) values will be different depending on your specific servo motor. Ideally, it should be between 1 and 2 milliseconds, but in practice, 0.5 - 2.5 milliseconds works well for me. Try different values to see what numbers are best for you.

 This program uses the millis() function to keep track of when the servo was last pulsed.  millis() produces an overflow error (i.e. generates a number that's too big to fit in a long variable) after about 5 days. if you're making a program that has to run for more than 5 days, you may need to account for this.

 by Tom Igoe additions by Carlyn Maw & Rob Faludi Created 28 Jan. 2006 Updated 10 Jun. 2008 */

 int servoPin = 2;     // Control pin for servo motor int minPulse = 500;   // Minimum servo position int maxPulse = 2500;  // Maximum servo position int pulse = 0;        // Amount to pulse the servo

 long lastPulse = 0;    // the time in milliseconds of the last pulse int refreshTime = 20; // the time needed in between pulses

 int analogValue = 0;  // the value returned from the analog sensor int analogPin = 0;    // the analog pin that the sensor's on

 void setup() {  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin  pulse = minPulse;           // Set the motor position value to the minimum  Serial.begin(9600); }

 void loop() {  analogValue = analogRead(analogPin);      // read the analog input  pulse = map(analogValue,0,1023,minPulse,maxPulse);// convert the analog value                                                    // to a range between minPulse                                                    // and maxPulse.  // pulse the servo again if rhe refresh time (20 ms) have passed:  if (millis() - lastPulse >= refreshTime) {    digitalWrite(servoPin, HIGH);   // Turn the motor on    delayMicroseconds(pulse);       // Length of the pulse sets the motor position    digitalWrite(servoPin, LOW);    // Turn the motor off    lastPulse = millis();           // save the time of the last pulse  } }

This code was written with a potentiometer in mind, so it assumes you're going to get values from 0 to 1023 from the sensor. If you don't, the servo won't move through its whole range. Determine the range of numbers the sensor is giving you and adjust the servo formula to fit. To fix this, use the map() function. You know the input range is the range of the sensor, 0 to 1023. And you know the output range is from minPulse to maxPulse. So do this: pulseWidth = map(analogValue, 0, 1023, minPulse, maxPulse); 
   2.  Using the Arduino Servo Library
The second example shows you how to control a servo motor using the Arduino Servo library. This library is very easy to use and is much easier to follow. However, it obscures all the calculations and handles the dirty work for you. This is useful once you've attempted the pulse method and understand it completely.

/* Servo control from an analog input using the Arduino Servo library This example code uses the Arduino Servo library which comes packaged with the Ar duino software. In order to make this work, you must include the Servo.h library file, create an  instance of the Servo object.  attach a pin to the Servo object, and then write an analog value to the Servo obj ect to set its position. The difference between using the Servo library and the older method of pulsing a  digital pin is that the library handles a lot of the work for you. You no longer need to figure out the translati on between pulse length and position.  You now can simply specify the angle you'd like your servo to be at and it will t urn to that position.

 Updated 08 Sep 2009 by Rory Nugent Created 20 Jan 2009 by Tom Igoe */

 #include <Servo.h>      // include the servo library Servo servoMotor;       // creates an instance of the servo object to control a servo int analogPin = 0;      // the analog pin that the sensor is on int analogValue = 0;    // the value returned from the analog sensor int servoPin = 2;       // Control pin for servo motor. As of Arduino 0017, can be any pin void setup() {    servoMotor.attach(servoPin);  // attaches the servo on pin 2 to the servo object }  void loop()  {    analogValue = analogRead(analogPin);             // read the analog input (value between 0 and 1023)   analogValue = map(analogValue, 0, 1023, 0, 179); // map the analog value (0 - 1023) to the angle of the servo (0 - 179)   servoMotor.write(analogValue);                   // write the new mapped analog value to set the position of the servo   delay(15);                                       // waits for the servo to get there  }



Source: http://itp.nyu.edu/physcomp/Labs/Servo
 

Write from Arduino to LCD

 Scheme Description:
  • Connect the LCD RS pin to the Arduino pin 12
  • Connect the LCD enable pin to the Arduino pin 11 
  • Connect the LCD D4 to D7 pins into pin 5 to 2 Arduino
  • Connect the LCD +5 and ground to pin +5 V and ground Arduino
  • Connect the pin to a potentiometer LCD Vo. Use of this potentiometer is to adjust the LCD contrast
In this Project, we will write ” Hello World ” from arduino to LCD

Program Arduino:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// LCD Demo Program
// Use LCD library
#include "LiquidCrystal.h";
// LCD initialization & use pin
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  // Set the numbers of LCD columns and rows
  lcd.begin(16, 2);
  // Make the writing on the LCD
  lcd.print("hello, world!");
}
void loop() {
  // Set cursor to Column 0 & Row 1
  // Note: Column & Row starting with 0
  lcd.setCursor(0, 1);
  // Print the number of seconds since last reset
  lcd.print(millis()/1000);
}

 

Temperature Sensor Using Arduino and LM35

LM35 is a temperature sensor from National Semiconductor that have a high accuracy. The output of analog voltage and has a measurement range of -55 º C to +150 º C with an accuracy of ± 0.5 º C. Output voltage is 10mV / º C. Output ports can be directly connected to Arduino, because Arduino has 6 ADC ports (analog input).


Analog inputs on the Arduino has a 10-bit resolution, which can provide output 2 ^ 10 = 1024 discrete values. When used 5V supply, the resulting resolution is 5000mV/1024 = 4.8mV. Because the LM35 has a resolution output of 10mV / º C, then the resolution of the thermometer are made with Arduino is 10mV/4.8mV ~ 0.5 º C.

So, let make a simple temperature sensor with Arduino and LM35. After we connect the LM35 with the Arduino as in the picture above, we can start write the program.


01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
// variable declare
float tempC;
int tempPin = 0;
void setup()
{
    Serial.begin(9600); // Open serial port, set baud rate 9600 bps
}
void loop()
{
    tempC = analogRead(tempPin);           // Read data from sensor
    tempC = (5.0 * tempC * 100.0)/1024.0;  // convert from analog to temperature
    Serial.println((int)tempC,DEC);        // send data via serial
    delay(1000);                           // delay
}

This program will read temperature data from LM35 and conversion the analog data to digital and write it to PC in celcius through Serial port.

 
                                                                                                

Sponsors

Categories:

Archives:

 
top