How to control on off buttons

Venki: here I want to use transistor instead of push button pls give me appropriate circuit diagram sir.

this is the circuit for previous page I mentioned program

  • Note: on most Arduinos there is already an LED on the board attached to pin 13.

No that is not true at all!

ALWAYS use a series resistor, the Arduinos do not have them built in.

here I want to use transistor instead of push button pls give me appropriate circuit diagram sir.

What do you mean? What controls the transistor?

If I press the push button The LED 13 will blink if I release the button means Led 13 will low, instead of push button I want to connect the transistor which will operated by external sensor.

for that only I need circuit diagram

Venki:
instead of push button I want to connect the transistor which will operated by external sensor.

I’m not sure what you mean when you say the transistor will be operated by a sensor (and by the way a button is a sensor).

I think you mean, the Arduino will read the sensor, and based on the result, control the transistor? (Presumably the transistor will switch something bigger than the LED, maybe a motor.) Well that’s really no different from controlling an LED: replace the LED with the base of the transistor.

The schematic attached shows a potentiometer attached to an analog pin as an example of a sensor; the transistor base is on a digital pin.

motor and pot.png

Venki: I want to connect the transistor which will operated by external sensor.

for that only I need circuit diagram

In which case, collector to the arduino input, emitter to ground, base to a resistor and the other end of the resistor to the sensor. Enable the internal pull up resistors.

Remember to connect the ground of the sensor to the ground of the arduino.

Grumpy_Mike: In which case, collector to the arduino input, emitter to ground, base to a resistor and the other end of the resistor to the sensor. Enable the internal pull up resistors.

Remember to connect the ground of the sensor to the ground of the arduino.

exactly i did it not working sir.

Then you did it wrong. As you do not seem prepared to tell us what you did do I can't tell you what you did wrong but it was something.

I used external sensor as a magnetic sensor, I given this through LM 358 opAmp, I given externally power supply to the OpAmp circuit, and the O/p of the O/P of the opAmp pins + and - are connected as you said (base current) and the arduino and opamp circuits are connected. Collector to the button read pin of ardu.

It's ok but I directly connected the sensor to 5 volt and button pin and the button pin - resitor leading to ground like push button circuit. Marvelously it is working as a push button.

But, there is little bit blink is there when I make vibrate a sensor widely. Shall I filter is by delay circuit.

Thank you.

I think you need to draw a schematic, most magnetic sensors have an open collector output which means it should be connected with a pull up resistor not a pull down resistor. I would remove the pull down resistor and enable the internal pull up one. If it is still misbehaving then you need to post your code.

These are my circuits and the code is

//Button State read

const int buttonPin = 2; //the number of pushbutton pin
const int ledPin = 8; //the number of Led pin

int buttonState = 0; // variable for reading the pushbutton status


void setup() {
  
  pinMode(ledPin, OUTPUT); // setting 13 as output
  pinMode(buttonPin, INPUT); //setting 2 as input
}

void loop() {
  buttonState = digitalRead(buttonPin); //read the state of the pushbutton value
  if (buttonState == HIGH) { //check if the pushbutton pressed
  digitalWrite(ledPin, HIGH); 
  }
  else {
    digitalWrite(ledPin, LOW); //turnoff led
  }
}

What is this magnetic sensor? It looks to be wired wrong. You have not enabled the pull up resistor on the input pin.

no in our Arduino IDE basics> Button Read ordinary button circuit, instead of push button magnetic sensor acting as a push button.

It is not worth giving you advice if you are going to argue. You know very little. I am telling you that sensor is wired up wrong. The button tutorial is also the wrong way to do things but that works.

So in the next post you can either tell what the sensor is ( the part number ), or I will not answer any more of your posts.

Grumpy_Mike:
So in the next post you can either tell what the sensor is ( the part number ), or I will not answer any more of your posts.

Ohhh sorry sir, Don’t mistake me,It dosen’t have any part number Actually I went to local electronic shop and I asked them give a electro magnet sensor, they given me for less than 1$ rate. I have attached the closed view. They,given me without box. I think it is also they are giving like LDR, piezo plate like that.

And,

Grumpy_Mike:
The button tutorial is also the wrong way to do things but that works.

Can you tell me pls, button also like sensor is it, in sensors gate currents acting like a bridge and here in button physically we are bridging it, is it? So only you are saying button tutorial also wrong is it? else can you please explain me how it is wrong? It is not argue I want to know that’s it?

The picture posted appears to be a plastic covered magnetic reed switch commonly used in alarm systems...most likely normally open and when the magnet gets close it closes, if I was going to 'read' this with an Arduino I would tie one side to ground and the other side to a digital input AND to VSS through a 10k pullup resistor. In software make that digital input HIGH and read it...when the switch closes it will read '0' ie low,when the switch is open it will read '1' ie high and you can change the state of the Led as you wish with a HIGH or LOW written to the digital out the Led is tied to through a current limiting resistor.

geraldpaxton, Thank u

geraldpaxton: I would tie one side to ground and the other side to a digital input AND to VSS through a 10k pullup resistor. In software make that digital input HIGH and read it...when the switch closes it will read '0' ie low,when the switch is open it will read '1' ie high and you can change the state of the Led as you wish with a HIGH or LOW written to the digital out the Led is tied to through a current limiting resistor.

NOT both to "Vss" (which is Gnd). Connect one lead to your input pin and the other to Ground; connect a 10K resistor from input pin to +5V (or use the "internal pullup".) Then you would check for the digitalRead to be == 0 or 1 (LOW or HIGH)