Arduino's analog signal input - voltage test

Arduino can use digital and analog signals for input and output.

The digital signal has only two values, the high voltage 1 and the low voltage 0.

Digital signal input and output are

pinModde(pin,mode);
int value=digitalRead(pin);//Input the signal of this interface
int value=digitalWrite(pin,HIGH);//Input high level

where pin is the pin, which can be defined before as

int pin=4;

Then mode is the mode of the pin, there are three kinds of OUTPUT, INPUT, INPUT_PULLUP

Among them, INPUT_PULLUP is the input voltage pull-up. If the pull-up is not set, and there is no fixed voltage in the current state, its voltage will change irregularly. The voltage pull-up is to change the pin to high voltage mode when there is no fixed voltage.

The input and output of the analog signal are

int value=analogRead(pin);//Input the signal of this interface
int value=analogWrite(pin);//Output signal

The input of the analog signal is the five ports of ANALOG IN on the Arduino development board; the output of the analog signal is not actually an analog signal. Instead, it approximates the analog input in a special way. This method is called Pulse Width Modulation (PWM, Pulse Width Modulation). In the Arduino UNO, the pins that provide this are 3, 5, 6, 9, 10, 11.


Then here is a practical example of signal input and output

From digital signal output, then analog signal input.

The circuit is as follows




The Arduino program is as follows

int in=4;
int out=A1;
                   
void setup() {
 pinMode(in,OUTPUT);
 pinMode(out,INPUT);
 Serial.begin(9600); //Open the serial port and set the baud rate to 9600bps
 delay(1000);
}

void loop() {
 digitalWrite(in,HIGH); //First make the input high, which is 5v
 delay(1000);
 int value=0; //The defined value is 0, or it can be defined at the beginning of the program
 value=analogRead(out); //Make the value of analog signal input value value
 float val=value*(5.0/1023.0); //Since the value of the analog signal input is a value from 0 to 1023, that is, a value from 0 to 5v, you can convert it here
 Serial.println(val); //What is the level of the output point
 delay(1000);
 digitalWrite(in,LOW); //When the input is low, it is 0v
 delay(1000);
 value=analogRead(out);
 val=value*(5.0/1023.0);
 Serial.println(val);
 delay(1000);
}

Before the analog signal pin can be connected to the second and third sum resistors, it will be a different level situation from the above.

When connected before the first resistor, the input analog voltage alternates between 5v and 0v.

When connected to the third resistor, the input analog voltage is 0v.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324414173&siteId=291194637