okay so i finally have time to play with my arduino some more! im try to get it so that when the phototransistor see the inferred light that it will turn on an led. im almost sure i have my phototransistor connected right, and i know the led is connected right. but i think that only leaves my sketch, take a look.
int ledpin = 13; // led is on pin 13
int pt = A1; // phototransistor is on pin analog 1
void setup(){
pinMode(ledpin, OUTPUT);
}
void loop(){
if (pt == HIGH)
{
digitalWrite(ledpin, HIGH);
}
else
{
digitalWrite(ledpin, LOW);
}
}
int ledpin = 13; // led is on pin 13
int pt = A1; // phototransistor is on pin analog 1
int val = 0;
void setup(){
pinMode(ledpin, OUTPUT);
}
void loop(){
val = analogRead (pt);
if (val == LOW)
{
digitalWrite(ledpin, LOW);
}
else
{
digitalWrite(ledpin, HIGH);
}
}
i didnt know my bedroom light can be seen by the pt.
new problem. im trying to get a pot to control how long the led will stay on, after the pt is off.
int ledpin = 13; // led is on pin 13
int pt = A1; // phototransistor is on pin analog 1
int val = 0; // place to store value from the phototransistor
int pot = A2; // pot is on pin analog 2
int val2; // place to store value from pot
void setup(){
pinMode(ledpin, OUTPUT); // declares the ledpin as an output
}
void loop(){
val = analogRead(pt); //reads the value from the phototransistor
val2 = analogRead(pot); // reads the value from the pot
if (val == LOW) // checks to see if val is off
{
digitalWrite(ledpin, LOW); // turns led off
}
else
{
digitalWrite(ledpin, HIGH); // turns led on
delay(pot); // delays how long the led is off
}
}
jareeb:
new problem. im trying to get a pot to control how long the led will stay on, after the pt is off.
As in a time delay from when the phototransistor goes off until the led is actually turned off?
In that case, take a look at the Blink Without Delay example. Set the timestamp whenever the phototransistor is on, and if it's been so long since that timestamp, turn it off.