March 3, 2019

Arduino Flashlight Tutorial


ARDUINO FLASHLIGHT TUTORIAL


INTRODUCTION

Arduino is a microcontroller which can be programmed to do certain operations like lighting led, controlling servo, etc. This is a DIY Arduino project intended to create a flashlight (torch). Flashlights are used for general purpose in household such as alternate light source during power outage, searching in the attic, check leaking pipes, etc. A simple and inexpensive flashlight can be created by using LED’s, resistors and arduino microcontroller. The flashlight setup consists of 9 white LED’s arranged in a 3x3 matrix which are connected to the microcontroller via the resistors. The LED’s are controlled by the microcontroller which runs on the user defined code.

COMPONENTS REQUIRED
1. Perfboard and Breadboard
2. Arduino (Mega 2560 or UNO) and USB cable
3. 5mm White LED’s (9)
4. 220 Ohm resistors (9)
5. Jumpers
6. A 5V Power supply

CIRCUIT SCHEMATICS

Fig.1 Schematic

Make the appropriate connections as shown in the schematic above

CODE

This is the code for simulating a torch. Note that this code is valid only for the particular schematic represented in figure1. The values and choice of ports can always be changed. Copy and paste the code in Arduino IDE sketch area.

/*
 Arduino Torch

 9 White LED's arranged in a 3x3 grid
 220ohm resistors
Created by Srinath Srinivasan
March 3, 2019

*/

int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LED6 = 7;
int LED7 = 8;
int LED8 = 9;
int LED9 = 10;

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  pinMode(LED7, OUTPUT);
  pinMode(LED8, OUTPUT);
  pinMode(LED9, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED1, HIGH);   // turn ON the LED's 1to 9 
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  digitalWrite(LED4, HIGH);
  digitalWrite(LED5, HIGH);
  digitalWrite(LED6, HIGH);
  digitalWrite(LED7, HIGH);
  digitalWrite(LED8, HIGH);
  digitalWrite(LED9, HIGH);
 
                                    
}

No comments:

Post a Comment