Total NOOB sorry :-) Love someone on board, for a small project please ?

Hi,
Only got a Nano yesterday,. No programming or electrical skills.
Baring understanding how to add sketch and run, basic LED flash and timing.
Have used 2 and 4 channel 433mhz RF in past, works great via remote.
But Now like to move onto better things.
Being 54 lol way too much for my brain cell to take in :slight_smile:

OK what im looking for, is to start the Nano sketch, by a small sensor.
Led comes on say 1 min, then flashes a few times various sequences for another 2 mins.
During this time, need to operate 2 mini linear stepper motors, as well as an actuator, and incorporate some sort of micro music player.
Full duration 2-3 mins

Any help would make an old man happy :slight_smile:
Regards

Hi there! I don't have any experience with all the hardware you mentioned but I can give you some advice as a starting point for your project.

start the Nano sketch, by a small sensor.

What exactly do you mean with that? When you power an atmega microcontroller (what your Arduino uses) the first piece of code that runs is something called a bootloader which then passes control over to your sketch.
Normally you can't really "start" an Arduino sketch using a sensor's output, but you can trigger an interrupt or wake the Arduino from sleep if that's what you want. What exactly are you trying to accomplish? Be more specific.

Led comes on say 1 min, then flashes a few times various sequences for another 2 mins.
During this time, need to operate 2 mini linear stepper motors, as well as an actuator, and incorporate some sort of micro music player.

Again, you will likely run into issues because an 8-bit AVR like what your average Arduino board has, does not support multitasking. It can only do one thing at a time. You can get around this by using millis() and there is a great tutorial on the subject if you are interested. In my opinion just do one thing at a time and start out with the basics.
Not to mention the stepper motors and the music player which will likely require additional libraries that you need to get familiar with. Just test each thing separately and then when everything is working you can try merging them. I said that because you mention it's your first project. I think it's too big for a first project so to speak.

Hope this helped you!

Normally you can't really "start" an Arduino sketch using a sensor's output

An alternative to the suggestion to start from sleep is to let setup() run, and then as setup()'s last line have a while() in which it sits reading the sensor, and when the reading is acceptable, pop out of the while() and hence out of setup() into loop().

void-basil:
An alternative to the suggestion to start from sleep is to let setup() run, and then as setup()'s last line have a while() in which it sits reading the sensor, and when the reading is acceptable, pop out of the while() and hence out of setup() into loop().

Yeah that is a very good alternative. But in my opinion depends on what OP is trying to accomplish. There are a few ways to do that and the OP might even be able to get away just by using an if statement.

WOW thank you for the replies much appreciated...
Understand wasnt too clear, didnt want to go too deep at the moment.

Sorry for being so naïve, as mentioned only got into this yesterday, so way over ones head so patience needed :slight_smile:
Ok Im a magician, came up with a few items, unable to attach a clip.
But if like to view test piece

Now needing to move to Arduino, for more exciting stuff :slight_smile:

So what i gather then, unable to really start sketch via remote, sensor or switch? just by the white button on the Nano, so have a pause timer? But the Nano be hidden no access.
Guess by now most will have given up :slight_smile:

Bare with me will try and be little more specific.
As i be giving a lecture, 3 mins into it, the item needs to start automatically, with any of the mentioned methods.

I will try and sketch out items used etc. and be little more specific.
Thanks again guys...

So what i gather then, unable to really start sketch via remote, sensor or switch?

Yes you can, just like I said earlier.

