29 December 2015

Arduino Quiz

Just some basic quiz to practice your programming skills using the Arduino development board.


Quiz 1:
Press the button on pin 2 once. Five seconds later the LED on pin 13 will be on, two seconds after the LED 13 will be goes off automatically. Show the value of seconds in serial monitor

Quiz 2:
Adjust the brightness of the first LED on pin 11 by using the analog input A0. If the brightness reaches 80%, the second LED on pin 13 will be on, if the brightness below 80%, the second LED will return goes off. Show the LED brightness levels in percent using a serial monitor

Equipment you need:
- 1 button
- 1 variable resistor
- 1 LED
- 1 resistor (for limiting LED current)
- 1 project board
- 5 jumper




Answer 1:

void setup() {
    pinMode(2, INPUT_PULLUP);
    Serial.begin(9600);
    pinMode(13, OUTPUT);
    Serial.println("Tekan tombol untuk memulai");
}

void loop() {

int sensorVal = digitalRead(2);
if (sensorVal == LOW) {
  delay(1000);
  Serial.println("satu");
  delay(1000);
  Serial.println("dua");
  delay(1000);
  Serial.println("tiga");
  delay(1000);
  Serial.println("empat");
  delay(1000);
  Serial.println("lima");
    digitalWrite(13, HIGH);
  delay(2000);
  digitalWrite(13, LOW);
  }
}


Answer 2:

int sensorValue;
int sensorValue1;

void setup() {
    Serial.begin(9600);
    pinMode(11, OUTPUT);
    pinMode(13, OUTPUT);
}

void loop() {
sensorValue = analogRead(A0);
sensorValue1 = map(sensorValue,0,1023,0,255);
analogWrite(11, sensorValue1);
    if (sensorValue>800){
          digitalWrite(13, HIGH);
          }
    else{
          digitalWrite(13, LOW);
          }
Serial.println(sensorValue);
}


It is your job to add some script in Answer 2 so the value in percent can appear, Easy huh? :D

No comments:

Post a Comment