Computer Shopper (UK) Feb 15 Article

There has just been a great bit of publicity for Arduinos. It is an article, just out, (early Dec 14) in the "Feb 15" issue (number 324) of the UK magazine "Computer Shopper". (computershopper.co.uk)

But they WAY overcomplicated the issues of reading light levels. I hope you will find this thread if you are reading the article, trying to use the article to get started with Arduinos. Arduinos are NOT that hard! And a lot of fun. And the project is an excellent one for a beginner.

Before I turn to that... four little things....

a) The diagram of the Micro's pins (top of page 138) is "upside down", relative to all the breadboard diagrams. You'd already noticed? Good.

b) You really, really do want to get a breadboard. Silly to call that "optional". A small one will do, but get one. Medium size, if you aren't pinching every penny!

c) BEWARE: The Arduino Micro comes in 5v and 3v3 versions. If in doubt, get a 5v one... and then certain things in the article don't need tweaking. If you already have the 3v3 one, don't worry... not the end of the world.

d) Parts supplier: Do you think that there might be a hint for you in the name of the featured supplier, "ThePiHut.com"? I have nothing against them, I've never done business there. But the fact that I couldn't find a way to search the site for an LDR didn't encourage me.

In the UK, I like hobbytronics.co.uk (and they have LDRs... 60p. LDRs will do in place of the £4, complicated, light sensor suggested in article) In the US, I like Sparkfun.com or ModernDevice.com

Yes! They charge you more for, say, an LED, than you would pay (unit price) for one in a bag of 50 from any of a dozen eBay sources... but the things they sell WORK, you have a nice, easy shopping experience, you don't have to place multiple orders (or wait for long deliveries, in some eBay cases.) Up to you. Maybe I have more money than sense. YOU try selling bits and pieces to hobbyists... the hobbyist suppliers EARN the (modest (in my view)) premium they charge.

=== Moving on to the important, but less simple point:

The article might, I suspect, leave a beginner a bit confused about the issues of sensing the light level. (This feature was made part of the project so that the automatic hallway light doesn't come on during the day. A nice feature!)

For a start: DON'T (as a beginner) connect ANYTHING to the ARef input (pin) of the Arduino. You don't need to! And if you do, but do it wrong/ fail to do other things right, you will harm your Arduino. (How you get around the need for the connection to ARef to come.)

For a start, it is simply not true that... "... you can't feed {an analogue input} directly into {an} Arduino" (As most readers of this forum will know. But remember, this post is trying to help newbies who have seen the article from which that quote was taken. (I should add here that I am a long-time reader, and ardent fan, of the magazine. It was great that they did an Arduino article at all, and, as a new venture for them, a little glitch is forgivable in my mind. General standard of content: High and useful.))

Even a simple Arduino has 6 built in ADCs (analogue to digital converters), and the software is aware of them, has native functions to access them.

=== So. How would I give the Arduino a way to sense the light level? I'd use a simple LDR (light dependent resistor... 60p from hobbytronics.co.uk. Beginners might want to avoid the (slightly) fancier "photo-transistor"))

An LDR has two leads. And it is not polarized. (It doesn't matter which "way" you "plug it in".)

Connect one end of the LDR to 5v (Or 3v3, if using a 3v3 Arduino), other end to both...

1) one of the Arduino's analog inputs, A0, to follow the article's suggestion, AND 2) the "top" end of a resistor (I'd try 10k... 10k would "work". Don't go below 1k until you know what you are doing. If the resistor is too big, the reading on the analogue input won't change much as the light levels change)

Connect the other end of the resistor to ground.


That's AWFUL, as text only. Pretty pictures, and more detail, at my page...

http://www.arunet.co.uk/tkboyd/ec/ec1senslight.htm


Anyway... connect up the LDR and resistor and Arduino as above, and you're done. NO WIRE TO ARef pin of Arduino from anywhere. No danger of frying Arduino.

And to use the light level in your program:

Just do something like....

int analogPin = 0; // LDR voltage divider (middle terminal) connected to analog pin 0 // outside leads to +5V and ground int iLightLevel = 0; // variable to store the value read

void setup() { //nothing needed here }

void loop() { iLightLevel = analogRead(analogPin); // read the input pin //And then use the value as you wish. e.g... // if (iLightLevel>500) {//turn LED on} }

==== Whew! Only one quick thing left:

If you have NOT connected anything to the Arduino's ARef pin, (or disconnected it, if you had done so) and you have a 5v Arduino, I can't see why you shouldn't (despite article's warning) "play" with your circuit, with an LDR or the article's suggested light sensor, before next month's article. (If you have a 3v3 Arduino, and a little confidence in what you already know, the same thought applies.)

My quick intro to reading analogue inputs should give you help. If you are very new to programming, I will immodestly suggest...

http://sheepdogguides.com/arduino/FA1main.htm

=== I hope that was of interest? Helped someone? Please "like" (Facebook or GooglePlus) one of my Arduino webpages, if you want me spending my time thus?

Hi, I used to read that mag years ago, even had a couple of articles in it. But I thought it died years ago. The photo dealer I worked for started selling home computers, so I got to play with Sinclair Spectrums, lynx, Dragon 64 and a very nice Nascom, etc.

Good times, good memories, unlike my own which is fading..

Regards

Mel.