Using negative voltage signal to activate a sketch

First, thanks Arduino for this wonderful tool and thank you my fellow techno-babblers, D&D gamers and other nerddom for your amazing collective knowledge and willingness to help. Problem: use a -5v signal to activate a portion of a sketch. Alternative 1: convert the -5v to +5v with a relay. Alternative 2: use a remote radio signal to activate the sketch. I'm making an adaptive device for my kid who is tactilely defensive, which means he can't grab the controls. What I am attempting to do is modify a sit-in electric car to be remotely controlled by the parent. I have adapted an inexpensive remote car controller to trigger the Arduino board. I have relays setup to control power and polarity at the sit-in car's 12v motor (forward/reverse). I can get this setup to move the wheels either direction with the +5v signal but need the -5v signal to turn the wheel the other direction; however, I understand Arduino can't read a negative signal at the input pins. The goal is to use the remote, to signal the motor controller, then use the motor controller (+5v/-5v output) as a signal to activate different sections in the sketch. I have managed to write the code to work and can get the +5vdc to activate the sketch (+5 to move the wheel fwd or rev) but need alternatives methods to use the -5v signal or use the remote signal to directly affect the Arduino. I could use the -5vdc to ground the primary side of a relay, then use a +5vdc on the secondary side to trigger a pin. I could also use the signal from the remote itself, but I'm not sure what type of sensor I need to read the signal, how to tune the sensor to the remote frequency, or if that is even necessary. I want to make this a cost effective DIY kit for parents to use on similar "ride-toys". I'm open to suggestions on simpler/cost effective approaches. I was able to use one of the Elegoo joysticks to successfully use analog thresholds to switch the relays fwd/rev, so I know the sketch works with at least analog input but this is hardwired and I need remote. The output/signal from the motor control is simply: +5v in forward, 0v in neutral, -5v in reverse. There is no PWM in the control. It switches instantly to 5v +/- both directions. When the control is switched back to neutral, you can see a bleed down from 5v to 0v over a second or two. (I'm guessing it's a capacitor discharge?) As a note, this car does not have a mechanical or electronic steering wheel. It turns like a zero-point lawn mower, or tank, in which forward of the left motor and reverse of the right motor causes it to rotate to the right quickly and vice versa. For a tactile kid, this is ideal since they won't want to touch the steering wheel anyways. It is also ideal since the controls are simplified to 2 fwd/rev joysticks for control and the sit-in cars like this are much less expensive than the ones with mechanical steering. The goal is to eventually teach the child to use the controls instead of parental control. This is not just for fun but a medium to overcome disability. Pushing a lever forward/back is much easier for these kiddos than trying to turn a wheel. They often times don't have the strength to turn it and simplification solves some of the difficulty they have with overwhelming sensory input. The other thing is, I was running the board in -5vdc to test the sketch. I'm guessing the amps draw was very small but I am not sure if I damaged the pins or not. How do I test the diode protection circuit on the board? My experience base: This is my first time using code since high school, which was very basic, in fact I think it was called basic or C not sure. That was 27 years ago. I'm currently a technical trainer and curriculum developer for automotive OEMs which includes electrical troubleshooting and theory. I have run and adapted about 30 sketches of various sensors from an Elegoo 37-in-1 sensor kit to get my feet wet. I have not used the IR or radio remote sensors yet but intend to do so next to help with this challenge. Over the past couple months, I have adapted, combined and used dozens of example sketches from this site with both failure and success equally. I'm getting more proficient at combining and modifying sketch examples but still very novice. This current sketch is on about the 37th revision. That doesn't include the fact I've wiped and started over several times as I realized either the code, wire diagram or components were incompatible, inefficient or "thermally reactive" (grounded without load :).

i could totally be oversimplifying, and I get kinda dense when I dont have code and/or a schematic in front of me (then again, when I do I can get down-right stupid)

what about using digitalread and looking for a low?

timmybdaddyof3:
i could totally be oversimplifying, and I get kinda dense when I dont have code and/or a schematic in front of me (then again, when I do I can get down-right stupid)

what about using digitalread and looking for a low?

