Hello,
I allowed myself to post this new topic, because I don't achieve to calculate something, and all help is welcome !
I have got a Arduino Mega, a battery (24V) and two analog sensors. However, I would like that in most of cases, two sensors are deconnected. To make this, I put a transistor NPN for the purpose of making an switch.The collector is connected with the battery alimentation, the base with an output of Arduino Mega and the emettor with the input voltage of the sensors.
Do you think this is well connected? or is it better to put the transistor between the ground of the sensors and the ground of the battery?
Moreover, I don't know to which output of Arduino Mega I should connect the base?
Thank a lot in advance,
Have a nice end of the day 
A "sensor" is normally on an input pin, but I think you are connecting something to an output.
If it's really on the analog input, the connections are wrong. And, a simple transistor circuit like that is non-linear and it won't work with analog. (It will work with PWM "analog" outputs which are not truly analog.)
You need a resistor in series with the base. That resistor should allow something like 1/50th to 1/20th of the collector-emitter current (allowing for the gain of the transistor).
If you don't know Ohm's Law - Current = Voltage / Resistance. (You can assume/apprximate the full 5V is dropped across the resistor.)
Without the resistor you'll get excessive current from the Arduino which could damage the Arduino (or simply cause it to malfunction).
I have got a Arduino Mega, a battery (24V)
Do NOT connect more than 5V to the Arduino inputs/outputs. 24V (properly connected) to the transistor is OK.
The maximum recommended voltage into the barrel jack power connector is 20V. You might get away with 24V if you are not drawing too much current through the voltage regulator.
A "sensor" is normally on an input pin, but I think you are connecting something to an output.
Take a look at this http://www.pighixxx.com/test/abc/ it's the most complete "how to" connect to the arduino guide you will find.
Mark
Isabelle_VP:
I would like that in most of cases, two sensors are deconnected.
It appears you mean "disconnected from power".
Isabelle_VP:
To make this, I put a transistor NPN for the purpose of making an switch. The collector is connected with the battery alimentation, the base with an output of Arduino Mega and the emettor with the input voltage of the sensors.
That will not work properly. For an NPN transistor to work as a power switch is must be between the load (your sensor) and GROUND. This is called a LOW SIDE switch. For a HIGH SIDE switch (between the power and load) you need a PNP transistor. To turn off the PNP transistor you have to raise the Base connector to the same voltage as the Collector. For an Arduino this is easy if your load is running on 5V but with a 24V load you will need a slightly more complex circuit, typically a 24V pull-up resistor on the Base of the PNP transistor to turn it off and an NPN transistor from the PNP Base to Ground. Turning on the NPN transistor will pull the Base low and turn on the PNP transistor.
Here is a good article on using transistors as switches:
http://www.electronics-tutorials.ws/transistor/tran_4.html
Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Including how you are powering your arduino.
Why do you need to switch the sensors OFF.
What are the sensors?
Then we can advise you on how to modify it.
Tom.... 