» Topics » DIY ideas »Nightlight with brightness control

Dimming Night Light

Today I want to tell you how to assemble a nightlight using a minimum of details and today we need:

1.Arduino (in my case, Uno)
2.Breadboar or as it is also called solderless breadboard
3.LED of any color for a voltage of 3 volts
4.Cable for programming
5. Potentiometer
6. jumper wires
7. 220 ohm resistor

so let’s transgress, first you need to program the arduino



Here is a sketch:

// give reasonable names for pins with LED
// and potentiometer (English potentiometer or just “pot”)
#define LED_PIN 9
#define POT_PIN A0
 
void setup ()
{
  // pin with LED - output, as before ...
  pinMode (LED_PIN, OUTPUT);
 
  // ... but the pin with the potentiometer should be an input
  // (English "input"): we want to read the voltage,
  // issued by him
  pinMode (POT_PIN, INPUT);
}
 
void loop ()
{
  // declare that further we will use 2 variables with
  // names rotation and brightness, and what we will store in them
  // integers (English "integer", abbreviated simply as "int")
  int rotation, brightness;
 
  // read the rotation voltage from the potentiometer in rotation:
  // microcontroller will give a number from 0 to 1023
  // proportional to the angle of rotation of the handle
  rotation = analogRead (POT_PIN);
 
  // in brightness, write the rotation value obtained earlier
  // divided by 4. Since we wanted to store in variables
  // integer values, the fractional part of the division will be discarded.
  // As a result, we get an integer from 0 to 255
  brightness = rotation / 4;
 
  // output the result to the LED
  analogWrite (LED_PIN, brightness);
}


then you need to connect everything according to this scheme;

Dimming Night Light


And roughly so I got




I think you liked this article and I suggest you participate in the survey below, but that's it for me
TILL
END
Question \ topic is automatically published in the social. site network - stay tuned for answers there:
did you manage to repeat?
Total votes: 5

Suitable for topic

Related topics

Add a comment

    • smilesmilesxaxaokdontknowyahoonea
      bossscratchfoolyesyes-yesaggressivesecret
      sorrydancedance2dance3pardonhelpdrinks
      stopfriendsgoodgoodgoodwhistleswoontongue
      smokeclappingcraydeclarederisivedon-t_mentiondownload
      heatirefullaugh1mdameetingmoskingnegative
      not_ipopcornpunishreadscarescaressearch
      tauntthank_youthisto_clueumnikacuteagree
      badbeeeblack_eyeblum3blushboastboredom
      censoredpleasantrysecret2threatenvictoryyusun_bespectacled
      shokrespektlolprevedwelcomekrutoyya_za
      ya_dobryihelperne_huliganne_othodifludbanclose
4 commentary
Dudosa1337
In fact, it’s good that he is engaged in arduino and programming
Antokha
Cool homemade, I managed to repeat
The kid will go far, already in the profile he writes "I do home-made to order." )))
while using a minimum of details

1.Arduino (in my case, Uno)
2.Breadboar or as it is also called solderless breadboard
3.LED of any color for a voltage of 3 volts
4.Cable for programming
5. Potentiometer
6. jumper wires
7. 220 ohm resistor
And this is to light up one LED? Soon they will not be able to go to the toilet without Arduino! scratch

We advise you to read:

Hand it for the smartphone ...