Yes, you are. This is not good advice. Fortunately, the OP already realizes that this may have damaged the Arduino.

You can use an NPN BJT transistor in common base mode. Ground the base, connect the collector to the Arduino with a pullup, and put a current limiting resistor in series with the emitter. When that lead goes to -5V, whatever current is in the emitter resistor will also flow in the collector circuit and will show up as a “low” at the Arduino input.

aarg is absolutely correct in the need to use some form of isolation - I was just thinking of triggering the sketch...and this brought me to another thought...which may be the OPs real problem.

These methods will show a high (on +5vdc for forward) and a low (on -5vdc on reverse) but how do you process the 0vdc in neutral

Going back to the sketch I can see using 2 pins - one as a forward (high) detection, and one for a reverse (low) detection, absence of both would be neutral.

aarg- tell me what I am missing now =) t

My method will show a "high" for both 0V and 5V. It might be a good idea to add a diode to prevent reverse biasing the BJT EB junction. The reverse voltage might not be enough to matter, it would depend on the transistor spec. Thus the +5 leg of the circuit should go to another pin with another diode and the pin pulled to ground with a resistor.

Great feedback. Aarg, nice name and how I feel working on this project 50% of the time. This would effectively drop (raise?) the voltage close to zero from -5vdc, correct? Originally, I thought the inputs would be analog, so I used a POT on a single input pin, which floated at 2.5v (in neutral). I was able to use IF thresholds to control when the switch turned on, and ELSE statements to turn it off in neutral. So, with your method of 5 HIGH and 0 LOW only, (no neutral) how do I trigger the relay to shut off when I drop out of a LOW state? For instance IF HIGH activates the power sequence, ELSE LOW could deactivate the sequence. But, IF LOW activates the sequence and it stays at LOW, how do I deactivate the sequence? Am I missing any logic in this line of thought? Sorry if my terminology is off, feel free to correct me.

The common base transistor will shift the level by adding approximately 5V to the signal, if the emitter and collector resistors are matched. The emitter resistor should approximately be a ratio of 4.3/5.0 to the collector resistance value (if the BE reverse polarity protection diode is omitted). Then an input range of -5 to 0V is translated approximately as 0 to 5V. That would be one input, a low state indicating a -5V. Beware that this is the opposite logic of the other one, which yields a high state for a +5V input. This arrangement requires two digital inputs, and an analog solution can also work if you can spare an analog port.

The program logic that you need to apply this is not intrinsically different than the analog case. In that case, you branch on analog values. In the digital case, you make the same branches but on the condition of the digital inputs. Perhaps you are not aware that it is possible to test for multiple logical values at the same time? For example, you can tell that the input voltage is a 0 if the level shifter shows "high" and the straight in through the diode (positive detector), shows "low".

It would look something like:

if (negativeInput == HIGH and positiveInput == LOW)
{...

The questions that you pose about program flow have no bearing on the hardware method that is used to sample the switch. They seem to be leaning towards questions of state change detection. That is another bag of beans.

If I had to do it in analog, I would do it with a resistive voltage divider, one end to VCC, the other end the input, and the center tap to an analog pin. Two equal resistors total parts count. :)

Man I wish I had 10% of your knowledge. No I wasn’t aware I could test for multiple logic values simultaneously. And that’s going to take a bit for my novice mind to process and research, as well as do the numbers on the voltage divider. I’m sure there is something showing an already made circuit but part of what I like about this is the learning of why and how it can be used. But, i do not learn these things intuitively or easily. It takes my brain many attempts reviewing and time to process to integrate the logic and be able to apply it. That’s always the difficulty with learning, rote vs application. Both are important, unfortunately I’m better at applying knowledge creatively than learning it, which brings about many interesting failures and a different type of learning called “the hard way” :slight_smile: I appreciate your help and will look into understanding and applying these methods an easier way. Thanks much!

Toss an optocoupler in there.

Ensure the input (LED) is driven correctly for the voltage and current needed by the opto. The output (transistor) becomes a switch across your device input.

The two sides are completely isolated, and the relative voltage across the input has no need to be related to the output levels. It’s simply light turning on the output (transistor) switch with no electrical relationship.