ARDUINO PROGRAMMING
Hello guys, welcome back to my blog. This time, new adventures await, as I bring you guys through my new adventure called Arduino Programming.
Well, if you guys are not wondering what Arduino Programming is, then you must know your coding really well. For those still wondering what Arduino Programming is, dont worry, this blog will make you understand what Arduino Programming is.
I will be explaining about the 4 tasks that was carried out in great details, for you guys to have a further understanding.
Input devices: Interface a potentiometer analog input to maker UNO board and measure/show its signal in serial monitor Arduino IDE.
1)Below are the code/program I have used and the explanation of the code.
|
|
int ledPin = 13; int sensorValue = 0; void setup() { Serial.begin(9600); pinMode(ledPin,OUTPUT); } void loop() { int sensorVal = digitalRead(2);
Serial.println(sensorVal); sensorValue = analogRead(sensorPin); digitalWrite(ledPin, HIGH); delay(sensorValue); digitalWrite(ledPin, LOW); delay(sensorValue); } |
int sensorPin = A0; means that the potentiometer is connected to analog pin 0. int ledPin = 13; means that the LED is connected to digital pin 13. int sensorValue = 0; declares another integer variable to store the value of the potentiometer. void setup() is where you set up the board's pin identity. Serial.begin(9600); establishes serial communication between your Arduino board and another device.This tells the Arduino to get ready to exchange messages with the Serial Monitor at a data rate of 9600 bits per second. pinMode(ledPin,OUTPUT); means that pin 13 is the output. void loop() means that the code runs on a loop. int sensorVal = digitalRead(2); means that it reads the input of pin 2 and writes into a integer variable, sensorVal. Serial.println(sensorVal); means it displays the value of sensorVal if the analog is pressed. sensorValue = analogRead(sensorPin); means the value is read from the analog pin, A0. digitalWrite(ledPin, HIGH); means pin 13 is set to 1, making pin 13 HIGH, causing it to ON. delay(sensorValue); a delay of 0 milliseconds. digitalWrite(ledPin, LOW); means pin 13 is set to 0, making pin 13 LOW, causing it to OFF. delay(sensorValue); a delay of 0 milliseconds. |
2. Below are the hyperlink to the sources/reference that I used to write the code/program.
3. Below are the problems I have encountered and how I fixed them.
4. Below is the short video as the evidence that the code/program work.
Input devices: Interface a LDR to maker UNO board and measure/show its signal in serial monitor Arduino IDE:
|
|
int LDR = A0; int ledPin = 13; int LDRvalue = 0 void setup() { Serial.begin(9600); pinMode(ledPin,OUTPUT); } void loop() { int sensorVal = digitalRead(13); Serial.println(sensorVal); LDRvalue = analogRead(LDR); if(LDRvalue > 600) digitalWrite(ledPin, HIGH); else digitalWrite(ledPin, LOW); |
int LDR = A0; means that the LDR is connected to analog pin 0 int ledPin = 13; refers to digital pin 13 int LDRvalue = 0; declares another integer variable to store the value of the LDR void setup() is where you set up the board's pin identity. Serial.begin(9600); establishes serial communication between your Arduino board and another device.This tells the Arduino to get ready to exchange messages with the Serial Monitor at a data rate of 9600 bits per second. pinMode(ledPin,OUTPUT); means that pin 13 is the output. void loop() means that the code runs on a loop. int sensorVal = digitalRead(13); means that it reads the input of pin 13 and writes into a integer variable, sensorVal. Serial.println(sensorVal); means it displays the value of sensorVal if it is pressed. LDRvalue = analogRead(LDR); refers to reading the voltage analog value through the A0 pin of the Arduino. This analog Voltage will be increased or decreased according to the resistance of LDR. if(LDRvalue > 600) means that LDR valye digitalWrite(ledPin, HIGH); means pin 13 is set to 1, making pin 13 HIGH, causing the LDR to ON. else digitalWrite(ledPin, LOW); means pin 13 is set to 0, making pin 13 LOW, causing the LDR to OFF. |
2.Below are the hyperlink to the sources/references that I used to write the code/program.
3.Below are the problems I have encountered and how I fixed them.
4.Below is the short video as the evidence that the code/program work.
Output devices: Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc)
1.Below are the code/program I have used and the explanation of the code.
|
|
void setup() { pinMode(8,OUTPUT); pinMode(12,OUTPUT); pinMode(13,OUTPUT); } void loop() { digitalWrite(8,HIGH); delay(1000); digitalWrite(8,LOW); delay(1000); digitalWrite(12,HIGH); delay(1000); digitalWrite(12,LOW); delay(1000); digitalWrite(13,HIGH); delay(1000); digitalWrite(13,LOW); delay(1000); } |
void setup() is where you set up the board's pin identity. pinMode(8,OUTPUT); means that pin 8 is set as an output. pinMode(12,OUTPUT); means that pin 12 is set as an output. pinMode(13,OUTPUT); means that pin 13 is set as an output. void loop() means that the code runs on a loop. digitalWrite(8,HIGH); increases pin 8 to 1, meaning HIGH, turning on the LED. delay(1000); means there is a delay of 1 second. digitalWrite(8,LOW); decreases pin 8 to 0, meaning LOW, turning off the LED. delay(1000); means there is a delay of 1 second. digitalWrite(12,HIGH); increases pin 12 to 1, meaning HIGH, turning on the LED. delay(1000); means there is a delay of 1 second. digitalWrite(12,LOW); decreases pin 12 to 0, meaning LOW, turning off the LED. delay(1000); means there is a delay of 1 second. digitalWrite(13,HIGH); increases pin 13 to 1, meaning HIGH, turning on the LED. delay(1000); means there is a delay of 1 second. digitalWrite(13,LOW); decreases pin 13 to 0, meaning LOW, turning off the LED. delay(1000); means there is a delay of 1 second. |
2.Below are the hyperlink to the sources/references that I used to write the code/program.
3.Below are the problems I have encountered and how I fixed them.
4.Below is the short video as the evidence that the code/program work.
Output devices: Include pushbutton to start/stop the previous task
1.Below are the code/program I have used and the explanation of the code.
|
|
void setup() {
pinMode(8, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); pinMode(2,INPUT_PULLUP);
}
void loop() { byte buttonstate = digitalRead(2); if (buttonstate == LOW){ digitalWrite(8, HIGH); delay(1000); digitalWrite(8, LOW); delay(1000); digitalWrite(12, HIGH); delay(1000); digitalWrite(12, LOW); delay(1000); digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } else{ digitalWrite(8,LOW); digitalWrite(12,LOW); digitalWrite(13,LOW); } } |
void setup() is where you set up the board's pin identity. pinMode(8, OUTPUT); means that pin 8 is set as the output. pinMode(12, OUTPUT); means that pin 12 is set as the output. pinMode(13, OUTPUT); means that pin 13 is set as the output. pinMode(2,INPUT_PULLUP); This is where we declare that PIN 2 is an INPUT and enable the internal pull up resistor. So, by default, PIN2 status will always be HIGH. void loop() means that the code runs on a loop. byte buttonstate = digitalRead(2); This variable stores the current digital state of the button while it reads from a specific digital PIN, PIN2. if (buttonstate == LOW) means the button is released. digitalWrite(8, HIGH); increases pin 8 to 1, meaning HIGH, turning on the LED. delay(1000); means there is a delay of 1 second. digitalWrite(8, LOW); decreases pin 8 to 0, meaning LOW, turning off the LED. delay(1000); means there is a delay of 1 second. digitalWrite(12, HIGH); increases pin 12 to 1, meaning HIGH, turning on the LED. delay(1000); means there is a delay of 1 second. digitalWrite(12, LOW); decreases pin 12 to 0, meaning LOW, turning off the LED. delay(1000); means there is a delay of 1 second. digitalWrite(13, HIGH); increases pin 13 to 1, meaning HIGH, turning on the LED. delay(1000); means there is a delay of 1 second. digitalWrite(13, LOW); increases pin 13 to 0, meaning LOW, turning off the LED. delay(1000); means there is a delay of 1 second. digitalWrite(8,LOW); decreases pin 8 to 0, meaning LOW, turning off the LED. digitalWrite(12,LOW); decreases pin 12 to 0, meaning LOW, turning off the LED. digitalWrite(13,LOW); decreases pin 13 to 0, meaning LOW, turning off the LED. |
Comments
Post a Comment