# Tag Info

5

A relay, as pictured, is a good choice. It provides complete galvanic isolation and switches the power properly. Another option is to use a MOSFET that can handle enough current (an N-channel switching the ground as a low side switch, or a P-channel switching the power which is itself switched by an N-channel, as a high side switch).

5

The simplest fix to your problem is to change the map() call to byte alrmSet = map(alrmSwState, 0, 1024, 0, 3); In the call above, the mapped intervals are of the semi-open type, e.g. [a, b), where the start values (namely 0) are understood as being inclusive and the end values (1024 and 3) are exclusive. Although not clear from the documentation, ...

4

Almost, you will need two 74157 (or similar chips) to switch 8 pairs of TTL level logic signals down to 8 individual signal.

4

You could configure one of the digital pins as INPUT_PULLUP and connect one end of the switch to it. The other end of the switch goes to ground. LOW = switch ON, HIGH = switch OFF. const byte pinNumber = 3; void setup(){ pinMode(pinNumber, INPUT_PULLUP); } void loop(){ }

4

Just three lines of code are needed for the conversion. almSet=0; if (alrmSwState>300) almSet++; // increment almSet if (alrmSwState>600) almSet++;

4

LEDs have a (fairly) fixed voltage drop across them. The red LED is about 2V. You can use that to work out the voltage at the input. You basically have a voltage divider, with your 200Ω resistor as R1, and your 1kΩ resistor as R2. The voltage drop of the diode is subtracted from Vin. So: Vout = (Vin - Vled) * (R2 / (R1 + R2)) = (5 - 2) * (1000 / (...

4

It's basically a push button. Possible examples depend on what you want to do. As it seems, you simply want to start interfacing it with Arduino, just use it as a normal push button. Use the DigitalInputPullup example, that comes with the Arduino IDE: Middle pin to pin 2 on the Arduino One of the other pins to ground (depending on which state you want to be ...

3

My guess would be that you're getting noise interference on the line and it's too much for the Arduino's little internal pullup. Try adding an external pullup resistor - say 5k-10k (exact value is not critical).

3

I notice that your pinMode function calls are not quite correct: pinMode(Sender = OUTPUT); // Setting pin two to output pinMode(Reader = INPUT); // Making pin 12 set to read switch data Should be: pinMode(Sender, OUTPUT); // Setting pin two to output pinMode(Reader, INPUT); // Making pin 12 set to read switch data Refer to https://www.arduino.cc/en/...

3

I'd suggest using a multimeter to figure out what's connected to what after hooking up the complete wiring scheme; there aren't that many options and you should be able to figure out what's connected to what soon enough. On a more philosophical note, it's only a bad idea if the alternatives weren't worse.

3

The expression read3 + " input" performs pointer arithmetic, i.e. you either add 0 or 1 to the start adress of " input", so you get either " input" or "input". Does the leading space disappear when pressing the button? To correct your code you can print the number separately: Serial.print(read3); Serial.println(" input"); You should get rid of the rest ...

3

Written and tested. I also included the red blinking led. //CONSTANTS const int BUTTON_PIN = 2; // Button const int in1 = 7; const int greenLED = 4; const int redLED = 9; //VARIABLES int buttonPushCounter = 0; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; // previous ...

3

A relay is just an electromagnet, and the same circuit that can drive a relay can drive an electromagnet. You just need to make sure it can handle the power. The simplest circuit is to use an N-channel MOSFET: simulate this circuit – Schematic created using CircuitLab Just make sure that the MOSFET can handle the required power dissipation and ...

3

Actually, you can very easily verify this yourself: Per item (1602LCD, 7 segment LCD and LEDs check how many pins you need and what type, like e.g. I2C or SPI for the 1602 LCD). The 7 segment displays can have many or less pins, depending on the 'controller', See the reaction of CrossRoads below. Count them together. If it fits on the Arduino you want to ...

3

It is wasting of IO pins to use the digital output pin just to get +5V rail. But both options will work. Don't forget to use pull/up or pull/down resistor, or activate internal pull/up resistor on the sensing pin. When the switch will be open, the input pin is not connected anywhere and will act as antenna, so it might pick up some noise.

3

There are some GNU extensions available in the avr-gcc/avr-g++ compilers (used in Arduino IDE for AVR based Arduino boards). One of them is suport of ... for the case: switch (i) { case 10 ... 100: Serial.println(F("First")); break; case 101 ... 1000: Serial.println(F("Second")); break; default: Serial.println(...

3

Replace the line: byte alrmSet = map(alrmSwState, 0, 1023, 0, 2); with byte alrmSet = alrmSwState / ((1023 / 3) + 1); And this should do what you want. Note that in C fractional results are truncated (not rounded)

3

If you want to declare multiple variables with the same name inside different case statements, you can enclose the code inside each of them inside curly braces: case 1:{ Code... break;} case 2: ... The curly braces will set the limits for the variables scope to just this case.

3

There are different ways to accomplish the same thing. The condition is a flag, or a read port. if(digitalRead(inPin)) { // Your first code here. } else { // second code } Switch contacts will bounce when opening or closing. You may want to consider that. Usually it is stable within 10 milliseconds. Depending on what you ...

3

There's certainly an issue with your optocoupler circuit aside from the fluctuation you observe. During a negative half-wave of 220V, you expect D1 to block the current through the LED. However, 1N4007 as any power rectifier has significant leakage current, about 5μA at normal temperature and up to 50μA when the diode is hot. This current will go though the ...

3

Let's assume the switch is on pin 9, that the pinMode() has already been set, and that the switch reads HIGH for loop operation. #define MODE_SWITCH 9 #define DO_LOOP HIGH // This loop will execute once if the mode-switch is off, or // will execute continously if the mode-switch is on: do { servo_things(); stepper_things(); motor_things(); } while( ...

3

Since it has two possible positions, and three pins, you have a connection between pin 1 and 2 when position 1 is selected, and between pin 1 and 3 when position 2 is selected. As BSF comment below, the middle pin is common. This means it will be connected to the outside pins depending on where the switch is moved towards. However, you always can verify ...

3

When you want to perform actions in response to button presses, you should take care of reacting to the signal edges rather than levels. In other words, you perform the action only when the signal changes from LOW to HIGH, not every time you see it HIGH. You should also read about button bounce, and either implement your own debouncing or use an existing ...

3

I suggest this simple circuit: simulate this circuit – Schematic created using CircuitLab Set both inputs to INPUT_PULLUP. If the input reads LOW, that means it has been grounded by the switch. Edit: Per Duncan’s request, here is the alternative circuit with the polarities inverted. With the switch’s common connected to Vcc, the inputs should be set ...

2

Yes, that is too simple. The Arduino's IO pin is not designed to directly drive a relay. It needs to go through a transistor first, and you must include a diode to absorb the back-EMF generated by the collapsing magnetic field. Google for "Arduino Relay" and you will find hundreds of thousands of examples. In short, the circuit you need to create is this:

2

One big problem is that you forgot the break statements for those cases. So if it compares in the first one and finds it, you'll still get null because it is going to go look for the third one afterwards.

2

This answer is based on a previous version of the question Not necessarily. You can use the internal pullups of the arduino if you're willing to accept that reading a "1" means that no piece is there and reading a "0" means a piece is there. Connect each wire up to a pin on the arduino. If you do it wisely, step 3 becomes fairly easy. You need to configure ...

2

I've just bought a few STP16NF06L fets for this very purpose, N channel MOSFET. The key part of that part number is the L at the end. This indicates low (or Logic) gate threshold, which means it will switch on fully at 5v gate drive, unlike most fets which are sort of conducting at 5v but need 10v to reach their specification (like an IRF530N). The 16 and ...

2

Call the resistors R1 and R2, the negative terminal Ground, and the positive terminal V+. The junction of R1 and R2 is connected to Ground. This holds the resistor ends at the junction to zero volts relative to ground. Ignoring P2 for the moment, the other end of R2 is open circuit to V+ when S2 is open. Applying Ohm's law, we have a finite resistance in ...

2

An input pin is in what is known as high impedance mode. That is, to all intents and purposes, to the external circuit it looks like a massive resistor to ground. This resistance can be in the millions of ohms. So let's redraw your circuit with those input pins as big resistors: simulate this circuit – Schematic created using CircuitLab Now you can ...

Only top voted, non community-wiki answers of a minimum length are eligible