Do Any Members Have Skill or Experience With Arduino; Coding for Microcontrollers

The other day I didn’t end up getting to the trimming, so I did a session last night. (And please don’t feel any urgency to reply. I know you have a life to live, haha).
Ok…

Yea, some combination of unplugging, closing/reopening, and checking out device manager ports seemed to get it working well enough. I had to “unhide” hidden to see ports (com & lpt) too. I found threads regarding similar issues too. I think it also might have been the second data cable I was trying to use too, but hard to know.

Haha. Ok, it’s all good. Thanks.

Thanks for the encouragement and understanding. I/we do have it pretty good with the internet, tuts, forums, etc., these days.


Ok, this is good to know. Because while testing out your code, I would break the beam and trigger the solenoid, then as designed it wouldn’t trigger again, and I’d use the ‘reset’ button on the arduino. Everytime I press the ‘reset’ button it will very quickly turn the solenoid on/off three times. I was wondering if it was something to do with inrush current, or maybe the diode I was using.

Ok, cool.

All good, sir. Thanks.

Ok. And thanks.

I found it in the preferences, can’t belive I asked before looking there.

Hmm, ok. This is interesting.

This comment about the pullup was there from the original adafruit code demo. Quote from the demo code: “Most microcontrollers have the ability to turn on a built in pull up resistor. If you do not, connect a 10K resistor between the white wire of the receiver and the red wire.”.
I don’t quite get it completely.
Some boards don’t have one? Is it only on a particular pin (like the led that’s on pin 13 on an UNO board)? What is this resistor’s purpose and wouldn’t its value make it only useful in certain circumstances/configurations? Maybe it’s of a value that’s meant to protect the board circuitry…?

Haha, nice. I’m going to add this into your/the code now and see if it stops that issue.

I really like the way you word this, as you said “I like to pretend I’m the “computer,” and literally interpret every line for each condition and see which way the code tells me to go.” That, and the numbered lines helps me follow the logic better. Thank you so much.

Ok. I’m gonna change your last .ino to look like this one, with the power up delay, and test it.
I was out yesterday and picked up some wooden snap traps as they’re easier to modify. Tomorrow I’ll temporarily fasten the solenoid down, tie it to the trigger pan, and see how that work.

Tonight I hope to finish my trimming and get that out of the way.

Have a good night.

1 Like

The solenoid still triggers up connecting 12v adapter and when reseting the UNO with reset button. I tried increasing the delay to 1500ms. And tried moving that delay line up to before line 9 (initializing LEDPIN, OUTPUT), too.
Maybe it’s hardware/wiring related…I’ll upload pictures of the setup later.

1 Like

How’s the book going @sfzombie13 ?

slow. i actually took a break and just started back. after i get some pictures and make a few additions i’ll have draft 2 out. the networking is a bitch to explain. i understand it, but explaining it so others can understand is hard.

1 Like

I hope this helps. Drawing a schematic would be difficult for me, I think. I only did very basic stuff in school, and remember very little of that even.
Power is applied with the 3-12v adjustable adapter I linked in an earlier post.




1 Like

I know what you mean. Two different things/abilities. Well, good luck with it, man.

1 Like

Do you have another USB cable you can try? USB cables are crap now a days and you can get that error with a faulty cable.

On a previous post early in the thread you mentioned the Arduino forums are not welcoming, that’s not really true unless you pop up without showing you are trying ex: post code that you have, what you expect it to do and you will get help. It’s the jokers who have not lifted a finger to do anything that get rolled, wishing and hoping someone will write the code for them.

Since you’re working with Arduino, does my forum handle ring a bell? :thinking:

2 Likes

I have the one that came with the Elegoo Arduino UNO kit. But I tried using one that came with a jtag lattice programmer because it was a bit longer and more convenient.

Ring a bell? No. Unless you mean from the most recent ‘error’ message I got from the IDE…?

Most Arduino use a Atmel “AVR” 328P. :wink:

1 Like

Hi @avr1

Nitt: Regarding the pull up and pull-down resistors, it depends.

Here’s your sensor:

It’s OPEN COLLECTOR transistor output. Let’s talk about that little detail before we chat about pull ups and pull downs. Open collector output refers to the photo switch’s output circuit - it’s a single transistor configured much like your darlington transistor. Its output is either floating [when it is outputting a ‘1’], or it’s pulled by the transistor switch to ground with very low resistance [when outputting a ‘0’]. We would want a pull-up resistor so that when the output is ‘1’ there is a defined state for the pin, it isn’t just floating all over the place based on stray voltages. 10K is a really common value for these since the old days, but they used to be largely external. I still lay out my circuit boards with hardware pull-ups and pull-downs as appropriate to ensure that hardware always functions predictably. Usually there’s 50K-200K pull-up resistors in microcontrollers that can be enabled, but that isn’t true across ALL microcontrollers. The reason for this is the same: if you want to apply a pull-up (or pull-down) resistor so your software acts reliably, may as well have it built into the microcontroller. That’s what Adafruit is talking about.

