Instructions

www.joy-it.net
Pascalstr. 8 47506 Neukirchen-Vluyn
In this experiment we will read the analog value of the potentiometer and
assign the value to the PWM port, so that a corresponding change in the
brightness of the LED can be observed. We will also display the analog
value on the screen.
int potpin = 0; // Initialises analog Pin 0
int ledpin = 11; // Initialises digital Pin 11 (PWM Output)
int val = 0; // Saves the Sensors Value
void setup() {
pinMode(ledpin,OUTPUT); // defines digital Pin 11 to Output
Serial.begin(9600); // Sets Baudrate to 9600
}
void loop() {
val = analogRead(potpin);
// reads the Analog-Value of the sensor and assigns it to Val
Serial.println(val); // shows the value of Val
analogWrite(ledpin,val/4);
// turns on the LED and sets the brightness (Max. Value: 255)
delay(10); // Waits 0,01 Seconds
}
Aer transmission of the program and when moving the potentiometer,
we can observe changes in the displayed values. We can also see an
obvious change in LED brightness.
Lesson 4: Traic lights
In the previous program we did the flashing LED experiment with only
one LED. Now it is time to do a more complicated experiment: Traic
lights.
Actually these two experiments are very similar. In this experiment we
will use 3 LEDs with dierent colors, while in the last one only one LED
was used. We need for this:
1x
Mega2560 board
1x
USB cable
1x
Red M5 LED
1x
Yellow M5 LED