0% found this document useful (0 votes)
31 views1 page

Arduino Sketch

This Arduino sketch reads an analog value from a pin, uses it to control the brightness of an LED, and prints messages to describe the reading. It sets up an analog input pin and LED output pin, then in a loop it reads the analog value, converts it to a voltage, prints it, and uses if/else statements to check the voltage and set the LED brightness accordingly, printing different messages based on the voltage range, with a delay between loops. The goal is to help beginners learn how to use analog readings to control an output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

Arduino Sketch

This Arduino sketch reads an analog value from a pin, uses it to control the brightness of an LED, and prints messages to describe the reading. It sets up an analog input pin and LED output pin, then in a loop it reads the analog value, converts it to a voltage, prints it, and uses if/else statements to check the voltage and set the LED brightness accordingly, printing different messages based on the voltage range, with a delay between loops. The goal is to help beginners learn how to use analog readings to control an output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

The following program describes how to write an arduino sketch to read an

analog value then use it to control the brightness of an LED :

int readPin=A0;
int ledPin=12;
int waitT=750;
float Vr=0.0;
String mess1="Vr is greater than 2.5v and less than 3.5";
String mess2="Vr is greater than 3.5";
String mess3="Vr is less than 2.5v";

void setup() {
// put your setup code here, to run once:
pinMode(readPin,INPUT);
pinMode(ledPin,OUTPUT);
Serial.begin(9600);

void loop() {
// put your main code here, to run repeatedly:
Vr=float(analogRead(readPin))*5.0/1023.0;
Serial.println(Vr);

if (Vr>2.5 && Vr<3.5)


{
Serial.println(mess1);
digitalWrite(ledPin, HIGH);
}
else if(Vr>3.5)
{
Serial.println(mess2);
digitalWrite(ledPin,LOW);
}
else Serial.println(mess3);

delay(waitT);

I hope it is helpful to beginners in arduino.

You might also like