Suzuki SV650 Riders Forum banner
21 - 40 of 92 Posts
Discussion starter · #22 · (Edited)
You picked that up quick, kodde!

If I may offer a suggestion, for the turn signal inputs, the voltage regulators and associated parts can be eliminated. Assuming those are being used to translate the turn signal voltage from 12v down to the uController input max voltage of 3.3v, a simple series resistor will do.

The protection diodes on the Atmega168 inputs can handle up to 1mA. To drop 12v down to 3.3v (=8.7v diff), the resistor should be 8.7v/1ma = 8.7/.001 = 8.7k ohms minimum. Plunk in a 20k ohm resistor in series between the turn signal and the uC input will give 2x saftey margin.
Oh, thanks.

But how can a simple resistor change the voltage? Isn't an resistor use to limit the current draw? I'm still new at this as you can probably tell.

I already bought these components and my trying around has been fruitless. I'm trying to figure out a way to sense when the turn signal lights are drawing current and I kind of stuck. Hall sensor can be used I guess, but seems overkill. I don't need exact measurements, only an on/off sensing functionality. Any ideas?


Awesome idea - I wonder if this would have a practical application for saddle bags/hard bags. The wireless would make use far easier.
Thanks. Yeah I did consider connecting a wire at one point, but that would be a real hassle and deal breaker for me.
 
...I'm trying to figure out a way to sense when the turn signal lights are drawing current and I kind of stuck. Hall sensor can be used I guess, but seems overkill. I don't need exact measurements, only an on/off sensing functionality. Any ideas?
Just a single 20k ohm resistor between the flasher and Arduino input will work fine. The clamping diode inside the Atmega chip will draw current through the resistor thereby dropping the voltage to a permissible level.

Don't use a hall sensor, voltage regulator or any other device; a resistor is all you need.

It works just like a series resistor to limit current (and drop the voltage) to power an LED.
 
Discussion starter · #24 ·
Just when I was beginning to think I understood how electronics works. So by limiting the draw the voltage is also reduced?

Do I read this on a digital or analog input on the arduino?

I'm going to try drawing this up, to make sure I get this straight.
 
Yes, except use a digital input instead of analog.

In this case the 20k ohm resistor drops 12v (actually 14.5v on the bike) down to 3.3v. It works according to Ohms law, V=IR: voltage = current x resistance.

This works because there is a protection diode inside the controller chip that starts drawing current any time I/O voltage exceeds 3.8v (3.3v + 0.5v). It's an elegant solution!


Edit: 20k ohms comes from the fact that the protection diode can handle 1mA max. 20k limits the current to 1/2 that for safe operation. 12v - 3.3v = 8.7v. 8.7v/20,000 = .44 mA.
 
Discussion starter · #27 ·
I'm trying to prototype this at home first (garage is a 5 minute walk, and no computer access).

So when prototyping this at home, I don't have the turn signal here. But I should be able to mimic this with just some simple switch instead of the light right? And this input would register on the Arduino as HIGH/LOW reading or what?

Thanks!
 
Yes, you don't need the bike or turn signal to test, just a 12v source. A switch setup would be fine, or simply touch the free side of the 20k to a 12v battery.

When touching the resistor to 12v the Arduino will register HIGH on the input. Touch the resistor to ground, Arduino will register a LOW.

Be careful not to touch 12v directly to any chip I/O. Double check the resistor (measure with your meter) to be sure it is 20k.

What are you using to program your chip? A simple one line loop program that drives an LED based on the digital input would be a good test setup.

Edit: If you don't have a 20k handy, anything from 20k up to 100k should work as well.
 
Discussion starter · #31 ·
Yes, you don't need the bike or turn signal to test, just a 12v source. A switch setup would be fine, or simply touch the free side of the 20k to a 12v battery.

When touching the resistor to 12v the Arduino will register HIGH on the input. Touch the resistor to ground, Arduino will register a LOW.

Be careful not to touch 12v directly to any chip I/O. Double check the resistor (measure with your meter) to be sure it is 20k.

What are you using to program your chip? A simple one line loop program that drives an LED based on the digital input would be a good test setup.

Edit: If you don't have a 20k handy, anything from 20k up to 100k should work as well.
I'm getting no response at all. I'm reading my input values and spitting em out through the USB cable. With no input at all it's just displaying noise, when trying to connect a 12V source nothing happens. Tried both the positive and ground, no response.

Have you tried this yourself? are you certain it should work?

I tried reading up on it, and the noise when no input is present seems normal.
http://arduino.cc/en/Tutorial/DigitalPins
 
I'm getting no response at all. I'm reading my input values and spitting em out through the USB cable. With no input at all it's just displaying noise, when trying to connect a 12V source nothing happens. Tried both the positive and ground, no response.

Have you tried this yourself? are you certain it should work?

I tried reading up on it, and the noise when no input is present seems normal.
http://arduino.cc/en/Tutorial/DigitalPins
Yes, I use it with PIC micro controllers which are identical to Atmel with respect to the clamping diodes.

Here is an Atmel Application note AVR182 which details the method (note the internal clamp diodes in Fig1). The example in the App note is for connecting 120v mains AC (ten times higher than your application) but is the same principal.