Much of my career experience has been designing electronics that absolutely have to work, in terrible environments. I generally use fairly “strong” pull-ups and pull-downs because of the harsh electrical environments and noise. But, they consume a little bit of power when being driven, such as when your break-beam would get tripped. Not a lot, but enough to be cognizant of when designing systems.

In your application, I’d put a 10K hardware pull-up from 5V to your sensor pin. It’s not going to hurt you, although you are getting a 20K already in this position from your Arduino. I like KNOWING the hardware is pretty much self-sufficient.

With that comment, let’s chat about your solenoid spazzing out on reset. I think it’s time to put a pull-down on your digital output pin. Back to a few sentences ago, when microcontrollers reset and outputs aren’t being DRIVEN (you haven’t yet set an OUTPUT, and it hasn’t been digital written yet), you don’t know the state of those pins. You can find out in the datasheet but usually those pins all go to input type on bootup, before any of your code ever runs. Sometimes they are just inputs, sometimes inputs with pull-ups. A pull-down on your digital output, LEDPIN in this case, would ensure the darlington never sees enough base voltage to turn on. What values of resistor do you have handy? Add something between 1K and 10K as a pull-down for your LEDPIN and see if that behavior disappears.

Here’s a schematic for my drying cabinet controller based on Arduino Nano. You’ll note pull-ups on buttons, and pull-downs on MOSFET gates.Cabinet_Ctrl HW Design.pdf (923.7 KB)

Hope that helps, like last week, I’ll be much more available to help Friday-Sunday.

Thank you for the pictures by the way, very clean photos and you’ve done a nice job being tidy. Looks very good. If you want help deciding where to put these two suggested hardware resistors (pull-up on the SENSORPIN, and a pull-down on the LEDPIN), I could easily draw those into your pictures on the breadboard.

1 Like

Just to be clearer. 10Ks are kinda the best overall balance of things. Generally you can be more aggresive with driven outputs because you KNOW what is driving them (the Arduino here, with 10mA+ of drive capacity). The datasheet for the sensor is mostly in Chinese and not decipherable, although it states it can drive pretty high loads. I’m just being conservative, and trying to communicate that these values aren’t critical. You won’t notice any difference between a 1K and a 10K in either of these places, although 10K is what I would pick.

1 Like

Ok, I’ll try this.

I’ve got a ‘kit’, so I probably have whatever’s needed for resistors.

I’ll try that out.

Wow. That’s…intimidating, hah. I had to look up “mosfet schematic symbol(s)” to know what I was looking for. I think I spot four of them, on the right side of the drawing (the “Nexperia” name next to them)?

Ok, thank you.

Haha, that sucks.
Thanks for the edited picture, I’ll try that out in the next hour or so.

I tried a 10K on the sensorpin, and a 10K on the ledpin. Didn’t solve it.
I tried a 1K on the ledpin. Didn’t work.
Then I tried a 2K on the ledpin. Didn’t work.

  1. Is there anything I can do/check with a DMM to figure out what’s going on?

  2. Could the fact I’m using pin13 with the onboard led as my “solenoid driving pin” have anything to do with the issue? I could just change the output pin being used and change the code to reflect that…?

When the solenoid “spazzes” (on-off, on-off, on-off) the onboard orange led for pin13 also goes (on-off, on-off, on-off).

(@FieldEffect too):
I’m curious. When people do show up, asking essentially for people to just “write code for them”, what are these “projects” that they are asking for ‘help’ with, usually? And do they have the hardware side figured out; do they know how to wire/connect the components up (doubtful, I guess?)? I’m sure it varies, but I’m curious.

One of the things I seriously considered, and somewhat tried to look for/look into (after maybe 6-12 month of on and off trying to figure out this project), was some type of “maker” workshop (I can’t remember my search terms, etc.) where there would basically be a service provided with people who’ve got the skill and ability who’d provide the service of writing code, and I guess also a “wiring diagram” and list of components for a “customer” to be able to make or complete their project.

I did find one source similar to what I’m trying to describe, but (1) I was wanting to do it myself, at the time, thought/hoped I could do it myself. And (2) the particular service sounded like it was maybe for much larger and more expensive projects or goals than what I was needing, ie: it sounded more like it was for aspring companies/businesses trying to produce a finished “product”, maybe. I could be wrong.

