I have 16 Channel relay system with feedback voltage (Analog). So when I send command to operate the relay, I should be able to read the Analog voltage on that channel without having to hard cade. For example analogRead(A0), analogRead(A1)
I am looking at passing analogRead (Ai) where i will have values from 0 to 15.
Yes for testing purpose I tried the following
int i=0;
int sensorvoltage = analogRead(Ai);
It is giving me an error
Relay are connected to different sensors, so when I operate the relay I have to read the analog voltage on each channel. Hope I have addressed your curiosity
add Arduino to focus and find some learning materials you like. In the meantime, take a look at these few lines of code:
// define some pin numbers where you want to analogRead:
const byte inputPins[ ] = {A0, A1, A2};
// later... to read the first pin
int reading = analogRead(inputPins[0]);
// and to read the second pin
int reading = analogRead(inputPins[1]);
You use the array name and an index N in brackets [ N ] to refer to one element on the array.
Indexes start at 0 and go to N - 1 where N is the number of elements in the array.
Hi,
Can you please post a schematic of your project?
Please do not use Fritzy, a hand drawn image will be fine.
Include ALL power supplies, component names and pin labels.
We need to see how you have your hardware connected.
If you are saying your 16 channels of relays feed back to 16 analogue inputs then all you have to do is to use the same number in the analogue read as you did to set which relay to activate. Although you don't have 16 analogue inputs on many Arduinos.
If you are saying you have 16 channels and the relays funnel one of 16 inputs to the same analogue pin then you have no need to change the analogue pin you read.
As others have said we need to see a schematic of what you have, or the code that you would consider to be hard coded, for at least three channels.
Post the full error that you get; when using IDE 1.8.x, there will be a button at the right hand side in the orange bar to "coppy error messages"; click it and next paste it here, again using code tags (the </> button in a reply windows on the forum).
A most useless description of the problem. Describe what you expect your code to do and describe what it actually does.
Unfortunately, the schematic is at hand drawn. I have purchased 16 Channel Relay board from the net and will experiment with that. Once when it is all working will have the drawing ready.
Great answer, thank you so much. I may need your help in the future as well. I am a mechanical engineer and not from software background so please bare with me.
So if you are going to make a mechanical something, would you make it and then do the drawing? I think not. A mechanical engineer would draw up what is needed to be made and then make it. As my school metal work teacher and my technical drawing teacher told me back in the 60s, "if you can't draw it then you can't make it".
It is exactly the same with an electronic engineer, draw it then make it. If you don't the you don't know what to make and don't know if you have made it correctly or if the design is just wrong.