How can I use this arduino coupler to input into the Arduino?
Would this work? I want to use a pull down resistor but not sure how to do that.
Or can i use the internal pull down resistors?
How can I use this arduino coupler to input into the Arduino?
Would this work? I want to use a pull down resistor but not sure how to do that.
Or can i use the internal pull down resistors?
Cant tell what yer doing here, the picture shows a regular transistor but you linked an opto coupler. Depending on what youre tryin to do a common way to use 4N25 is
When "some voltage" is present current flows in LED of optocoupler and turns on its transistor. That pulls D2 LOW against the pullup resistor in Arduino. When "some voltage" goes away or reverses polarity then the optcoupler turns OFF and D2 goes high.
int optoPin = 2; // 4N25 opto coupler connected to digital pin 2
void setup()
{
pinMode(optoPin, INPUT); // sets the digital pin as input
digitalWrite(optoPin, HIGH); // turns on the internal pull up
}
void loop()
{
if (digitalRead(optoPin) == LOW) {
// do stuff when "voltage is present"
}
}
ah so i dont have to give it 5V at all I can just ground it.
Thanks
Yh i was just trying to illistraight the transister side only.
So would this be ok?
I want to count the number of pulses in a second. Is there a better way? If im going to have multiple things in the main loop is that the right way of doing it or should i use interupts? I'm very new to this . Thanks Rob
//////////////////////////////////////////////////
/////////////////START UP CODE////////////////////
//////////////////////////////////////////////////
int latchPin = 8; //Latch pin declare
int clockPin = 12; //Clock pin declare
int dataPin = 11; //Data pin declare
int rpmpulseinput = 1; //RPM input declare
int pulsesdetected = 0; //RPM counted
void setup() {
//start com with (serial)
Serial.begin(96000);
Serial.println("Arduino Connected to M1330 via USB");
//Connect to shift register IC
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(rpmpulseinput, INPUT);
// sets the digital pin as input
digitalWrite(rpmpulseinput, HIGH);
// turns on the internal pull up
//Output test of IC
}
//////////////////////////////////////////////////
///////////////////MAIN CODE//////////////////////
//////////////////////////////////////////////////
int pulseread(){
if (digitalRead(rpmpulseinput) == LOW) {
pulsesdetected=pulsesdetected+1;
}
}
void loop()
{
pulseread();
//DO OTHER THINGS
//MORE OTHER THINGS :)
}
//////////////////////////////////////////////////
////////////////////END OF CODE///////////////////
//////////////////////////////////////////////////
Dont increment pulsesdetected every time you see input LOW, just whenever input changes from HIGH to LOW.
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// //
// Producer : RMFMellink //
// e-mail : XXX //
// //
//////////////////////////////////////////////////
//////////////////////////////////////////////////
//////////////////////////////////////////////////
/////////////////START UP CODE////////////////////
//////////////////////////////////////////////////
int latchPin = 8; //Latch pin declare
int clockPin = 12; //Clock pin declare
int dataPin = 11; //Data pin declare
int rpmpulseinput = 1; //RPM input declare
int pulsesdetected = 0; //RPM counted
int lastpulsestatedetected = 0;//RPM last pulse state detected
void setup() {
//start com with (serial)
Serial.begin(96000);
Serial.println("Arduino Connected to M1330 via USB");
//Connect to shift register IC
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(rpmpulseinput, INPUT);
// sets the digital pin as input
digitalWrite(rpmpulseinput, HIGH);
// turns on the internal pull up
//Output test of IC
}
//////////////////////////////////////////////////
///////////////FUNCTION DECLARATION///////////////
//////////////////////////////////////////////////
int LEDon(int LEDnumber){
//Turns on LED number X with 0ms delay
Serial.print("LED ");
Serial.print(LEDnumber, DEC);
Serial.print(" has been called.");
//Prints LED 10 has been called.
digitalWrite(latchPin, LOW);
//Set latch pin to LOW
shiftOut(dataPin, clockPin, MSBFIRST, LEDnumber);
//Send data to IC
digitalWrite(latchPin, HIGH);
//Set latch pin to HIGH to set changes in IC
}
int LEDtest(int numberofLEDtolight,int delaytime){
//Lights all LED's up with numberofLEDtolight with delay of delaytime in ms
for(int LED1=1;LED1=numberofLEDtolight;LED1++){
//Turns on 1 LED with delaytime ms delay
LEDon(LED1);
//Turns on loop number LED
delay(delaytime);
//Delays the next LED coming on
}
}
int pulseread(){
if(digitalRead(rpmpulseinput)==LOW){
//If the input has a pulse on it
if(digitalRead(lastpulsestatedetected=0)){
//If the output has changed then add one to the number of pulses detected
pulsesdetected=pulsesdetected+1;
}
}
}
int pulseoutput(){
Serial.println(pulsesdetected);
//Print the number of detected pulses
delay(1000);
//Delay 1 second
pulsesdetected = 0;
//Clears pulses detected
}
//////////////////////////////////////////////////
///////////////////MAIN CODE//////////////////////
//////////////////////////////////////////////////
void loop()
{
pulseread();
pulseoutput();
//Do more stuff here all functions
}
//////////////////////////////////////////////////
////////////////////END OF CODE///////////////////
//////////////////////////////////////////////////
is that ok?
How fast will the ARduino be? Just im looking at pulses about every 0.01 seconds so 100 pulses per second MAX.
OK update:
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// //
// Producer : RMFMellink //
// e-mail : ... //
// website : ... //
// //
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// The following code aims to recieve a pulsed
// input with a variable frquency and output the
// number of pulses per minute (rpm) to a shifting
// register which drives up to 30 LED's with the
// overal brightness of the LEDs driven by a PWM
// signal via a transistor.
//////////////////////////////////////////////////
////////VARIABLE AND PIN DECLARATION//////////////
//////////////////////////////////////////////////
//Shift register declaration
int latchPin = 8;
//Latch pin declare
int clockPin = 12;
//Clock pin declare
int dataPin = 11;
//Data pin declare
//RPM inputs
int rpmpulseinput = 1;
//RPM input declare
int pulsesdetected = 0;
//RPM counted
int lastpulsestatedetected = 0;
//RPM last pulse state detected (0=LOW and 1=HIGH)
//////////////////////////////////////////////////
///////////////FUNCTION DECLARATION///////////////
//////////////////////////////////////////////////
int LEDon(int LEDnumber){
//Turns on LED number X with 0ms delay
Serial.print("LED ");
Serial.print(LEDnumber, DEC);
Serial.print(" has been called.");
//Prints LED 10 has been called.
digitalWrite(latchPin, LOW);
//Set latch pin to LOW
shiftOut(dataPin, clockPin, MSBFIRST, LEDnumber);
//Send data to IC
digitalWrite(latchPin, HIGH);
//Set latch pin to HIGH to set changes in IC
}
int LEDcumlon(int numberofLEDtolight,int delaytime){
//Lights all LED's up with numberofLEDtolight with
//delay of delaytime in ms between LEDs
for(int LED1=1;LED1=numberofLEDtolight;LED1++){
//Turns on 1 LED with delaytime ms delay
LEDon(LED1);
//Turns on loop number LED
delay(delaytime);
//Delays the next LED coming on
}
}
int pulseread(){
//Addes one to the pulses detected if the input
//changes state
if(digitalRead(rpmpulseinput)==LOW){
//If the input has a pulse on it
if(digitalRead(lastpulsestatedetected=0)){
//If the output has changed then add one to the
//number of pulses detected
pulsesdetected=pulsesdetected+1;
}
}
}
int pulseoutput(){
//Resets the pulse count every 1 second so the number
//of pulses per second is output
Serial.println(pulsesdetected);
//Print the number of detected pulses
delay(1000);
//Delay 1 second
pulsesdetected = 0;
//Clears pulses detected
}
//////////////////////////////////////////////////
///////////////////MAIN CODE//////////////////////
//////////////////////////////////////////////////
void setup() {
Serial.begin(96000);
Serial.println("Arduino Connected to M1330 via USB");
//start com with (serial)
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
//Connect to shift register IC
pinMode(rpmpulseinput, INPUT);
// sets the digital pin as input
digitalWrite(rpmpulseinput, HIGH);
// turns on the internal pull up
LEDcumlon(15,500);
//Output test of IC of
//X (LEDs to be turned on)
//Y (milliseconds of delay between turning on LEDs)
}
void loop()
{
pulseread();
//Counts the number of pulses
pulseoutput();
//Outputs the number of pulses in 1 second
////////////////////////////////////
//Do more stuff here all functions//
////////////////////////////////////
}
//////////////////////////////////////////////////
////////////////////END OF CODE///////////////////
//////////////////////////////////////////////////