نمونه کد آردوینو:
CodeSimple code example that reads the value at A0 and outputs the results via the serial monitor, if you use 5v rather than 3.3v then you will need to change the 3.3 in the following line
sensorVoltage = sensorValue/1024*3.3;[CODE]
کد:
void setup()
{
Serial.begin(9600);
}
void loop()
{
float sensorVoltage;
float sensorValue;
sensorValue = analogRead(A0);
sensorVoltage = sensorValue/1024*3.3;
Serial.print("sensor reading = ");
Serial.print(sensorValue);
Serial.println("");
Serial.print("sensor voltage = ");
Serial.print(sensorVoltage);
Serial.println(" V");
delay(1000);
}
نتایج خروجی :
TestingOpen the serial monitor and look at the readingssensor reading = 46.00
sensor voltage = 0.15 V
sensor reading = 46.00
sensor voltage = 0.15 V
sensor reading = 46.00
sensor voltage = 0.15 V
sensor reading = 46.00
sensor voltage = 0.15 V
sensor reading = 46.00
sensor voltage = 0.15 V
رفرنس:
Arduino and GUVA-S12SD UV Sensor - Arduino Learning