Also, I thought to myself over the course of this…journey, perhaps delusional, that if I had these skills (enough electronics/electrical engineering abilities), that this type of thing - this level of project - would be something I could and perhaps would do for a fee. Know what I mean? And this is sort of what made me think to look for such a service.
I’m sure EE’s demand quite a good wage/salary though (at least I would hope so), so, I duno if that’s realistic thinking or not. But like I mentioned, we’ve spend easily over $1500 on rodent related stuff over the last two or so years. But other’s in the area have spent about that amount just to have an Orkin/pest control company come and throw poison blocks in their attic or wherever (repeat visits, etc.).

Thanks for any insight.

I think what usually bothers folks when people ask for help are the same sort of ignorant questions that get asked on pot-growing boards. You know the type. It’s irritating to take time to help people that aren’t investing at least a reasonable level of effort.

You are different than those, and I’m spending several hours of my time to help you, because:

  1. You have thoroughly attempted to figure this out on your own. Just need a little guidance.
  2. You are trying the things suggested and reporting back.
  3. You are actually learning.

Absolutely, there are folks that help others with this sort of thing. Me for example or others in this thread. Pretty much anybody will help anybody genuinely trying to learn something. It’s across all parts of life. I’m willing to help an alcoholic who WANTS to stop drinking, but until that point it’s no use. I’m happy to share anything I know or have experienced with anyone that WANTS to hear it. But if they don’t, it’s a waste of effort on everyones parts. I’ll help you with anything you want, with an unlimited time ceiling and I enjoy doing it because you want to learn it.

I think the issue with having someone with lots of experience get paid to design something for you is the cost of qualified people to do so, as you have identified. Consulting, I’d be charging somewhere on the order of $150-250/hr, although generally I’d expect the work to be much more demanding. My day job is about all I’m interested in getting paid for anyway, at least anymore. It’s far more gratifying than the money to just share the knowlege for free. When I was younger and money was worth more than the time to me (funny how life and perspective changes things), I consulted all the time. Mostly much crazier things than a rat trap, which is a fun little project I think.

3 Likes

Try changing the pin, perhaps the LED is meant to flash on boot-up.

NOTE: I just tried a “blank” UNO here on my desk and it blinks on boot. Use a different pin.

1 Like

90% is for school/homework.

I you live in or near a big city they have maker groups that get together and compare notes etc etc. Personally I live way back in the sticks and am a self taught hobbyist.

2 Likes

In short: Changing from pin 13 to another pin seems to have fixed that issue.
Details:

Alright.
I decided I’d use pin 8 instead of pin 13. So I simply moved that jumper wire from the header’s pin 13 to pin 8.

Then I opened up the IDE. I changed my define LEDPIN 13 to define SOLENOIDPIN 8 (I change the pin number, as well as the name).
Then I used ctrl+f to find and replace all other instances of “LEDPIN” to “SOLENOIDPIN” (cool feature). I read through to double check that I got them all, though. (And I changed the old comments from ledpin to solenoidpin as well.)

I verified the code, then I connected the UNO and uploaded it. I disconnected from the laptop, then connected the 12v adapter (Note: the pin 13 led lit up and stayed lit up. This behaviour reminded me of when I was first playing with basics sketches like “blink”. I had to search internet to ask “why is my pin 13 led staying lit?”. I found threads where other newbs were asking the same thing. I remember the answer being along the lines of, sometimes it will do that, sometimes it won’t. And that you can upload a simple command/sketch to set it to LOW and default that led to “off”, or something if you don’t want it to do that. Anyways…)

Next, I broke the beam. The solenoid fired. Then I hit the ‘reset’ button and it reset the UNO without spazzing out! Success, I think. When I reset it, I also noticed that the pin 13 led (which was in a solid “on” state, as I said) blinked on and off three times. When I saw that behavior, I really felt as though that was definitely the root cause of the issue. I tried it a few more times. It seems to be working correctly now.

This was done with a 10K resistor on the SENSORPIN/pull-up, and a 1K on the LEDPIN (“SOLENOIDPIN” now)/pull-down. So, I removed both of those resistors to further test the ‘theory’ out, and it still worked just fine - no solenoid spazzing. Nice!

I actually feel like I figured something out, and did some level of troubleshooting (low level ‘educated guess’ work), haha.

Another observation: This rapid on-off doesn’t appear to happen when I plug the power adapter/UNO in. It only seems to be happening when I use the ‘reset’ button. Any thoughts on that?

Thanks again.

3 Likes

Hahaha! Man, that is pretty funny. I wouldn’t have probably guessed that, but now I totally see it.

That is impressive. How long would you say it took you to be “proficient” with it? And what was the initial motivation?

I don’t consider myself proficient but being retired I have plenty of time to read up on anything I need to know.
I started playing with avr/pic when I was working, I was a trucker and when I had nothing to do I spent it reading datasheets, teaching myself C since getting high was out of the question. Has been and still is a time killer that I also happen to enjoy.
The internet has the ability to make a dumbass like meself about 1/2 ass fluent in doing stuff I did not have the opportunity to do when I was a young buck

3 Likes