Newbie just tsrating, need help with a sketch

Hi, Im just starting out with my Arduino, but am enjoying. Does anyone know of any courses for begineers to follow online?

I want to write a sketch that will basically, start a loop, when a button is pressed, which basically has some LEDs going on and off and dancing about, and this loop to run for 1 moinute then stop, is that simple enough to do?

I then, later down the line woudl like to change the button pressed to a motion sensor if possible, and have that triggering the loop.

Any help or suggestiosn would be great!

Thanks
Darren

Hello
Take a view into the IDE to found some pretty examples.

1 Like

Arduino links of interest.

How to use this forum:

Getting started:
https://www.arduino.cc/en/Guide

Listing of downloadable 'Arduino PDFs' :
Either Google >>>- - - - > arduino filetype: pdf
Or
https://www.google.ca/search?q=arduino+filetype%3A+pdf&rlz=1C9BKJA_enCA739CA739&oq=arduino+filetype%3A+pdf&aqs=chrome..69i57j69i65.1385j0j7&hl=en-US&sourceid=chrome-mobile&ie=UTF-8

Listing of downloadable 'C++ PDFs' :
Either Google >>>- - - - > C++ filetype: pdf
Or
https://www.google.ca/search?q=c%2B%2B+filetype%3A+pdf&rlz=1C9BKJA_enCA739CA739&oq=c%2B%2B+filetype%3A+pdf&aqs=chrome..69i57.22790j0j7&hl=en-US&sourceid=chrome-mobile&ie=UTF-8

Arduino cheat sheet:
https://dlnmh9ip6v2uc.cloudfront.net/learn/materials/8/Arduino_Cheat_Sheet.pdf

Watch these:
Arduino programming syntax:
https://m.youtube.com/watch?v=CbJHL_P5RJ8

Arduino arithmetic operators:
https://m.youtube.com/watch?v=UUx0_s-ElSs

Arduino control flow:
https://m.youtube.com/watch?v=QpPGGuaGbCA

Arduino data types:
https://m.youtube.com/watch?v=xmZXWMEltEc

Understanding Destructive LC Voltage Spikes:
https://www.pololu.com/docs/0J16/all
OR
https://www.pololu.com/docs/pdf/0J16/destructive_LC_voltage_spikes.pdf

Why MOSFET gate resistors:
https://youtu.be/o0OHGWCZ7B0

Some things to read

LCD information:
https://learn.adafruit.com/character-lcds?view=all
OR
https://cdn-learn.adafruit.com/downloads/pdf/character-lcds.pdf?timestamp=1573085286

Reading a schematic:
https://learn.sparkfun.com/tutorials/how-to-read-a-schematic

Language Reference:
https://www.arduino.cc/en/Reference/HomePage

Foundations:
https://www.arduino.cc/en/Tutorial/Foundations

How and Why to avoid delay():
http://playground.arduino.cc/Code/AvoidDelay

Demonstration code for several things at the same time.
http://forum.arduino.cc/index.php?topic=223286.0

Multitasking:
Part 1:
https://learn.adafruit.com/multi-tasking-the-arduino-part-1?view=all

Part 2:
https://learn.adafruit.com/multi-tasking-the-arduino-part-2?view=all

Part 3:
https://learn.adafruit.com/multi-tasking-the-arduino-part-3?view=all

Sparkfun Tutorials:
https://learn.sparkfun.com/tutorials?page=all

Micro Controllers:
https://learn.adafruit.com/mcus-how-do-they-work?view=all

Useful links:
https://forum.arduino.cc/index.php?topic=384198.0

Arduino programming traps, tips and style guide:
http://www.gammon.com.au/forum/?id=12153

Arduino programming course:
https://startingelectronics.org/software/arduino/learn-to-program-course/

Jeremy Blume:
https://m.youtube.com/playlist?list=PLA567CE235D39FA84

Arduino products:
https://www.arduino.cc/en/Main/Products

Motors/MOSFETs
http://www.gammon.com.au/motors

Making a library
https://www.arduino.cc/en/Hacking/libraryTutorial

