Arnov Sharma
Published © CC BY

Dimmable MOSFET LAMP

Learn how to create a Dimmable LED lamp with and without a microcontroller.

BeginnerProtip9 minutes3,266
Dimmable MOSFET LAMP

Things used in this project

Story

Read more

Code

Untitled file

C/C++
int potPin= A0;  //Declare potPin to be analog pin A0
int MOSFET= 3;  // Declare LEDPin to be arduino pin 9
int readValue;  // Use this variable to read Potentiometer
int writeValue; // Use this variable for writing to LED
 
void setup() {
  pinMode(potPin, INPUT);  //set potPin to be an input
  pinMode(MOSFET, OUTPUT); //set LEDPin to be an OUTPUT
  Serial.begin(9600);      // turn on Serial Port
}
 
void loop() {
  
 readValue = analogRead(potPin);  //Read the voltage on the Potentiometer
 writeValue = (255./1023.) * readValue; //Calculate Write Value for LED
 analogWrite(MOSFET, writeValue);      //Write to the LED
 Serial.print("You are writing a value of ");  //for debugging print your values
 Serial.println(writeValue);
 
}

Credits

Arnov Sharma
343 projects • 349 followers
I'm Arnov. I build, design, and experiment with tech—3D printing, PCB design, and retro consoles are my jam.
Contact

Comments

Please log in or sign up to comment.