Show Posts
Pages: [1] 2 3 ... 49
1  Using Arduino / General Electronics / Making Sure I Understand Opto Interrupt Sensors on: May 23, 2014, 01:19:58 pm
I just got back into Arduino and electronics, and I wanted to make sure I know what I'm doing. I'm working with some coin hoppers that use opto interrupts to detect the coins being dispensed. Below is the schematic of how the sensor is in the hopper. If I understand correctly, I would just supply the 5v and ground as shown, and then I would need a pull up resistor on the signal pin, correct?

2  Using Arduino / Programming Questions / Re: Getting back into Arduino, don't know why this code doesn't work. on: May 18, 2014, 09:12:17 pm
Right now the motor is actually simulated by an LED (with a resistor of course). On the coin hopper I bought, there is apparently a trigger pin, which only takes a very small amperage. I think the hopper might have its own relay or transistor inside.
3  Using Arduino / Programming Questions / Re: Getting back into Arduino, don't know why this code doesn't work. on: May 18, 2014, 08:56:18 pm
Here's the working code. I used the variable "mval" to control the motor status instead of "high" or "low".
Code:
int motor = 13;
int sensor = 12;
int button = 11;

int buttonstate;
int sensorstate;
int prevsensorstate;
int count;
int prevcount;
int mval;

void setup() {
  pinMode(motor, OUTPUT);
  pinMode(sensor, INPUT);
  pinMode(button, INPUT);
  
  mval = 0;
  digitalWrite(motor, mval);
  
  count = 0;
  prevcount = 0;
}

void loop() {
  if(mval == 0){
    buttonstate = digitalRead(button);
  }
  
  sensorstate = digitalRead(sensor);
  
  if(buttonstate == 1 && count < 50) {
    mval = 1;
    digitalWrite (motor, mval);
    if(sensorstate == 0 && prevsensorstate == 1){
      count = prevcount + 1;
    }  
  }
  else if(count == 50){
    if(sensorstate == 1){
      mval = 0;
      digitalWrite(motor, mval);
      count = 0;
    }
  }
  prevcount = count;
  prevsensorstate = sensorstate;
  delay(10);
}
4  Using Arduino / Programming Questions / Re: Getting back into Arduino, don't know why this code doesn't work. on: May 18, 2014, 08:45:36 pm
psstate = previous sensor state, because I have to compare what the sensor is NOW compared to what it was on the previous loop.

And I think david is right. I made a new variable to store the state of the motor (1 or 0), and it seems to be working fine now. The weird thing is it works when plugged into my computer, but not when plugged into my wall wart.
5  Using Arduino / Programming Questions / Re: Getting back into Arduino, don't know why this code doesn't work. on: May 18, 2014, 08:26:04 pm
No. If you know which of the two is HIGH and which is LOW then you should be able to debug using the 0's and 1's.
How is the switch (button) wired (exactly) ?
The button is just connected to 5v on one side and the input pin on the other. I also have a pull down resistor on the input pin side.
6  Using Arduino / Programming Questions / Re: Getting back into Arduino, don't know why this code doesn't work. on: May 18, 2014, 08:20:16 pm
I tried that at one point, and the thing that confused me is the readout in Serial Print is a 1 or 0, not high or low. Should I be using 1 and 0 in my variables instead?
7  Using Arduino / Programming Questions / Re: Getting back into Arduino, don't know why this code doesn't work. on: May 18, 2014, 08:10:42 pm
You mean as far as what the code is supposed to do? I'm basically building a machine to count out 50 coins and then stop.

The "button" is the trigger that a person would press, and once it is pressed, the machine needs to dispense 50 coins. The "motor" is the motor in the coin dispenser, and the "sensor" is basically an IR transmitter and receiver that is blocked by the passing coins, and can be used to count the coins.
8  Using Arduino / Programming Questions / Getting back into Arduino, don't know why this code doesn't work. on: May 18, 2014, 07:09:42 pm
Hello everyone. I used to be quite active here a few years back, and then school got more difficult and I had to take a break from Arduino. Anyways, I had some free time and I needed to make a quick project. Below is the code I wrote, and I can't figure out what I did wrong.

Code:
const int motor = 13;
const int sensor = 12;
const int button = 11;

int bstate;
int sstate;
int psstate;
int count;
int pcount;

void setup() {
  pinMode(motor, OUTPUT);
  pinMode(sensor, INPUT);
  pinMode(button, INPUT);
 
  digitalWrite(motor, LOW);
 
  count = 0;
  pcount = 0;
}

void loop() {
  if(motor == LOW){
    bstate = digitalRead(button);
  }
 
  sstate = digitalRead(sensor);
 
  if(bstate == HIGH && count < 50) {
    digitalWrite (motor, HIGH);
    if(sstate == LOW && psstate == HIGH){
      count = pcount + 1;
    }
    else{
    } 
  }
  else if(count == 50){
    digitalWrite(motor, LOW);
    count = 0;
  }
  pcount = count;
  psstate = sstate;
}
9  Community / Bar Sport / Re: Your latest purchase on: November 25, 2011, 11:47:41 pm
Bought 2 10' iPhone cables, and 2 2 amp iPad chargers off ebay... Already got the cables (3 days later) and they work great! Cost me $3 each, compared to the $30 each that high quality ones (Griffin Technology) cost.
10  Community / Bar Sport / Scorpions: ever been stung? on: November 21, 2011, 08:24:22 pm
Has anyone out there been stung by a scorpion? I had it happen once before, and I couldn't find relief... It happened again, and I'm wondering what on earth can make this go away?
11  Community / Bar Sport / Re: Your latest purchase on: November 19, 2011, 06:24:54 pm
Just went christmas shopping... Bought my bro the Xbox 360 controller he wanted. D

(don't worry, he doesn't read arduino)
12  Community / Bar Sport / Re: Your latest purchase on: November 07, 2011, 09:26:57 pm
Quote
Don't underestimate the power of a .22... Anyhow, the rim split, and the gasses came out the back, finding any way out that they could.

Aw heck, I've had that happen in several revolvers.  I just dropped them by a gunsmith for a look-see and they never had to have any work done.
Well, a P22 is a semi auto, so when it blows, the gas doesn't just go out the side... it goes any where it can. I'm gonna make a youtube vid about how walther handles it, and review their coustimer service.
13  Community / Bar Sport / Re: Your latest purchase on: November 07, 2011, 06:47:39 pm
Jeremy, it's a 22LR rimfire, how the heck did you blow it up?  Get a round trapped in the barrel from a light load? 

Is your hand OK?..    Now we know why safety glasses are a really good idea.
Don't underestimate the power of a .22... Anyhow, the rim split, and the gasses came out the back, finding any way out that they could.

And yes, my hand is fine.
14  Community / Bar Sport / Re: Your latest purchase on: November 06, 2011, 04:44:43 pm
Well... FML, my Walther P22 blew up in my hand, so I guess my next purchace is either shipping to send it in for warranty, or to buy a new one...
15  Community / Bar Sport / Re: Your latest purchase on: November 06, 2011, 09:52:44 am
2 boxes of this: http://www.fatwallet.com/static/attachments/8270_winchester40calammo.jpg

and a box of 100 12 gauge Federal rounds...

Well, off to go waste em all, cya later.
Pages: [1] 2 3 ... 49