Arduino Workshop, Part 3

Today’s Lesson was about the IF :lol: – ELSE :sad: command. The physical example we used for that was:IF you turn a potentiometer underneath a certain vale, make the LED blink. To keep things easy we used pin 13which has a resistor built in to let the LED blink. I wanted to make things a bot more spicy and also make use of the ELSE IF and ELSE command, so i decided to make a wiring wiith a second LED on pin 12 that work like that: If the value received from the potentiometer is below 100 let LED1 blink, if it’s between 100 and 300 let LED2 blink, if the value is above 300 switch both LED’s constantly on.

Today Code:

//analog in

int analogvalue = 0;
int ledPin1 = 13; //declares pin 11 and 12
int ledPin2 = 12;

void setup()

Serial.begin(9600); //sends the value to the serial monitor
pinMode(ledPin1, OUTPUT); //set pin as output
pinMode(ledPin2, OUTPUT);

void loop()

analogvalue = analogRead(0); // the varialble “analogvalue” equals the analog value read on pin ADC
Serial.println(analogvalue); // print the “value” to the serial monitor
delay(250); // pause 250 millisec before looping

digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);

if (analogvalue < 100) // if value is less then 150 blin kled 1 once
digitalWrite(ledPin1, HIGH); //turns LED1 on
digitalWrite(ledPin1, LOW); //turns LED1 on

else if (analogvalue > 100 && analogvalue < 600)
digitalWrite(ledPin2, HIGH); //turns LED2 on
digitalWrite(ledPin2, LOW); //turns LED3 on

digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);


pictures will follow..

0 Responses to “Arduino Workshop, Part 3”

  • No Comments

Leave a Reply

You must be logged in to post a comment.

Recent Tweets

Creative Commons License