I am trying to use an Arduino as a multiplexer. It will receive 6 different inputs from a secondary arduino; those inputs are 5 volts. The inputs are being read by the Analog Pins.
Once the board receives the 5 volts as an input, I need it to output 5 volts on a digital pin.
I have uploaded the code below. Any critiques would be much appreciated. I have been trying to figure this out for the past 3 days, and have not been able to come to any conclusion as to why this is not working for me.
The only part of the code I am not confident with is the start of the if statement, as I am not sure if it should be an integer with a value of 0-1023 or a HIGH/LOW type of communication.
// I am using an Elegoo Mega 2560
// I need the board to receive 5 volts on the analog input pins, and then output 5 volts to specific output pins.
// No matter what I do, this will not work. Not sure if I somehow fried my board maybe?
int Ipin1 = A1; // Sets the analog input to be an integer, with a variable name of "Ipin1"
int pin2 = 2; // Sets the digital pin 2 to be an integer, with a variable name of "pin2"
void setup() {
// put your setup code here, to run once:
pinMode (Ipin1, INPUT); // Sets "Ipin1" to be an input
pinMode (pin2, OUTPUT); // Sets "pin2" to be an output
Serial.begin(9600); // Sets the baudrate to 9600
}
void loop() {
// put your main code here, to run repeatedly:
if(analogRead(Ipin1 > 500)) { // I also tried "if(analogRead(Ipin1 == HIGH))", it does the same thing. (also tried < and "LOW")
digitalWrite(pin2, HIGH); // If the above statement is true, set pin2 to output 5 volts
delay(2000); // Pauses the program for 2 seconds
Serial.print("AnalogPin1 was given a signal "); // Provides some kind of feedback for the serial monitor
digitalWrite(pin2, LOW); // Turns off the output of pin 2
}
"will not work" conveys no useful information. The code does something, what does it do?
Look at that statement very carefully comparing it to the syntax for the analogRead() function and the if structure. Note, especially, the placements of the parenthesis.
Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum. Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
@daveypoo48, I'm not sure why you think that this relates to Avrdude, stk500 or Bootloader issues and hence your topic has been moved to a more suitable location on the forum.
Please read the post at the start of any forum , entitled "How to use this Forum".
This will help with advice on how to present your code and problems.
The 5volts input, is it 0V then 5V, if so then you can use a faster digital input.
0V = Low or False, 5V = HIGH or True.
The Arduinos that are supplying the signal would probably be digital outputs.
// I am using an Elegoo Mega 2560
// I need the board to receive 5 volts on the analog input pins, and then output 5 volts to specific output pins.
// No matter what I do, this will not work. Not sure if I somehow fried my board maybe?
int Ipin1 = A1;
int pin2 = 2;
void setup()
{
// pinMode(Ipin1, INPUT);
pinMode(pin2, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (analogRead(Ipin1) > 500) // About 2.44V or higher
{
Serial.println("AnalogPin1 was given a signal ");
digitalWrite(pin2, HIGH);
delay(2000);
digitalWrite(pin2, LOW);
}
}
Why use an analogue read and not a digital read?
Because your code is in a loop then once the signal has gone high and the output has gone high and then low again, then if the input is still high the output will immediately go high again. In other words you will never see the low signal.
On the face of it you don't need a processor just connect your inputs to your outputs.
Sorry about the format of the code; In my experience, using the apostrophe button would automatically format my code on other websites. Regardless, I made that mistake, it was my fault, I should have double checked the formatting before I posted.
I was able to make the code work, I appreciate your help with pointing out my parentheses mistake.
I am only just now figuring out the sad realization that the Elegoo Mega cannot receive more than 1 input at the same time. Am I correct in that realization?
The outputs from the Elegoo go to 100 different relays. This system is acting as a simple controller.
Can you please give a detailed description of your project; this should include examples of the data that you send from the PC to the Uno and what the expected output on the Mega would be.
The Uno code would be useful as well to help us understand.
I suspect that the GUI e.g. sends 5, the Uno translates this to e.g. 5 on the output pins, the Mega reads this and sets a specific output HIGH.
Hi,
You can't use pin1 of the UNOs, that and pin 0 are the programming I/O.
Have you got 100 drivers for the relays?
Why not use I/O expanders for your two Megas.
At the moment you have 3 lots of code.
If you use one controller, UNO or Nano, and a series of port expanders you only need ONE code.
Tom....
PS. This sounds like a piece of performance, kinetic art.
A very simple GUI, coded in Python, tells the Arduino which digital pins to set to HIGH. I am only using digital pins 2-13 on the Arduino (12 in total). THIS MEANS THAT THE ARDUINO IS SENDING A CONSTANT 5 VOLTS VIA THE DIGITAL OUTPUTS, FOR ABOUT 1 SECOND EACH.
Digital outputs 2-7 are sent to the first Elegoo Board. Digital outputs 8-13 are sent to the second Elegoo Board.
The original problem I faced was the Elegoo not reading the 5 volt input from the arduino. I have already fixed that problem.
Now, my question is, can the Elegoo boards receive more than one input from the arduino at the same time?