You could (just as a f'rinstance) have an ultrasonic sensor reading in a while() loop in setup(), and when it detects you getting close (like maybe waving your hand in range?) it will hop out of the while(), out of setup(), and into loop() to do the thing.

Nobody has given up!
If you answer the questions below I guess that your problem will (likely) be solved:

  • What you want to accomplish with your Arduino board?
  • What's your project idea?
  • Do you have any experience in using any of the items you bought?

void-basil:
Yes you can, just like I said earlier.

You could (just as a f'rinstance) have an ultrasonic sensor reading in a while() loop in setup(), and when it detects you getting close (like maybe waving your hand in range?) it will hop out of the while(), out of setup(), and into loop() to do the thing.

Sitting in a while loop in void setup doing nothing except of wasting clock cycles seems like a bad idea to me. You could use those wasted cycles to perform another operations if you want. Basically in my opinion the most efficient way is to use an if statement but again this depends on what you want to do, something you didn't make clear.
The term "remote sensor" does not make any sense to me. Do you mean a remote control module like an NRF24L01+ OR do you mean a sensor that is just far from the Arduino but hard wired to the board?
Let's give you an example to clear things:
I will assume you have a generic DHT22 temperature and humidity sensor and you want to start the sketch only if the temperature rises above 30 degrees.
Mainly there are two approaches to do that, each with its pros and cons:

Approach #1 (While loop, as void-basil suggested)

#include <DHT.h>   //Includes the library needed for the Arduino to communicate with the sensor. You do that so there is no need to reinvent the wheel.

DHT dht(3, DHT22); //DHT sensor type is DHT22 connected to pin 3

void setup() {
  dht.begin();     //Initializes the DHT sensor

  while (dht.readTemperature() <= 30) {
    //Do absolutely nothing
  }
}

void loop() {
  //Your program will run here
}

This program just gets stuck in the while loop doing nothing if the temperature is less than or equal to 30 degrees celsius.

Pros:

  • Simple and easy to understand / implement.
  • Less power consumption since the MCU will do nothing (also achievable in an if statement).

Cons:

  • Inefficient
  • Can't do more than one thing
  • Stuck in setup
  • Doesn't make any sense to me and the list goes on...

Now for a really simple task this is all you need. However there is a different approach too, that is my recommendation.

Approach #2 (If statement)

#include <DHT.h>   //Includes the library needed for the Arduino to communicate with the sensor. You do that so there is no need to reinvent the wheel.

DHT dht(3, DHT22); //DHT sensor type is DHT22 connected to pin 3

void setup() {
  dht.begin();     //Initializes the DHT sensor
}

void loop() {
  if (dht.readTemperature() <= 30) {
    //Do absolutely nothing
  }
  else {
    //Your program will run here
  }

  //Your second program can also run here
}

Whenever the loop is run, the if statement is too. It basically means that if temperature is less than or equal to 30, it does nothing and if that condition isn't met (for example temperature is more than 30) it goes to the point where it says "Your program will run here". When it finishes that task it continues over to the second program and then the loop repeats an infinite amount of times...

This is a slightly different and more compact approach by just inverting the condition that has to be met, therefore eliminating the need of an extra else statement. In short, understand it and use that one instead. It's better.

#include <DHT.h>   //Includes the library needed for the Arduino to communicate with the sensor. You do that so there is no need to reinvent the wheel.

DHT dht(3, DHT22); //DHT sensor type is DHT22 connected to pin 3

void setup() {
  dht.begin();     //Initializes the DHT sensor
}

void loop() {
  if (dht.readTemperature() > 30) {
    //Do absolutely nothing
  }

  //Your second program can also run here
}

Pros:

  • Doesn't get stuck in a while loop.
  • You can do more things if you like.
  • It's expandable.
  • It's the preferred way in general.

Cons:

  • From my perspective, absolutely nothing.

Thanks for taking the time to read through all of this. I hope this helped you a bit!

Sitting in a while loop in void setup doing nothing except of wasting clock cycles seems like a bad idea to me. You could use those wasted cycles to perform another operations if you want.

What's the difference between sitting picking its nose in a while() in setup() or loop()-ing doing nothing, when there is nothing else that needs to be done? In this case, OP made it clear there's nothing else to do, zie simply wanted the Arduino to "wake up" and start the show. In other circumstances I'd agree with you, but you yourself said earlier it depends what the OP actually wants to do, and zie clarified that. My solution fits that need.

BTW (not that it really matters) my suggestion of holding a sketch at the bottom of setup() pending some or other "start signal" is at least as old as #1 here:

https://forum.arduino.cc/?topic=257300

Thanks all, much appreciated.
Items for project? Arduino Nano, 10mm 3v LED 5v linear phase 4-wire Mini Stepper Motor & (Stepper Motor Driver - A4988) ??(could do away with this and just use 3 x 12v solenoids
push / pull 10 mm DC 12v solenoid & (IRF520 MOS FET MOSFET Driver Module). ??
Either remote, reed switch toggle switch, what ever is easiest.
Resistors 100/150k
(Sorry cant divulge info that its going into at the moment, please there's no disrespect).
I be doing a talk, 3 minutes in, the item kicks in action.
LED comes on (3 mins duration, flashes, stays on random)
Music player plays. During this period, solenoid with be activated, push pull 6 times.
After 4 push pulls other solenoid with push once.
3rd solenoid, push pull random times through the 3 min duration of the effect..
Hope this is a little clearer? Obviously i can mess with timings so no big deal, just to mash it all together :slight_smile:
Think i have gone overboard, and going to be real complex, also not sure on wiring to Nano :frowning:
Thanks again...

void-basil:
What's the difference between sitting picking its nose in a while() in setup() or loop()-ing doing nothing, when there is nothing else that needs to be done? In this case, OP made it clear there's nothing else to do, zie simply wanted the Arduino to "wake up" and start the show. In other circumstances I'd agree with you, but you yourself said earlier it depends what the OP actually wants to do, and zie clarified that. My solution fits that need.

Okay I didn't understand that. Then your solution is more than enough for such a simple problem.
I just listed every possible solution because I know that the OP might not know yet what he needs or what he can achieve since he stated that is a novice.

However, it is noteworthy that the OP needs to reset the Arduino if he wants to deactivate the sketch. If he uses the if statement then the only thing he needs to do is just to flip the switch and the sketch is over. If he puts it into setup then the Arduino needs to be reset.
If for some reason the if statement needs to be avoided, I suggest you to place the while loop inside void loop so that it repeats.

lefterisgaryfalakis
Appreciate your time and patience thanks.
Sorry not been too clear.

Will need to do lot of work, honestly, this was a pipe dream to sort, clutching at straws on last effort on here :-).
Have number of the items, will just try and wire one at a time, and try get head round a bit of it.
Did find this on youtube, which actually did auto stop the blinking., but to start the blinking with delay.
So press button or what ever, will delay for 2-3 mins then set it off...

int ledPin = 13;
int blinkTime = 100;
void setup()
{
pinMode(ledPin, OUTPUT);
blinkyBlinky(20, blinkTime); // 20 is number of blinks, blinkTime is the milliseconds in each state from above: int blinkTime = 500;
}
void loop()
{
//
}
void blinkyBlinky(int repeats, int time)
{
for (int i = 0; i < repeats; i++)
{
digitalWrite(ledPin, HIGH);
delay(time);
digitalWrite(ledPin, LOW);
delay(time);
}
}

Hi there again!
No it's not an issue, don't worry!
I just somehow wrote a complete answer and the forum never published it... :o :o

Basically I was trying to say that you need to rework some aspects of your project.
For example the IRF520 is not suitable. You need a logic level MOSFET as the other one won't be fully saturated and thus create heat as a result of wasting energy... Also make sure it has a pulldown resistor as well as a gate resistor to the Arduino GPIO just in case...

The solenoids will cause inductive spikes that can damage your Arduino board and other stuff in parallel to the power line too. You need to use a flyback diode for each solenoid to be on the safe side. Not using it can also have quite ackward results like for example making your Arduino glitch / freeze / whatever.

You didn't mention what MP3 module are you using and how it connects to the Arduino. Does it require a library?

The stepper motor controller, can (according to its datasheet) handle up to 0.8A. Are you sure you are well under this limit?

Have you bought the parts?

I hope I will be able to get you out of this difficult situation... Just note that you should take my advice with caution and a grain of salt because in case you don't know I'm just a 15 year old guy who somehow ended up on this forum. What I say might be correct but also might not. Do your research in any case! :smiley:

15yr old lol, wow, impressive. closest thing i got to a pc at your age was a calculator, the size of a brick.
Ok items currently have the Nano
MOS FET Trigger Switch Driver Module PWM Regulator
Operating Voltage:DC 5V-36V
Trigger Signal Source: digital high/low level (DC 3.3-20V),can connect with MCU IO port, PLC interface, DC power etc; can connect with PWM signal; support signal frequency 0--20KHz.
Output Power: DC 5v-36v, room temperature sustained current 15A, power 400W! Auxiliary cooling conditions, the maximum current can be up to 30A.
Operating Temperature: -40~85 Celsius

DC12V ZYE1-0530 0.4N Push-Pull Open Frame Solenoid

Model:JF-0530B
Rated Voltage:DC 12V
Rated Current:300mA

Enough resistors etc.

Stepper motor just from out of an old cd/dvd player.
Obviously need a stepper motor driver?

Thanks again...

Closest thing i got to a pc at your age was a calculator, the size of a brick.

Haha yeah! It's impressive to see how things have changed in the span of only a few decades. Information is very easily accessible now and I think that if it wasn't for the internet the modern generation would know a fraction of what you knew at my age...

To the point:
Your MOSFET is an IRF520. It's datasheet says it all. Just look at the 3rd page and find the gate-to-source voltage / drain current characteristic curve. 5V is next to nothing for such a MOSFET. The gate threshold is the minimum voltage required to activate a MOSFET, not to fully saturate it. That said your solution will work, but it's not ideal.

The solenoids are perfectly fine. It's just that you are not driving them the proper way. You need flyback diodes in parallel... Just google the term "flyback diode" and you will learn why it is so important. Fundamentally it's just something like a relief valve for the coils that solenoids typically have.

Make sure you both have 200Ω and 10kΩ resistors handy as you will need them for the MOSFET.

Stepper motor just from out of an old cd/dvd player.
Obviously need a stepper motor driver?

Yeah, you need one. Apart from that, it has to be suitable for the current rating of the stepper motor and vice versa. Do you have its part number?

Lefteris

Hi.
Unfortunately no numbers, but should be similar to this.. and what it looks like Ta...

brinamo:
Hi.
Unfortunately no numbers, but should be similar to this.. and what it looks like Ta...

Assuming that you can solder on that ribbon wire then it seems ok. I'm not sure about the wiring but this setup has been attempted before. You might be better off buying something like that which has the control board included.
Otherwise you just have a 2 phase stepper motor and you can see tutorials on how to control it online.

Aye thanks, as mentioned may just use 12v solenoid, get the same effect, be easier also....
Aye soldering's pretty good.

Cheers
..

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.