Pulsating Lamp using Arduino

Posted by Unknown on Friday, July 04, 2014 with No comments
In this project we will alter the brightness of the LED, and make a pulsating lamp, using the analogWrite() function.

Parts Required

Table 3-3lists the parts required for Project 7. We simply use an LED and resistor.










Connect It Up

The circuit for this project is simply a green LED connecting, via a current-limiting resistor, between ground and Digital Pin 11.



Enter the Code

Open up your Arduino IDE and type in the code .

int ledPin = 11;
float sinVal;
int ledVal;
void setup()
 {
pinMode(ledPin, OUTPUT);
}
void loop() {
for (int x=0; x<180; x++)
 {
// convert degrees to radians then obtain sin value
sinVal = (sin(x*(3.1412/180)));
ledVal = int(sinVal*255);
analogWrite(ledPin, ledVal);
delay(25);
}
}

Verify and upload. You will now see your LED pulsate on and off steadily. Instead of a simple on/off state, we are now adjusting its brightness.
Categories: