Question: I want to write an Arduino Uno code that firstly measures the input voltage with voltage sensor. After that, if the voltage is not between

I want to write an Arduino Uno code that firstly measures the input voltage with voltage sensor. After that, if the voltage is not between 20 - 22 V, decrease or increase the duty cycle of MOSFET until the voltage becomes in the range of 20-22 V. I want to write an Arduino Uno code that firstly measures theHere is my code, can anyone rewrite or fix it?

int analogInput = Al; #define PWM_out 6 float vout = 0.0; float vin= 0.0; float R1 = 30000.0; float R2 = 7500.0; int value = 0; int pwm_value = 0; void setup() { pinMode (analogInput, INPUT); Serial.begin (9600); Serial.println("BASIC DC VOLTMETER"); } void loop() { // read the value at analog input value = analogRead(analogInput); vout = (value * 5.0) / 1024.0; vin = vout / (R2/ (R1+R2)); if(vin > 22) { pwm_value --; pwm_value = constrain (pwm_value, 0, 255); } if (vin =20 && vin 22) { pwm_value --; pwm_value = constrain (pwm_value, 0, 255); } if (vin =20 && vin

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!