What will you make:
In this tutorial we will learn how to make night detector using some of the components provided in the Missduino Kit .
What will you need:
For this project you will need:
- LilyPad Arduino USB
- LilyPad Light Sensor
- LilyPad LED
- Alligator Clips
- micro USB data cable
Using Arduino IDE
Lilypad night detector code using arduino ide
// Set higher or lower to adjust sensitivity.
const int darkLevel = 5;
// Create a variable to hold the readings from the light sensor.
// Set which pin the Signal output from the light sensor is connected to
int sensorPin = A3;
// Set which pin the LED is connected to.
int ledPin = 3;
// Set sensorPin as an INPUT
// Set LED as outputs
// Set pin A5 to use as a power pin for the light sensor
// Initialize Serial, set the baud rate to 9600 bps.
// Read the light sensor's value and store in 'lightValue'
lightValue = analogRead(sensorPin);
// Print some descriptive text and then the value from the sensor
Serial.print("Light value is:");
// Compare "lightValue" to the "dark" variable
if (lightValue <= darkLevel) // If the reading is less then 'darkLevel'
digitalWrite(ledPin, HIGH); // Turn on LED
else // Otherwise, if "lightValue" is greater than "dark"
digitalWrite(ledPin, LOW); // Turn off LED
// Delay so that the text doesn't scroll to fast on the Serial Monitor.
// Adjust to a larger number for a slower scroll.
- Connect the components as shown in schematic.
- Copy the Code.
- Select the LilyPad board from tools > boards > Arduino USB
- Select the LilyPad port from tools > Port > port#(LilyPad ).[as shown in Guide Book]
- Connect LilyPad to your Laptop/Computer and upload the code by pressing upload button.
- Go on with it.
- Go to Tools, click Serial Monitor, and see the output over there as well that what the level of light intensity is.