Go Down

Topic: Switch using ground (Read 5033 times) previous topic - next topic

Cooptech

Hello All,

I have an 6 LED board that uses the ground to switch between three stages of; one on, three on, and six on. I am using an ambient light detector to tell the LED's when to use these stages, as it gets darker the light arrangement gets brighter.  I'm assuming I could use the digital out on the MEGA to send the signal, but how do I send a signal of ground vs no connection?

I need code fragments for three pins, ground, VIN, and signal using either digital (or analog if I'm wrong). I will understand how to reassign the pin assignment values in the code.

Thank you for anyone that can help.

Paul__B

Well now, if you have read the forum instructions you should realise that you need to
  • Post your present code (such as it might be) as well as
  • A schematic (hand drawn will generally suffice but "Fritzing" diagrams are frowned upon with prejudice as they tend to more accurately represent how you imagined you wired it rather than how you really did) and
  • Perfectly focused photographs showing every part of your assembly in good light (outside daylight generally necessary) and which allow individual wires to be accurately traced.
And - please do not use the "Attachments and other options" function below the Preview window as due to a current problem with the forum software, for many people, such links are either troublesome to use or entirely unusable.  Code should be embedded in the text using the "code" tags (the first icon above) and Image links using the corresponding icon, as links to a reputable image storage site (imgur seems to be generally usable).

PaulRB

#2
May 25, 2015, 03:27 pm Last Edit: May 25, 2015, 03:33 pm by PaulRB
how do I send a signal of ground vs no connection?
Hi, I assume you mean these leds have a common anode, which you connect to 5V, and 3 cathode connections, which you wire to ground to get each group of leds to light? As Paul__B says, we need more from you, otherwise we might give bad advice because we are having to guess.

If I am assuming right, then an Arduino output provides a connection to ground, through itself, if you set the pin to pinMode(x, OUTPUT) and digitalWrite(x, LOW). This will allow current to "sink" to ground through the Arduino pin. If you set digitalWrite(x, HIGH) or pinMode(x, INPUT) then it will not sink any current.

Before you wire anything up, you  need to know how much current will flow from these leds. The Arduino outputs can only deal with around 25 to 30mA (maximum 40mA for short periods, but this should be avoided because it will reduce the life of the chip). So if your leds need more than that, then you will need to use a transistor between the Arduino pin and the leds.

Another important question is does the board contain series resistors? If not, you will need to connect them off-board, to prevent too much current flowing through the leds and damaging them.

Paul (the British one, not the Australian one)

Cooptech

CRAP, busted, I thought it was the typical, don't spam, don't harass jargon, that's why I didn't read the "how to use" section. I apologize.

I am using the ambient light sensor code to detect light and send a signal based on values.

for example, four arbitrary values for the sake of helping me (I haven't metered the actual values yet)

1000 for daylight (light off)

1500 for dusk (one LED on)

2000 for second set of LEDs on

3000 for dark (All LEDs on)



I am getting power from a 12v battery regulated to 7 volts, the board is powered to 5v through a separate regulator same battery.

Three wires, ground, power and signal (the signal wire being a simple ground switch)

Ummm code and schematics will be hard, I don't have code for the then statement, I guess that's what I'm looking for...

The signal the LEDs use to run off of was a ground interrupt push button. I just need to know how to ground interrupt on an if statement

if (ambient sensor) reads 1500 THEN interrupt ground on Dpin 52

I hope this clears up what Im looking for
 

Cooptech


if (someCondition1500) {digitalWrite(x, HIGH)for 1 m/s???
   // some condition being the signal from the light sensor
} else {????????? digitalWrite(x, LOW)
   // do stuff if the condition is false
}

I want the pin mode to be output, if I'm not correct, assigning pin mode only happens once during setup

Cooptech

BUT I dont want to power the ground either, right?

PaulRB

#6
May 25, 2015, 04:47 pm Last Edit: May 25, 2015, 04:48 pm by PaulRB
I didn't read the "how to use" section. I apologize.
Have you actually read it yet, because your further posts seem to indicate you haven't ;)

I am using the ambient light sensor code to detect light and send a signal based on values.
What is "the ambient light sensor code"? Post it using code tags so it looks like
Code: [Select]
this

I am getting power from a 12v battery regulated to 7 volts, the board is powered to 5v through a separate regulator same battery.
Why two regulators? The Arduino runs at 5V too. Also you are wasting more than half the battery power this way. You should get a DC-DC convertor. I can't recommend one because you have not given us any clue how much current is involved. Use a multimeter to measure the current this board is drawing on max brightness.

Three wires, ground, power and signal (the signal wire being a simple ground switch)
So if you short the signal wire to ground, the light changes? Use multimeter to measure the voltage on this signal wire and how much current flows when you ground it.

The signal the LEDs use to run off of was a ground interrupt push button. I just need to know how to ground interrupt on an if statement
Like I said, probably with digitalWrite(x, LOW), but we need to know that it will be safe for the Arduino, hence the need to measure the signal pin with your multimeter.

If I guess correctly, using the switch, that was attached to this signal line, cycled through 3 brightness settings and off? If so, how will the Arduino know what brightness setting is currently selected, other than by "dead-reckoning" using the number of times it has grounded the signal wire?

Cooptech

"Have you actually read it yet, because your further posts seem to indicate you haven't"

I have, I'm missing information for one simple reason (well mainly), I don't have a multi-meter (going to get it today) I spent all the money on parts and forgot that all important tool. Other reasons will become obvious in my other responses.

"So if you short the signal wire to ground, the light changes?"

RIGHT- I will measure the output voltage of the signal wire and get back to you

"Why two regulators?"

The LED aray runs at 7 volts max, at least thats the battery configuration I took out of it. The second is to power the arduino, 12v regulated down to 5V, BUT I do have MB102 3.3V/5V Breadboard Power Supply Module which says it can take the 12v and turn it into 5v is this a better option than the regulator?

"If I guess correctly, using the switch, that was attached to this signal line, cycled through 3 brightness settings and off?"

RIGHT

 "If so, how will the Arduino know what brightness setting is currently selected, other than by "dead-reckoning" using the number of times it has grounded the signal wire?"

I HAVE NO IDEA, other than the one you mention. I hadn't thought about if the system had to read at a separate point other that full daylight. What I also need to be thinking about is how to tell the board what setting it is currently on, which will always be off at start.

"What is "the ambient light sensor code"?"   

I didn't think I really needed to include this information, all of that is arbitrary to the point of how to take the code information and use digital write to simply hit the switch, HOWEVER I do realize it may come into play when trying to calibrate the system to recognizing the state of the light array. I have not ordered the light sensor, I wanted to focus first on simply being able to turn the light on and on and on and off, lol. I thought there may be a way I could do that using the switch still, on a seperate digital pin,

read pin (push button) each button push would represent the stages of the light sensor, prior to the mention of reading the state of the LED array, using If then statement. If (button push) then (write digital LOW like mentioned before). Once I have the sensor I would change that segment of pin read write sequence to coincide with the sensor instead of the push button.


Hmm, ok so I have some more research to do. Look, Im real REAL new at the coding aspect.

I know how to measure sensor reads (obviously once I get that multimeter lol)
I know WHAT the components do and HOW they do it. I know how to define their operation in setup() and how to identify using the pins pinMode().

I'm going to go take some pictures of the setup I am working with and post them later, at this point I will return with more information, AND SOME ACTUAL CODE, so I don't expect TOO much enlightening information, maybe some guidance on where to look to calibrate the board to know how many "clicks" to send down the signal line (and being able to count those, I will also test to see the voltage coming out of the signal line of the LED array.


PaulRB

I don't have a multi-meter (going to get it today)
Just get a cheap $10 one.

BUT I do have MB102 3.3V/5V Breadboard Power Supply Module which says it can take the 12v and turn it into 5v is this a better option than the regulator?
No, that's just another regulator. If you want your 12V battery to last as long as possible, you should avoid regulators. Regulating 12V down to 5V wastes seven twelfths of the battery's energy as heat in the regulator, so it is only 42% efficient. A DC-DC converter will create 5V from 12V with 90%+ efficiency.

I have not ordered the light sensor,
A cheap Light Dependant Resistor (LDR) is all that's needed. Combine that with a 10K resistor and feed the result into an Arduino analog input.


Grumpy_Mike

Note that you will only get readings from 0 to 1023 from the analogue input pin.

When you read the how to use this forum did you forget the bit about how to post code or did you only skim read it?

Cooptech

When you read the how to use this forum did you forget the bit about how to post code or did you only skim read it?
Well, Like I said, I read it, I have however, not really posted any code yet.

Paul RB gets the idea of what my question was I'm sure, the question really isn't even a question of what code to use but which pin I should use to send the signal and how to use two grounds with one being the signal wire. The concept in question is of values not code, what value would equal a ground to switch between the arrays phases, PaulRB says print Low to simulate a ground, IF I understood him correctly. What he then told me was to measure the voltage coming out of the signal line when off the ground, to make sure that idle voltage wouldn't be damaging to the arduino. (which I am getting to).

I would like to take this opportunity to correct the board I am using, IT IS THE NANO, I am saving the MEGA for an array of other sensors. The NANO will have the light sensor (for the LED array), a temp sensor to control two cooling fans, and two motion sensors, a front and a rear. (for clarification, this is all just information I am sharing on the components I am bringing together, I am not asking how to do it).

PaulRB

Cooptech, can you bypass the control board and wire directly to the leds? I'm not convinced the board is adding any real value here. The Arduino can control the leds directly with a transistor, and fade up or down in 256 steps instead of only 3. It would also avoid the uncertainty over whether it is safe to connect this signal line to the Arduino. Before attempting to connect directly to the leds, its important to establish where the series resistors are in case they are on the board and so need to be replaced.

Grumpy_Mike

Well, Like I said, I read it, I have however, not really posted any code yet.
What about reply #4?
Did you put the similes in the code you posted? That is what the code tags prevent.

Cooptech

The board doubles as the holder. I could try to hack it.

 :smiley-confuse: was ???

PaulRB

The board doubles as the holder. I could try to hack it.
Sounds difficult then. Don't risk ruining it. I thought it might be a separate board.

Measure that signal line - voltage/current when switch is pressed/not pressed.

Go Up