Switches:
http://www.gammon.com.au/forum/?id=11955

https://www.amazon.ca/Arduino-Cookbook-Recipes-Enhance-Projects/dp/1449313876/ref=sr_1_1?ie=UTF8&qid=1522801721&sr=8-1&keywords=arduino+cookbook

Share tips you have come across, 700+ posts:
https://forum.arduino.cc/index.php?topic=445951.0

Debug discussion:
https://forum.arduino.cc/index.php?topic=215334.msg1575801#msg1575801

Frequently Asked Questions:
https://www.arduino.cc/en/main/FAQ#toc10

SMD soldering:
SMD soldering

Number 'type's.

  • boolean (8 bit) - simple logical true/false, Arduino does not use single bits for bool
  • byte (8 bit) - unsigned number from 0 to 255
  • char (8 bit) - signed number from -128 to 127. The compiler will attempt to interpret this data type as a character in some circumstances, which may yield unexpected results
  • unsigned char (8 bit) - same as 'byte'; if this is what you're after, you should use 'byte' instead, for reasons of clarity
  • word (16 bit) - unsigned number from 0 to 65535
  • unsigned int (16 bit)- the same as 'word'. Use 'word' instead for clarity and brevity
  • int (16 bit) - signed number from -32768 to 32767. This is most commonly what you see used for general purpose variables in Arduino example code provided with the IDE
  • unsigned long (32 bit) - unsigned number from 0 to 4,294,967,295. The most common usage of this is to store the result of the millis() function, which returns the number of milliseconds the current code has been running
  • long (32 bit) - signed number from -2,147,483,648 to 2,147,483,647
    float (32 bit) - signed number from -3.4028235E38 to 3.4028235E38. Floating point on the Arduino is not native; the compiler has to jump through hoops to make it work. If you can avoid it, you should. We'll touch on this later. Sparkfun.

You select the 'type' best suited for your variables.

ex:

  • your variable does not change and it defines a pin on the Arduino. const byte limitSwitchPin = 34;
  • since an analog variable can be 0 to 1023, a byte will not do, you can select 'int'. int temperature;
  • if your variable needs to be within -64 to +64 a 'char' will do nicely. char joystick;
  • if your variable is used for ASCII then you need type 'char', char myText[ ] = {"Raspberry Pie Smells"};
  • if your variable enables some code then boolean can be used. boolean enableFlag = false;
  • millis() returns the time in ms since rebooting, unsigned long currentTime = millis();
    etc.

Oh, and have fun too :slight_smile: !

1 Like

Hello
Don´t hesitate to ask in case do you have issiues by the realization of you projects.
You will find many helpful people and don´t forget to post your sketch in code tags "</>".

Hi, so this is my very primitive code so far, sorry.

What I'd like is to have this loop run for 30 seconds and activated by a push button.

The idea is for it to sit on my desk and be pwoered by a battery, also is there anyway to factor in a power safe mode at all to try and save power?

Thank you!

D

/*
  Blinking LEDs - test program to run 3 LEDs in a pattern of blinks
*/

int led1 = 12;
int led2 = 11;
int led3 = 10;
int led4 = 9;
int led5 = 8;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led1, OUTPUT);   
  pinMode(led2, OUTPUT);  
  pinMode(led3, OUTPUT);    
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(180);                      // wait for 1/2 a second
  digitalWrite(led1, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(led2, HIGH);    // turn the LED on (HIGH is the voltage level)
 delay(180);                      // wait for 1/2 a second
  digitalWrite(led2, LOW);     // turn the LED off by making the voltage LOW
  digitalWrite(led3, HIGH);     // turn the LED on (HIGH is the voltage level)
delay(180);                     // wait for 1/2 a second
  digitalWrite(led3, LOW);      // turn the LED off by making the voltage LOW
  digitalWrite(led4, HIGH);     // turn the LED on (HIGH is the voltage level)
delay(180);                   // wait for 1/2 a second
  digitalWrite(led4, LOW);      // turn the LED off by making the voltage LOW
  digitalWrite(led5, HIGH);     // turn the LED on (HIGH is the voltage level)
delay(180);                    // wait for a second
    digitalWrite(led4, HIGH);      // turn the LED off by making the voltage LOW
      digitalWrite(led5, LOW);     // turn the LED on (HIGH is the voltage level)
delay(180);                     // wait for 1/2 a second
    digitalWrite(led3, HIGH);      // turn the LED off by making the voltage LOW
  digitalWrite(led4, LOW);     // turn the LED on (HIGH is the voltage level)
delay(180);                      // wait for 1/2 a second
     digitalWrite(led2, HIGH);     // turn the LED off by making the voltage LOW
  digitalWrite(led3, LOW);     // turn the LED on (HIGH is the voltage level)
delay(180); 
         digitalWrite(led1, HIGH);    // turn the LED off by making the voltage LOW
  digitalWrite(led2, LOW);    // turn the LED on (HIGH is the voltage level)
}

You are not doing your reading:

https://playground.arduino.cc/Code/AvoidDelay/



See this too:

https://code.google.com/archive/p/narcoleptic/

1 Like

Hello
Well, I think this is a school assignment published several times. Take some time and search in the forum. Don't the teachers have any new ideas?
Think of a solution without delay(), sooner or later a button will surely be added.

the chance to find an online-tutorial that is doing exactly your wished program-behaviour is very low.

Of course there are demo-codes and tutorials for similar things.

Just taking an example-code and trying to modify it without knowing the basics of programming is like shooting in the fog.

So to have some basic generalised knowledge about coding for arduinos is very good.
This is what this tutorial is doing:
Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

best regards Stefan

1 Like

Oh is it? I'm a 49 year old man trying to learn something new lol

Yes I think I need to produce this first step with delay but having trouble understanding adding multiple LEDs and combing their timings but I'll get my head around it eventually :blush:

@StefanL38 thank you! I'll give that a try and comment on how I found it but I think my grey matter isn't the best :joy:

Hello
It seems to be a small Knight-Rider sketch, isn´t it?

ah come on your brain-age is just short beyond highest performance. ;-))

I think you are better than "the ideal candidate for this tutorial"
(which is somebody who has never done anything with computers before)
best regards Stefan

1 Like

So, my effort here using the blink without delay isnt working;
is there anytjing wrong int he code?

Or....is it do to with my circuit? but the circyit works on the previous code I posted with delay.

// SETTING PIN NUMBER

int GREEN =  12;// the number of the LED pin

// THIS WILL CHANGE
int LAMPSTATE = HIGH;         

unsigned long previousMillis = 0;      

// constants won't change:
const long interval = 1000;  

void setup() {
  // set the digital pin as output:
  pinMode(GREEN, OUTPUT);
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the difference
  // between the current time and last time you blinked the LED is bigger than
  // the interval at which you want to blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (LAMPSTATE == HIGH) {
      LAMPSTATE = LOW;
    } else {
      LAMPSTATE = HIGH;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(GREEN, LAMPSTATE);
  }
}

Ahhh yes O suppose it coudl be described as that - but its for an old aircraft indicator lamp i picked up off ebay - thought it woudl be cool to learn on and have on my desk :slight_smile:

I don't see anything wrong with the code - check your wiring.

yes so my other thought is that, does any of this make a difference...?

The nano board is being used to ground the earth to connect the circuit, does that make sense? the circuit worksif i use the delay sketch, without touching the circuit

Your old code is doing multiple LEDs. Perhaps the light is connected to a pin other than twelve.

There are 5 rows of 4 LEDS in 12, 11, 10 , 9 , and 8 so in theory any should work, but it's going to an array as they are being driven by anothr power source, so the grounds are completing the circuit, i hope this make sense lol
I've created some Frankenstein of a circuit probably

I changed the IO-pin-number from 12 to 13 this means that the onboard-LED of an arduino Uno is switched on off. Your sketch works as expected one second LED on one second LED off

Do you have multiple microcontrollers connected to your computer?
If you flash the code (upload the code) what is the message you see after falshing hast finished?

best regards Stefan

Yes if i change it to 13 the onboard led flashes
which makes me think its something with the circuit, this is the circuit