Arduino Uno -- Multiple Inputs & Multiple Outputs

Hi all,

I am new to Arduino & not a programmer by nature. Just working on a DIY project & am having some trouble in writing the code to do what I want. I have an Arduino Uno Rev.3 & I want to do the following:

-have 2 separate inputs, on analog input pins 2 & 3 -have 2 separate PWM outputs, on digital pins 5 & 6

Right now, I can get the code to work perfectly for one input/output at a time, using the following:

int ledPin = 5; // LED connected to digital pin 5

int analogPin = 2; // potentiometer connected to analog pin 2

int val = 0; // variable to store the read value

void setup()

{

pinMode(ledPin, OUTPUT); // sets the pin as output

}

void loop()

{

val = analogRead(analogPin); // read the input pin

analogWrite(ledPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255

}

However, when I try to amend the code to account for two inputs & outputs, they don't seem to function independently (i.e. potpin2 ONLY controls output5 & potpin3 only controls output6):

const int ledPin1 = 5; // LED connected to digital pin 5 const int ledPin2 = 6; // LED connected to digital pin 6 const int analogPin1 = 2; // pot1 connected to analog pin 1 const int analogPin2 = 3; // pot2 connected to analog pin 2 int val1 = 0; // variable to store pot1 data int val2 = 1; // variable to store pot2 data

void setup() { pinMode(ledPin1, OUTPUT); // sets pin 5 as output pinMode(ledPin2, OUTPUT); // sets pin 6 as output }

void loop() { val1 = analogRead(analogPin1); // reads the input1 pin analogWrite(ledPin1, val1 / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255 val2 = analogRead(analogPin2); // reads the input2 pin analogWrite(ledPin2, val2 / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255 }

I appreciate any help/insight given! Thanks.

You do realize the loop( ) runs very quickly. If you are expecting see anything with your eyeballs, that isn't going to happen.

bauer41s4: However, when I try to amend the code to account for two inputs & outputs, they don't seem to function independently (i.e. potpin2 ONLY controls output5 & potpin3 only controls output6):

If the pots are not acting independently you may have them wired incorrectly. How, exactly, are they wired?

Guys, never mind. I'm an idiot. I was only using one pot. in my testing, & simply switching the wiper lead to/from analogin 2/3. When I connect two separate pots, everything works as I had hoped for!

Thanks for rattling my brain back on track!

Yep, floating analog inputs typically produce values very close to the last non-floating input. The analog input is stored in a sample/hold capacitor. If there is no current flowing in or out (unconnected input), the charge on that capacitor tends to stay the same.

There is only one S/H capacitor shared by all the pins, and its tiny (8pF I think), the best thing to do is completely ignore any reading from a floating pin.

Hello developers, I am new in the Arduino world. I'm willing to create an PIR alarm with gsm calling function with gsm module or Bluetooth module. But I also wish to use few relay switches. That would be operted via wifi i guess. Arduino UNO is available to me. Have to buy all other stuff and also need instructions and coding help. Atleast for a couple of times to start with this projects. Later I will be managing it myself but startup help would be greatly appreciated. Hope someone out here will be glad to help me out. Regards Himanshu Bansal

That would be operted via wifi i guess.

If the Arduino is going to wear a WiFi shield, so that this can happen, why on earth would it need to wear a GSM shield or a bluetooth shield/module?

I am new in the Arduino world.

So you choose Expert to be part of your handle?

Thanks for your reply buddy. Actually I wish to use gsm or Bluetooth to bypass any chances of WiFi connectivity loss or even a WiFi cable cut is possible as any intruder can cut off the WiFi optical cable which is going @ just 5cm parallel to my entry door. I am going to connect the Arduino by big batteries which can only be disconnected in the premises. I'm using Alfred Android camera too but the app don't alert instantly.

I just wish to get instant alert as priority.

Relay module is the secondary requirement.

Otherwise can I use 1 PIR(outside the premises) output to just call me up and other PIR(mounted between door and main entry) to call and buzz an alarm?

Sorry if I m annoying but curiosity is the key to make my project better

When you decide on what radio system you want to use (bluetooth, WiFi, GSM, XBees, etc.), then you can think about what to send, and how to send it.

What you want to send the data TO will have some affect on your choice of sending hardware.

That will also affect how many Arduinos are involved, and what the PIR sensor(s) and relay(s) are connected to.

That will affect what each Arduino needs to do.

Until you get that sorted out, asking questions in the Programming section is pointless.

Ok so the point is that I want a PIR sensor and alarm connected to Arduino and gsm shield to make calls to my number immediately when motion is detected. Now the point is what to buy? Including all small parts and how to do coding( need 1st time sample for my project

Now the point is what to buy?

What I could/would buy may not be the same was what you could/would buy. Some clue as to what part of the world you are in might be useful.

Obviously, you need an Arduino that can take shields. You need a GSM shield. You need a PIR sensor. You (think you) need a noise maker.

Only you know what kind of noise you want to make, so only you can choose that. Only you know where you live, so only you can choose the appropriate GSM shield.

We have no idea what your experience with Arduino, or electronics, is, so we have no idea whether you need wire, wire strippers, a soldering iron, a multimeter, first aid cream for when you burn yourself with the soldering iron, etc.

There are quite a few examples around for using a PIR sensor. Most of them are crap, because they ignore the fact that it is easy to detect a state change, so they have convoluted logic to determine when there is motion.

There are libraries for the common GSM shields. If there is not one for the shield you pick, seriously consider NOT ordering that one.

Getting all the pieces to work together is your job.

I have all the assembling/soldering setup.

I just need to buy uno or uno R3? Gsm shield 900 works in India PIR sensor is just simple to buy. Next I need 12v output to power a siron for loud noise. Any diodes or resistors or led required in the setup?

And I want gsm shield to call me Lastly how can I reset the alarm when I am away.

Any diodes or resistors or led required in the setup?

If you use a 12V siren, you will not be able to connect it directly to the Arduino. You'll need a relay or transistor.

That may require extra components.

Lastly how can I reset the alarm when I am away.

Use your phone. Call your neighbor. Have them do it.

Or make the Arduino respond to text messages.

Really, it's time to shut up and try something.

On the way to buy parts from local market.
I will get the relay, can you help me with coding

Why hijack a six month old thread on a completely different topic?