Control relay with TIP120

Control Omron G5LE-1 relay that requires 12V to switch the relay on and off. The relay it self is turning a 220VAC circuit on and off.

Using a potentiometer to control LED

You can easly control the current running through your LED by adding a potentiometer as part of your circuit.

To control the LED with Arduino programming you attach the potentiometer to your analog in and let your Arduino program decide how much to dim the LED depending on the input you get from the potentiometer.

The input from analogRead returns a value between 0 and 1023. The analogWrite takes values between 0 and 255. The code below show you have to convert your analog in value to make your LED shine as bright as possible when the potentiometer is fully on.

  1. int ledPin = 3;
  2. int potentiomenterInput = 0;
  3.  
  4. void setup()  {
  5.   pinMode(ledPin, OUTPUT);
  6. }
  7.  
  8.  
  9. void loop()  {
  10.  
  11.   potentiomenterInput = (analogRead(0)/4); // Divides input 0-1023 to resemble to 0-255
  12.  
  13.   analogWrite(ledPin, potentiomenterInput);  
  14.   // The delay can be change to get the desired dimming effect
  15.   delay(20);                            
  16. }

PNP transistor


Turn the LED on with this code:

  1. void setup() {                
  2.   pinMode(13, OUTPUT);    
  3. }
  4.  
  5. void loop() {
  6.   digitalWrite(13, HIGH); // Turn on LED
  7.   delay(5000);
  8.   digitalWrite(13, LOW); // Turn off LED
  9.   delay(5000);      
  10. }