int ledPin = 13; // LED is connected to digital pin 13
int sensorPin = 0; // light sensor is connected to analog pin 0
int sensorValue ; // variable to store the value coming from the sensor
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
Serial.begin(9600); //initialize the serial port
How do i add a second, third, fourth led?
Is this code correct?
int ledPin = 13; // LED is connected to digital pin 13
int ledPin = 12; //LED is connected to digital pin 12
int sensorPin = 0; // light sensor is connected to analog pin 0
int sensorValue ; // variable to store the value coming from the sensor
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
Serial.begin(9600); //initialize the serial port
You need seperate variables and commands for each LED
eg:
int ledPin = 13; // LED is connected to digital pin 13
int ledPin2 = 12; //LED2 is connected to digital pin 12
int sensorPin = 0; // light sensor is connected to analog pin 0
int sensorValue ; // variable to store the value coming from the sensor
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(ledPin2, OUTPUT); // sets the ledPin2 to be an output
Serial.begin(9600); //initialize the serial port
I have the leds set to flash on and off - How do i get each set of leds (they will be wired in pairs of 2) to work individually - ie sets 1, 2 and 3 will blink at a faster rate than the others?
I have this so far
int ledPin = 13; // LED is connected to digital pin 13
int sensorPin = 0; // light sensor is connected to analog pin 0
int sensorValue ; // variable to store the value coming from the sensor
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
Serial.begin(9600); //initialize the serial port
}
void loop() {
if ( analogRead(sensorPin) <= 100) // read sensor
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
else
{
digitalWrite(ledPin, LOW); // turn led off
}
}