```cpp
const int sensorPin = A0; // Analog input pin
int relayPin = A1; // Digital output pin that tiggers relay
int sensorValue = 0; // sensorPin default value
float Vin = 5; // Input voltage
float Vout = 0; // Vout default value
float Rref = 1000000; // Reference resistor's value in ohms (you can give this value in kiloohms or megaohms - the resistance of the tested resistor will be given in the same units)
float R = 0; // Tested resistors default value
void setup ()
{
Serial.begin(9600); // Initialize serial communications at 9600 bps
}
void loop ()
{
sensorValue = analogRead(sensorPin); // Read Vout on analog input pin A0 (Arduino can sense from 0-1023, 1023 is 5V)
if (sensorValue < 800)
analogWrite(relayPin, 200);
if (sensorValue > 800)
analogWrite(relayPin, 0);
}
Now, I need to add another timer/relay module that will be activated using the same output signal. I tried to use the A1 output common to both timer/relay modules, but these modules started clicking erratically. Thinking this was too much of a power draw, I created another relayPin and assigned it to A3 (below), which I would use for the added timer/relay. The only change is int relayPin = A1 and A3. It didn't work because the original relay no longer worked. I admit I know next to nothing about making these codes, and I feel pretty stupid, but I am in the process of learning more.
const int sensorPin = A0; // Analog input pin
int relayPin = A1 and A3; // Analog output pin that tiggers relays
int sensorValue = 0; // sensorPin default value
float Vin = 5; // Input voltage
float Vout = 0; // Vout default value
float Rref = 1000000; // Reference resistor's value in ohms (you can give this value in kiloohms or megaohms - the resistance of the tested resistor will be given in the same units)
float R = 0; // Tested resistors default value
void setup ()
{
Serial.begin(9600); // Initialize serial communications at 9600 bps
}
void loop ()
{
sensorValue = analogRead(sensorPin); // Read Vout on analog input pin A0 (Arduino can sense from 0-1023, 1023 is 5V)
if (sensorValue < 800)
analogWrite(relayPin, 200);
if (sensorValue > 800)
analogWrite(relayPin, 0);
}
Is this a reasonable approach, and if so, how do I create another relayPin?
Do you understand what an analogWrite to an analogue pin gives you?
EDIT:-
On an Nano every if you write anything higher that 127 then you will get about 4.7V, otherwise you will get nothing.
What do you think this does?
You might think it does, but no one agrees with you on that thread. I think you are fooling yourself.
I will keep the original timer/relay on A1 and then the additional one hooked to A3. I tried this below:
```cpp
const int sensorPin = A0; // Analog input pin
int relayPin = A1; // Digital output pin that tiggers relay
int relayPin2 = A3;
int sensorValue = 0; // sensorPin default value
float Vin = 5; // Input voltage
float Vout = 0; // Vout default value
float Rref = 1000000; // Reference resistor's value in ohms (you can give this value in kiloohms or megaohms - the resistance of the tested resistor will be given in the same units)
float R = 0; // Tested resistors default value
void setup ()
{
Serial.begin(9600); // Initialize serial communications at 9600 bps
}
void loop ()
{
sensorValue = analogRead(sensorPin); // Read Vout on analog input pin A0 (Arduino can sense from 0-1023, 1023 is 5V)
if (sensorValue < 800)
analogWrite(relayPin, 150);
analogWrite(relayPin2, 150);
if (sensorValue > 800)
analogWrite(relayPin, 0);
analogWrite(relayPin2, 0);
}
The A1 still works (goes from 1 mV to 4.6V), but the A3 goes from 490 mV to about 250 mV weird. I changed the program to relayPin2 = A4 and the A4 pin had the same voltage change.
I will keep the original timer/relay on A1 and then the additional one hooked to A3. I tried this below:
```cpp
const int sensorPin = A0; // Analog input pin
int relayPin = A1; // Digital output pin that tiggers relay
int relayPin2 = A3;
int sensorValue = 0; // sensorPin default value
float Vin = 5; // Input voltage
float Vout = 0; // Vout default value
float Rref = 1000000; // Reference resistor's value in ohms (you can give this value in kiloohms or megaohms - the resistance of the tested resistor will be given in the same units)
float R = 0; // Tested resistors default value
void setup ()
{
Serial.begin(9600); // Initialize serial communications at 9600 bps
}
void loop ()
{
sensorValue = analogRead(sensorPin); // Read Vout on analog input pin A0 (Arduino can sense from 0-1023, 1023 is 5V)
if (sensorValue < 800)
analogWrite(relayPin, 150);
analogWrite(relayPin2, 150);
if (sensorValue > 800)
analogWrite(relayPin, 0);
analogWrite(relayPin2, 0);
}
The A1 still works (goes from 1 mV to 4.6V), but the A3 goes from 490 mV to about 250 mV weird. I changed the program to relayPin2 = A4 and the A4 pin had the same voltage change.