led strip: https://www.adafruit.com/products/887
power supply: https://www.adafruit.com/products/352
breakbeams: https://www.adafruit.com/products/2168
mosfet transistor: http://www.adafruit.com/datasheets/irlb8721pbf.pdf
I've attached photos of how I've got everything wired. If you're using the fritzing diagram, the 9V represents the 12V DC, the IR sensor on the left is the transmitter, the IR on the right is the receiver, and the white LED is the led strip.
My sketch is as follows:
- Code: Select all | TOGGLE FULL SIZE
int ledPin = 6;
int sensorPin = 3;
int sensorState = 0, lastState=0;
void setup() {
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
sensorState = digitalRead(sensorPin);
if (sensorState) {
Serial.println('low');
digitalWrite(ledPin, LOW);
} else {
Serial.println('high');
digitalWrite(ledPin, HIGH);
}
lastState = sensorState;
}
When I run this - the whole thing works for a second, and then malfunctions. The last time I tried it, my IR transmitter started smoking. I've tested all the components individually and they still work, but I'd like to know what I'm doing wrong so I can avoid destroying $130 worth of components. Can you provide any advice?
Thanks!