Automatic Sensor Night Light
by eugenia1217 in Circuits > Arduino
193 Views, 1 Favorites, 0 Comments
Automatic Sensor Night Light
When all the socket in your bedroom is full, but you really need a little light to sleep, this automatic sensor night light will definitely be your best choice! An Automatic Sensor Night Light is a really useful thing. in my own opinion, I will definitely need a night light every night in able to sleep well, so this will help me a lot when I don't have sockets anymore in my room.
Materials
the material list of this night light is provided under:
1x Arduino Leonardo or Equivalent and USB cable
1x breadboard
9x 220-ohm resistor
20x wires
1x Ultrasonic sensor
9x LED
1x cardboard
1x scissor
tape
the materials above are the easy and simple ones if you would like to make your night light more colorful and more fascinating, you may add any other items you want!
Arduino Code
boolean t = true;
int i = 12; void setup()
{
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
}
void loop()
{ digitalWrite(i, HIGH);
delay(50);
digitalWrite(i, LOW);
if (t == true)
{
i = i - 1;
}
else
{
i = i + 1;
}
if (i < 5)
{
i = 6;
t = false;
}
if (i > 12)
{
i = 11; t = true;
}
}
Circuit
the circuit shown above might be a bit messy, but this is the full version of my whole Arduino Leonardo or Equivalent and USB cable and the breadboard.