Question

Write an Arduino program to continuously read the value of pin A1. The program lights up...

Write an Arduino program to continuously read the value of pin A1. The program lights up an LED connected to pin 5 if the value of A1 is greater than 300. If the value of A1 is less than 50, the program lights up an LED connected to pin 10.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:


int ledPin1 = 5;   //Declaring Digital pin 5 as reference variable 'ledPin1'
int ledPin2 = 10;   //Declaring Digital pin 10 as reference variable 'ledPin2'
int analogPin = 1;   //Declaring analog pin A1 as reference variable 'analogPin'
int val = 0;   //to store analog pin values
void setup()
{
Serial.begin(9600); // setup serial communication
//set ledPin1 and ledPin2 as outputs
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}

void loop()
{
   val = analogRead(analogPin);   //Read the data from the pin
   //switching on LED1
   if(val > 300){
       digitalWrite(ledPin1, HIGH);
   }
   //switching on LED2
   else if(val < 50){
       digitalWrite(ledPin2, HIGH);
   }
   //put a delay of 1 second, remove it if not necessary
   delay(1000);
}

Add a comment
Know the answer?
Add Answer to:
Write an Arduino program to continuously read the value of pin A1. The program lights up...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT