Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Arduino college project

  • 25-11-2016 7:54pm
    #1
    Registered Users, Registered Users 2 Posts: 61 ✭✭


    Hi All.

    I have been given a college project to write arduino code and build a circuit that performs the task that the code specifies. Trouble is that I am poor at this and have a week to get it done. It involves coding a switch to be pressed which counts down from 5 seconds. Within the 5 seconds 2 more switches have to be pressed together to make a motor turn on. Otherwise system resets.

    I have attenpted to write the code but I keep getting errors. How do I get this done?

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 1,435 ✭✭✭Big Lar


    So many different ways to do it.
    If I was doing that now I would use the first switch to call a while loop relying on the Timer.h library set to 5 seconds and a simple if statement within the while loop that if the other two switched were pressed that would enable the motor.


  • Registered Users, Registered Users 2 Posts: 61 ✭✭michealkc


    Big Lar wrote: »
    So many different ways to do it.
    If I was doing that now I would use the first switch to call a while loop relying on the Timer.h library set to 5 seconds and a simple if statement within the while loop that if the other two switched were pressed that would enable the motor.

    Hi Big Lar

    Thanks for the advice. Would the arduino website be the best place to look for getting my head around what each line of code means. I have to learn this from scratch with no previous experience. Any good advice that helps me out is greatly appreciated.

    Regards
    M


  • Registered Users, Registered Users 2 Posts: 1,435 ✭✭✭Big Lar


    Yep start there on the andruino forums. If you don't have an arduino there are plenty of simulators online where you can test out your sketch


  • Registered Users, Registered Users 2 Posts: 61 ✭✭michealkc


    Hi All.

    Anybody know of any people who can instruct me on arduino. Even trouble shoot.

    Thanks


  • Registered Users, Registered Users 2 Posts: 854 ✭✭✭human 19


    out of curiosity, what language are you to write it in?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 70 ✭✭Jimllfixit


    human 19 wrote: »
    out of curiosity, what language are you to write it in?

    Hi Micheal,

    Best to write in the Arduino code that comes with the Arduino "IDE" software download:

    https://www.arduino.cc/en/Main/Software

    - this code is a flavour of "C".

    The IDE allows you to verify your code for basic sytntax errors.

    But go back a step or two:

    1: Get the pdf of the schematic for the Arduino board you propose to use. (I use an "UNO") The boards are all different and code written for one board won't necessarily do what you want on another.

    2: Figure out out what your hardware circuit will be. It sounds as if you need some switches, and perhaps a LED to pretend to be a motor. (You could drive a real motor if you had a MOSFET and a power supply).

    3: Wire up the hardware. The easiest way is to hook up a prototyping breadboard to the Arduino with insulated single-strand wires. The switch is tied to an input/output pin (you choose in or out when you write the program).

    4: Write out in longhand English EXACTLY what the programme is to do. Every detail no matter how trivial. Sounds boring but it provides a firm basis for the rest of the project.

    5: Now create a "Flow Chart" of the English you just finished. Most people throw their hands up at this point and say "this guy lives in pre-history" "why waste your time" etc etc.

    DON'T LISTEN TO THEM!

    The flow chart is how you start to transfer your ideas into code. Trust me.

    6: Now open a "Sketch" either as a test file or in the Arduino IDE and write lines of comments for each step in the flow chart. The comments must be very simple and say exactly what the code instruction is doing. Each line starts and finishes with a "/" character. Most people throw their hands up at this point and say "this guy lives in pre-history" "why waste your time" etc etc.

    DON'T LISTEN TO THEM!

    Unles you comment your code religiously, you will lose the plot, especially when you come to look at it the next morning. And why not put the comments in first? Trust me.

    7: Now write the code. By this time, you SHOULD know how the instructions in the code line up with the comments, which tell a third party what is supposed to be happening. Or you, a day later.

    8: Verify the code in the Arduino IDE and pull out any typos.

    9: When you get your Arduino e.g. UNO, hook it up to your breadboard and plug it in to your PC or laptop with an ordinary USB printer cable. It will tell the PC what it is and the PC will hunt for driver software the first time. You may need to poke into the Arduino Tools menu and check that it is connected to a COM PORT other than COM1.

    10: Then "Upload" the code using the Arduino ID. (It always verifies as well before uploading; you'll know it is uploading because the yellow Tx & Rx LEDs light up briefly on the board).

    11: When it has finished uploading, the code will start to run. Your program may need to do something like "Poll for a switch press" to start off with, so that you know you have to press the switch to make things happen. There is an on-board LED connected to pin 13 that is very handy to flash on and off, to indicate for instance, that the program is waiting for you to do something. A bit like a cursor.

    This post may be too late for your project although I'd be surprised if you could pick up Arduino AND prgramming in one week! I'll paste it into a word document for future use. Arduino information is all there but I've rarely found any structure to it myself.


  • Registered Users, Registered Users 2 Posts: 70 ✭✭Jimllfixit


    There's a built-in example of detecting a switch here:

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


  • Registered Users, Registered Users 2 Posts: 70 ✭✭Jimllfixit


    and your "motor" can be a LED:

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

    attached to a pin of your choice (don't forget to add a serial resistor).


  • Registered Users, Registered Users 2 Posts: 70 ✭✭Jimllfixit


    and you may wish to have a third LED (a red one) to show that your system became reset. This LED only goes out when you press your switch to restart.

    and it seems you need three switches: one to start the program, and two more that you have to press together to prevent it resetting etc.

    (There is also a Reset switch on the UNO that restarts the program from zero, for instance, if your code goes into an endless loop by accident).


  • Registered Users, Registered Users 2 Posts: 70 ✭✭Jimllfixit


    Well, that was great! We never found out if yer man ever got his Arduino project started let alone finished.
    That's the last time I'll ever waste time trying to help.


  • Advertisement
Advertisement