I have got a sensor attached to a0 and to the - and +
its reading about 55 in the current light - which is dusk
where would i put "analogRead"?
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
digitalWrite(ledPin, LOW); // turn the LED on
}
void loop() // run over and over again
{
if
analogRead(analogPin); // read the input pin
int(sensorvalue <= 55) // if sensor level goes below 55
digitalWrite(ledPin, HIGH); // turn led on
}
Apologies for the questions? Its for a uni end of year show and dont have long left!
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); <= 55 // read sensor
{
digitalWrite(ledPin, HIGH); // turn led on
}
{
if analogRead(sensorPin); => 54 // read sensor
}
{
digitalWrite(ledPin, LOW); // turn led off
}
}
But its saying the following errors
Blink:26: error: expected primary-expression before '=' token
Blink:26: error: expected primary-expression before '>' token
Blink:27: error: expected `;' before '}' token
void loop() {
if ( analogRead(analogPin) <= 55) // read sensor
{
digitalWrite(ledPin, HIGH); // turn led on
}
it says 'analogPin' was not declared in this scope and then the following errors
Blink:25: error: expected primary-expression before '>' token
Blink:26: error: expected primary-expression before '}' token
Blink:26: error: expected `;' before '}' token
How do i use else?
im struggling to understand this - i have tried searching all over for an answer so thanks for your patience and time
Im wanting to have the lights on when it gets darker (and im trying to figure out how to make the light "twinkle" as it will have fibre optic cables attached to the led)
It now does what i want in regards to turning on and off - now i need to worry about making the led flash but im working with the blink programme so we will see what i come up with.
Edit - this code seems to work
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
}
}
Now - how do i now programme another 14 leds - i want them in groups of two per petal but i cant seem to get just one working on the code! Any help from anyone -