Question

Embedded Systems Project Assignment 02 Connect a potentiometer and a LDR to your Arduino board. Using an H bridge connect a D
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Arduino Code:

#include <LiquidCrystal.h>

#define pot A0
#define LDR A1

#define input1 8
#define input2 9
#define pwm 10

float Pot_val = 0;
float LDR_val = 0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
pinMode(pot, INPUT);
pinMode(LDR, INPUT);
pinMode(input1, OUTPUT);
pinMode(input2, OUTPUT);
pinMode(pwm, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
}

void loop()
{
Pot_val = analogRead(pot) / 1023 * 255;
analogWrite(pwm, Pot_val);
  
lcd.setCursor(0, 0);
lcd.print("speed:");
lcd.setCursor(7, 0);
lcd.print(Pot_val / 255 * speed_max);
  
LDR_val = analogRead(LDR) / 1023 * 10;
lcd.setCursor(11, 0);
lcd.print("Dir:");
if (LDR_val > 5)
{
digitalWrite(input1, 1);
digitalWrite(input2, 0);
lcd.setCursor(0, 1);
lcd.print("Clockwise");
}
else if (LDR_val < 5)
{
digitalWrite(input1, 0);
digitalWrite(input2, 1);
lcd.setCursor(0, 1);
lcd.print("Anti-Clockwise");
}
}

Add a comment
Know the answer?
Add Answer to:
Embedded Systems Project Assignment 02 Connect a potentiometer and a LDR to your Arduino board. Using...
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