Basics of arduino
Arduino is vary famous microcontroller. vary easy to control it
here is codes which i use in videos.
for digital input output....
/*
* simple digital input output test code
*
* ER BROS
*
* https://www.youtube.com/channel/UCY6KA8oFk1s36fyPiFEmedQ
*
* http://erbros1.blogspot.com/?m=1
*/
int val; // create a variable
void setup() {
pinMode(13, OUTPUT); // define 13 number pin as output
pinMode(8, INPUT); // define 8 number pin as input
digitalWrite(13, LOW); // make 13 number pin by default low
}
void loop() {
val = digitalRead(8); // this function will chack either HIGH or LOW
if(val == HIGH) { // use if esle statment
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
}
for analog inputs
/*
* simple digital input output test code
*
* ER BROS
*
* https://www.youtube.com/channel/UCY6KA8oFk1s36fyPiFEmedQ
*
* http://erbros1.blogspot.com/?m=1
*/
int val;
void setup() {
pinMode(A0, INPUT);
pinMode(9, OUTPUT); // must use pwm pin
Serial.begin(9600);
// put your setup code here, to run once:
}
void loop() {
val = analogRead(A0);
analogWrite(9, val/4);// here 0-1013 convert into 0-255 value
Serial.println(val);
// put your main code here, to run repeatedly:
}
here is codes which i use in videos.
for digital input output....
/*
* simple digital input output test code
*
* ER BROS
*
* https://www.youtube.com/channel/UCY6KA8oFk1s36fyPiFEmedQ
*
* http://erbros1.blogspot.com/?m=1
*/
int val; // create a variable
void setup() {
pinMode(13, OUTPUT); // define 13 number pin as output
pinMode(8, INPUT); // define 8 number pin as input
digitalWrite(13, LOW); // make 13 number pin by default low
}
void loop() {
val = digitalRead(8); // this function will chack either HIGH or LOW
if(val == HIGH) { // use if esle statment
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
}
for analog inputs
/*
* simple digital input output test code
*
* ER BROS
*
* https://www.youtube.com/channel/UCY6KA8oFk1s36fyPiFEmedQ
*
* http://erbros1.blogspot.com/?m=1
*/
int val;
void setup() {
pinMode(A0, INPUT);
pinMode(9, OUTPUT); // must use pwm pin
Serial.begin(9600);
// put your setup code here, to run once:
}
void loop() {
val = analogRead(A0);
analogWrite(9, val/4);// here 0-1013 convert into 0-255 value
Serial.println(val);
// put your main code here, to run repeatedly:
}
Comments
Post a Comment