Introduction: Simple Creation - Light Alarm
This experiment is really interesting – to apply a DIY phototransistor. DIY phototransistors use the glow effect and photoelectric effect of LEDs – they will generate weak currents when some light is shined on it. And we use a transistor to amplify the currents generated, so the Arduino Uno board can detect them.
Step 1: Components
- Arduino Uno board * 1
- USB cable * 1
- Passive Buzzer *1
- Resistor (10KΩ) * 1
- LED * 1
- NPN Transistor S8050 * 1
- Breadboard * 1
Step 2: Schematic Diagram:
Step 3: Procedure
With the photoelectric effect, LEDs generate weak currents when exposed to light waves.
NPN consists of a layer of P-doped semiconductor (the "base") between two N-doped layers. A small current entering the base is amplified to produce a large collector and emitter current. That is, when there is a positive potential difference measured from the emitter of an NPN transistor to its base (i.e., when the base is high relative to the emitter) as well as positive potential difference measured from the base to the collector, the transistor becomes active. In this "on" state, current flows between the collector and emitter of the transistor. The value of A0 will be larger than 0. By programming, we make the buzzer beep when A0 is larger than 0.
A 10kΩ pull-down resistor is attached to the transistor output stage in order to avoid analog port suspending to interfere with signals and cause misjudgment.
Step 1:
Build the circuit.
Step 2:
Download the code from https://github.com/primerobotics/Arduino
Step 3:
Upload the sketch to the Arduino Uno board
Click the Upload icon to upload the code to the control board.
If "Done uploading" appears at
the bottom of the window, it means the sketch has been successfully uploaded.
Now, shine a flashlight on the LED and you can hear the buzzer beep.
Step 4: Code
//Simple Creation
- Light Alarm//Now, you can hear that the buzzer make sounds when the LED is shined.
//Email: info@primerobotics.in
//Website:www.primerobotics.in
void setup()
{
Serial.begin(9600); // start serial port at 9600 bps:
}
void loop()
{
int n=analogRead(A0); //read the value from analog pin AO
Serial.println(n);
if(n>0) //If there is a voltage
{
pinMode(5,OUTPUT); //set the digital pin 5 as an output
tone(5,10000); //Generates a square wave(10000 Hz frequency,50% duty cycle) on pin 5
pinMode(5,INPUT); //set the pin 5 as an input
}
}