mortenbs.com

Arduino

Shown 103 times
Arduino source code examples, Arduino projects and circuits, robotic projects and more. Use the Arduino to control electronics from your PC. With simple programming the Arduino device can also be programmed and disconnected from the PC, while it is doing its task. It is easy to use the Arduino.

Home \ Robotics \ Arduino

An Arduino board is used to control electronics from a PC.
With simple programming the Arduino can be programmed and unhooked from the computer, while doing it's task.
It is also possible to control an Arduino directly from a computer through USB-cable.

With an Arduino it's easy...

...to turn things on/off, reading sensors, controlling motors and more.

Digital pins to turn things on/off, or to read an on/off state
PWM pins to use for analog purpose, and to communicate with PWM equipment.
Analog inputs to read potentiometers or sensors etc.

Digital pins

Digital pins is managed by boolean data type (true/false) or (HIGH/LOW).
A digital output pin gives 5 volt DC when true, and 0 volt DC when false.
A digital input pin is given ~3-5 volt DC to be true, and given 0 volt DC to be false.

PWM pins

PWM pins is managed by integer data type (timing).
A PWM pin is used for remote control, motor control, servo motors and more.

Analog input pins

Analog inputs is read as a byte data type.
An analog input is used for potentiometers, sensors and more.

PWM and digital pins is initialized to be an input or an output.
To protect the Arduino, all input pins should be given only 5 volt from the device itself.
If inputs is given above 5 volt it may damage the device.
Also if and output pin is connected to ground, the pin may be destroyed.

Connecting a potentiometer to the Arduino

The outer pins is connected to ground and 5 volt DC.
The middle pin is the analog out.


Potentiometer analog input, LEDS digital output

//Potentiometer analog input, LEDS digital output 

void setup(){
 for(byte b=0;b<=12;b++){pinMode(b,OUTPUT);}
}

int curPin;
int sensorValue;
int pauseMs;

void loop(){
 sensorValue=analogRead(1);
 pauseMs=4+(sensorValue/10);
 curPin=curPin+1;if(curPin>13){curPin=0;};
 digitalWrite(curPin,HIGH);delay(pauseMs*2);
 digitalWrite(curPin,LOW);//delay(pauseMs);




Various scripts for Arduino


Serial monitor, Analog-inputs

//SERIAL MONITOR ALL SIX ANALOG INPUTS

void setup(){                
 Serial.begin(9600);
}

void loop(){
 Serial.print("0=");Serial.print(analogRead(0));Serial.print(", ");
 Serial.print("1=");Serial.print(analogRead(1));Serial.print(", ");
 Serial.print("2=");Serial.print(analogRead(2));Serial.print(", ");
 Serial.print("3=");Serial.print(analogRead(3));Serial.print(", ");
 Serial.print("4=");Serial.print(analogRead(4));Serial.print(", ");
 Serial.print("5=");Serial.print(analogRead(5));Serial.println(".");
 delay(100);




Test PWM-outputs

//TEST PWM OUTOUTS

void setup(){                
 pinMode(3,OUTPUT);
 pinMode(5,OUTPUT);
 pinMode(6,OUTPUT);
 pinMode(9,OUTPUT);
 pinMode(10,OUTPUT);
 pinMode(11,OUTPUT);
}

byte n=0;

void loop(){
 n=n+1;if(n>255){n=0;}
 analogWrite(3,n);
 analogWrite(5,n);
 analogWrite(6,n);
 analogWrite(9,n);
 analogWrite(10,n);
 analogWrite(11,n);
 delay(10);




Test Servo-outputs

//TEST SERVO OUTPUTS

#include <Servo.h> 

Servo servo5;//servo on PIN 5
Servo servo6;//servo on PIN 6
byte aValue=0;

void setup(){
 servo5.attach(5);
 servo6.attach(6);
}

void loop(){
 aValue=aValue+1;if(aValue>180){aValue=0;}  
 servo5.write(aValue);
 servo6.write(aValue);
 delay(30);
}  




Related pages

1 Robotics  (10) 

Other pages in Robotics

1 Robotic vehicle, 24 VDC, 2x400W 22A motors  A year ago
2 Old 7v robotic vehicle  A year ago
3 Transistor 
4 Small circuits 
5 Resistor 
6 Robotic vehicles by B. Laursen  Four years ago
7 LPT relay-board circuits  Four years ago
8 DC Motor Control 

No content



Copyright 2008-2014, mbsnet.dk, All Rights Reserved. Loaded in 0.12 sec.