Serial.println("Signal Received (low)") //Display on Serial monitior so I can see it did it If (EmitterPin = LOW) //IF Digital Pin 8 = LOW If (currentMillis - previousMillis2 >= Read_Emitter) //IF Current time - Previous time is greater than 1000ms Serial.println("BasePin Low") //Display on Serial monitior so I can see it did it PreviousMillis1 = currentMillis //Update perviousMillis1 to current timeĮlse if (currentMillis - previousMillis1 >= TransistorOffTime) //IF Current time - Previous time is greater than 2000msĭigitalWrite(BasePin, LOW) //Set digital Pin 4 LOW Serial.println("BasePin High") //Display on Serial monitior so I can see it did it If (currentMillis - previousMillis1 >= TransistorOnTime) //IF Current time - Previous time is greater than 4000msĭigitalWrite(BasePin, HIGH) //Set digital Pin 4 HIGH Pulse_Read() //Sub Routine for receiving pulses from the 2N3904 Transistor Emitter Pin Pulse_Send() //Sub Routine for sending pulses to the 2N3904 Transistor Base Pin Serial.println() //Print a blank line to the Serial MonitorĬurrentMillis = millis() //Track time through each loop Serial.println("Program Begin.") //Print something on the Serial Monitor so I know program has started PinMode(EmitterPin, INPUT_PULLUP) //Set pin 8 as INPUT_PULLUP PinMode(BasePin, OUTPUT) //Pin 4 set as OUTPUTĭigitalWrite(BasePin, LOW) //Set Pin 4 LOW Serial.begin(BAUD) //Start Serial for troubleshooting Unsigned long Read_Emitter = 1000 //Read state of Emitter pin every 1000ms Unsigned long TransistorOffTime = 2000 //Turn transistor off for 2000ms Unsigned long TransistorOnTime = 4000 //Turn transistor on for 4000ms Unsigned long previousMillis2 = 0 //For storing Previous time Unsigned long previousMillis1 = 0 //For storing Previous time Unsigned long currentMillis //For saving current time Long BAUD = 115200 //BAUD rate for Serial Monitior * Emitter Pin of 2N3904 Transistor connected to Pin 8 of Arduinoīyte BasePin = 4 //Base Pin of 2N3904 Transistor to Pin 4 of Arduino UNO R3īyte EmitterPin = 8 //Emitter Pin of 2N3904 Transistor to Pin 8 of Arduino UNO R3 * Collector Pin of 2N3904 Transistor connected to Arduino Ground Pin * 10K resistor connected to Base Pin of 2N3904 Transistor * Digital Pin 4 from Arduino connected to 10K Resistor * Components: Breadboard Arduino UNO R3 2N3904 Transistor 10K Resistor Jump wires. The Collector Pin is connected to Ground of the Arduino, the Emitter Pin to Pin 8 on the Arduino. I have the 2N3904 Transistor on a breadboard, I have a connection going from Pin 4 of the Arduino to one end of a 10K resistor, the other end of the resistor going to the Base Pin of the 2N3904. ![]() Secondly I'm not sure if I understand the Transistor correctly either. I'm attempting to test a 2N3904 Transistor with an Arduino UNO R3, for starters I believe I haven't coded the program correctly.
0 Comments
Leave a Reply. |