Hall effect sensor controlled LED strip

Hello, I have a question about adding a hall effect sensor to my project. I am 11 years old so advanced Arduino is still a little too hard for me.

I finished this project for a battery powered LED strip: http://www.instructables.com/id/PWM-an-RGB-LED-Strip-with-Arduino/?ALLSTEPS

I want to build on this plan and add a hall effect sensor so the lights can be turned on and off with a magnet. My idea is to have a strip of lights that will turn on when you touch the sensor with the magnet, then turn off when you touch it again with the magnet. I don't want something that will turn off when you move the magnet away. I did my research and it looks like I need a latching hall effect sensor. Is this right?

I have never written code before but am willing to try if I need to. I'm just not sure how to add a hall effect sensor to that Instructables project (or if I can at all). Will I need to write a whole new code or can I add something to the original code? If anyone can help I would be very happy! Thank you very much!

IMHO better start writing the code from scratch.
You will learn a lot and probably find a new hobby :slight_smile:

I am 11 years old so advanced Arduino is still a little too hard for me.

I did my research and it looks like I need a latching hall effect sensor. Is this right?

No.
Why ?
Look at this tutorial about a momentary push button switch and led, neither of which , by itself is latching, yet when the two are put together with some code, the result is a latching led. If you said you wanted to do what this sketch does and asked if you needed a latching led , what would the answer be ?

I have never written code before but am willing to try if I need to.

You have the rest of your life to learn. There's no better time to start than now. The sooner you get started, the sooner you'll know what you're doing.

My idea is to have a strip of lights that will turn on when you touch the sensor with the magnet, then turn off when you touch it again with the magnet. I don't want something that will turn off when you move the magnet away. I did my research and it looks like I need a latching hall effect sensor. Is this right?

No, you don't need a special hall effect sensor.

Your software (your Arduino "sketch") "knows" if the LEDs are on or off. So, you just need to change the state whenever the magnet is detected.

I recommend that you start-over without the Instructables code. Figure-out how to detect the Hall Effect sensor and turn an LED on & off first. And, the easiest thing to do is use the Pin-13 LED that's already on the board. Then, maybe you can mix your new code with the Instructables code.

I'd also suggest you figure-out how to do this with a plain-old switch before adding the Hall Effect sensor (a momentary switch would best-simulate the Hall Effect sensor). With any project, you've got to break it down into manageable parts.

The trick to what you are trying to do is an [u]if-statment[/u] and some other logic... In English, "If the LED is on AND the Hall Effect sensor is detected, turn it off... If the LED is off AND the Hall Effect sensor is detected, turn it on." Of course, the computer doesn't understand English, so you have to translate that to C++. :wink:

The two concepts that make programming really useful are Conditional Branching (if-statements and other similar logic that makes it possible for a computer to "make decisions") and Loops (doing thing over-and-over, often until some condition is reached.)

I don't want to scare you , but programming is NOT easy! Yeah, it's easy to make an LED blink, and the Arudino is a pretty good way to learn some basic programming, but a 4-year Computer Science degree is pretty-much a "programming degree". And, professional computer programmers make more mistakes in a day than most other professionals! Because, it ain't easy! :smiley: And with the the Arduino, you've got to learn at least some electronics too, and that's a whole different subject!

I suggest you read-through the [u]Programming Reference[/u] to get an idea of what the basic functions do. There's not a lot to it, but you won't understand it all the first time through (and you won't remember it all) but it's still a good idea to read-through it a couple of times. Technical subjects are like math... You could probably read your math book in a week, but you have to read it several times and try-out the problems, and it takes a whole semester before you understand it all.

And try some of the simple examples (depending on what hardware you have) and try to understand how the code works (and how the hardware works). I assume that you don't understand all of the code in the Instructables example, and that's OK... Start with something simpler.

When you do start writing your own code, start with a basic "framework" program like the Blink LED example. I almost always start with that. Then, write one or two lines of code at at time and compile & test before continuing. If you try to write the whole program at once, it usually won't work. You can have one little error and the compiler might give you many error messages that don't make sense to you. The compiler doesn't know what you are trying to do, it just knows that what you are doing doesn't make sense in C++.

Besides making sure that there are no syntax errors (things that don't make sense in the C++ language), you can have logical errors. In other words, the program may run but it doesn't do what you want.

One thing that's really helpful for testing & debugging is to send messages to the [u]Serial Monitor[/u] so you can "see" what the program is doing. For example, you can send out a message that says "start delay", and "end delay", etc.

The biggest mistake beginning programmers make is to try and write the whole program at once. But, it's not as easy as writing the lines in-order... For example, if you erase the last half of an existing program, it won't compile. You have to "build' or "develop" your program in a way that it always makes sense, especially in a way that makes sense to the compiler.

Of course, experienced programmers write more than one or two lines at at time, but they are usually working on big programs so they don't write the whole thing at once... They develop, debug, and test, one section at a time.

P.S.
You'll probably find that you need to [u]debounce[/u] your Hall Effect sensor. To a human, it might look like it's turning on & of "cleanly", but at some point it will be "half-on" and if the processor is reading the sensor a few million times per second, it might read 100 on/off cycles and your program may not behave as expected.

That's one of those things you don't have to start with... You can add the debouncing as you "develop" and debug your code. The easiest thing is to simply add a little delay (probably a few milliseconds) each time through the loop.

Most of the advice given so far is good advice, but I'll add that there's nothing to be afraid of when writing code. You can't break an Arduino by putting in the wrong code! The code will just not work or not work as you expected and making mistakes is a good way to learn how not to do it and, eventually, how to do it correctly. If you get stuck, there's always this forum to help you out., and, depending on where you are, there are local user groups who can also help you. Good luck.

You asked what you needed to do to add the hall effect sensor. I gave you a link to how to do the same thing with a led. All you have to do is figure out how to read the sensor and use that in the code that toggles the led and replace the led with the light strip output code.