If you leave the I/O open you will read noise. The resistor must connect to 12v or ground to have a stable reading.

Try first using normal 3.3v and 0v at the input (no resistor). Once you get that working then try 12v through 20k.

How are you determining what the chip is seeing on the I/O pin?


Excerpt from the App Note AVR182:
To protect the device from voltages above VCCand below GND, the AVR has internal
clamping diodes on the I/O pins (see Figure 1). The diodes are connected from the pins
to VCCand GND and keep all input signals within the AVR’s operating voltage (see Fig-
ure 2). Any voltage higher than VCC+ 0.5V will be forced down to VCC+ 0.5V (0.5V is the
voltage drop over the diode) and any voltage below GND - 0.5V will be forced up to
GND - 0.5V.
By adding a large resistor in series, these diodes can be used to convert a high voltage
sinus signal down to a low voltage square wave signal, with amplitude within the AVR’s
operating voltage ± 0.5V. The diodes will thus clamp the high voltage signal down to the
AVR’s operating voltage.
 
Discussion starter · #33 ·
Yes, I use it with PIC micro controllers which are identical to Atmel with respect to the clamping diodes.

Here is an Atmel Application note AVR182 which details the method (note the internal clamp diodes in Fig1). The example in the App note is for connecting 120v mains AC (ten times higher than your application) but is the same principal.

If you leave the I/O open you will read noise. The resistor must connect to 12v or ground to have a stable reading.

Try first using normal 3.3v and 0v at the input (no resistor). Once you get that working then try 12v through 20k.

How are you determining what the chip is seeing on the I/O pin?
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(12, INPUT);
}

void loop(){
int myInput = digitalRead(12);
if(myInput == HIGH){
digitalWrite(13, HIGH);
}
else{
digitalWrite(13, LOW);
}

Serial.println(myInput);
delay(50);
}


The "myInput" variable is being printed through the USB-cable. I'm monitoring it through the Arduino software's Serial Monitor on the PC.

Nothing with a 5V source either.
 
Discussion starter · #35 ·
Image


This is the Arduino Uno, connected from 5V pin to 2 x 10kOhm resistors in series, then to the digital pin 12 on the Arduino Mini Pro 3.3V.

What's strange is that I have prior to this successfully connected the two arduinos just as a quick test to see if I could read a current from one of them to the other. I had the Uno hooked up with a simple button, when pressed it would set a HIGH value on a pin. This pin was connected to a pin on the Mini. The Mini would read from this pin, and if this pin went HIGH it would blink a LED. It worked like a charm. Seeing that this work, I cannot figure out why a raw power source to trigger instead wouldn't work...
 
Discussion starter · #36 ·
The loop() runs automatically. All Arduino code is basically the setup-part and void-part.

On my already mentioned prior attempt between the two Arduino's I measured the current being drawn, was around 19mA.

The Arduino Uno operates on 5V and the Mini on 3.3V. However the Arduino Uno has 5V & 3.3V output pins.
 
Hey, nice photo! That helps.

I would try a couple things:

1. Make sure the Mini is operating by itself by artificially toggling myInput from inside the program, don't use I/O yet. This will make sure the Mini is alive and the program is looping. Toggle maybe once per second.

2. Once that is working, test the Mini I/O by just connecting a 3.3v (normal I/O level) signal to Mini-digital-pin12, no resistor. Don't involve the Uno until this is working by itself.

3. After verifying the Mini can sense digital I/O with normal voltage, then bump up to 5v through a 10k. After that, 12v through 20k.

As a teacher once told me, "Divide and conquer."

Good luck!
 
Discussion starter · #38 ·
Well. I think I managed to get all your suggested steps right except the last part with 12V.

Thing is I don't have a good source of 12V. So far I've been connecting the Uno though the barrel jack port with a 12V power adapter, then just connecting whatever I wanted to test 12V through touching wires to the back of the Uno where the barrel jack connector is soldered. Maybe this is where I'm doing it wrong? I'm not that familiar with the barrel jack connector to be honest.
 
:thumbsup: You are fast.

If 5v through 10k to the 3.3v input is working, 12v through 20k will work as well.

12v from the barrel jack is a good source, just make sure you have ground connected between the Uno and the Mini! That is missing in the photo (sorry, just noticed it).
 
Discussion starter · #40 ·
In case I forget to mention. Thanks for all your help and patience TeeRiver, really really helpful for a beginner like me.

So, my last few test have got me a bit further I think. With 12V I am able to get a steady current (1) when I connect input12 to one of the three solder spots of the barrel jack connector. When touching the solder spot two and three of the barrel jack connector I get a steady ground (0). When not touching any solder spots I get noise, switching between 0 and 1 constantly over and over.

Is this what is expected? Will I be getting noise when applying this to my bike later?

Now I need to adapt this to the Gladius and figure out how to connect it there as well. But... it's 01:50AM where I live, and I have laundry in the morning T_T

I'll keep you posted during tomorrow, see how it goes.

Thanks and goodnight.
 
21 - 40 of 92 Posts