Moin,
I am looking for some guidance on the data returned from analogRead().
Photos: https://github.com/Potatoconomy/Relay-Photos/tree/master
Briefly, my goal is to test circuit switching of a relay (G6A) that is controlled by the Arduino Uno. To do this, I breadboarded together a voltage divider that returns a different voltage into A5 depending on which circuit in the relay is connected. I read these voltage changes in the form of a binary message I send through that controls the switch state of the relay.
see link for photo
I also measured this output with an oscilloscope. A relay has a small period of time where the lever needs to switch, creating a momentary open circuit in the board. Here, all 5V should be going through A5 and the scope probe to the GND (So Serial data will be 1023). According to the datasheet, this time period is maximum of 5ms. With the scope, I measured 2.5ms.
see link for photo
However, recording with the Arduino, I need to have at least delay(7) following turning the Relay circuit on in order to not measure values of 1023.
see link for photo
The above photo can be compared to the delay(5) shown below, where the open circuit points are visible.
see link for photo
Any ideas what is going on?
PS: Sorry for not having embedded photos. I had it really prettily formatted, but Arduino Forums does not allow new users to embed photos. Hence the Github Repo for a better format.
https://github.com/Potatoconomy/Relay-Photos/tree/master
//======
const int COIL_PIN = 2;
const int TOP_DATA_PIN = A5;
const int MESSAGE_SIZE = 10;
const boolean MESSAGE[10] = {1, 1, 1, 1, 0, 0, 1, 0, 0, 0};
//=======
void setup() {
Serial.begin(9600);
pinMode(COIL_PIN, OUTPUT);
}
//=======
void loop() {
analogReference(DEFAULT); // 5.0V - 4.9mV resolution
int i;
for (i = 0; i < MESSAGE_SIZE; i++) {
write_bit(COIL_PIN, MESSAGE[i]);
}
}
//=======
void write_bit(int pin_number, boolean current_bit) {
// Writes HIGH or LOW to corresponding pin
digitalWrite(pin_number, current_bit);
delay(7); // Relay requires 5ms switching time, actually only needs 2.5ms according to scope
get_analog(TOP_DATA_PIN, 10);
}
//=======
void get_analog(int pin_number, int n_print) {
// Reads analog data from selected pin and records it.
int i;
for (i = 0; i < n_print; i++) {
Serial.println(analogRead(pin_number));
}
}
//======





