last day (16 days later) » 

08:12
-1
Q: Using 1.1Vf to read stable battery voltage and sensor voltage

electro_nooobbbbAfter several tries, i was successful with reading stable battery voltage using internal voltage reference of 1.1v, now the issue i face is that i cannot read stable sensor voltage, could you please let me know how can i read my sensor voltage? or do i need additional voltage divider (my sensor g...

Looking at your past posts, you are repeatedly using the wrong code and then asking why it doesn't work. Maybe you should search how the ADC work. The reading from sensorValue = analogRead(A0) is a value ranging from 0 to 1023, to convert it to a voltage, the formula is voltage = (sensorValue/Vref) * 1023, where Vref is the reference Voltage you are using, in this case, it is 1.1v. Furthermore, you can't get a correct sensorValue if your input at A0 is HIGHER than the Vref, you will get the wrong value!
@hcheung ok,understood. i will change now and update. before i do so please ans my question: 1) if i use vref as 1.1v, do i need to measure my battery voltage, will it affect the code in any way? because my system only requires sensor measurement that's it. i am following this link (electronoobs.com/eng_arduino_tut156.php) that says we need to measure battery voltage then we can use it with the sensor code. i will update you with the results please stay connected
Whether you want to measure and calibrate the Vref, it is +/-10% differences according to datasheet (I mentioned this already on my prefer answer, please read them). so that means the Vref could be in the range of 0.99 - 1.21v.
@hcheung Hi, please check the code above it displayed constant 0.00V. i have connected solar to a voltage divider that drops the voltage down to 0.85V.
In the schematic above the LDR has been used in place solar panel due to the unavailability of the component in the software.
internalReference should be '1.1` or the voltage you actually measured with a volt meter at Vref. What is the resistance of the LDR?
08:15
Hi
ldr as i said is just used because i dont have solar panel component in my software.
Yes, i did try with 1.1v as well, it is persistently showing me 0.00V
my solar panel is 6V, 30mA
Please check my schematic and code , i have posted it.
okay, so you want to measure the voltage of the solar panel. As I said, Vref is the VOTLAGE value, you need to change your internalReference value to 1.1, not the reading from the analogRead().
ADMUX |= B11000000;
int sensor = analogRead(A0);
ADCSRA |= B11000000;
while(bit_is_set(ADCSRA, ADSC));
float voltage = ADCL | (ADCH << 8);
voltage = (sensor /1.1)*1024;
Serial.println (voltage);
can u see error?
"ADMUX |= B11000000;
int sensor = analogRead(A0);
ADCSRA |= B11000000;
while(bit_is_set(ADCSRA, ADSC));
float voltage = ADCL | (ADCH << 8); "
Why are you keep repeating those code? this can be replaced by one line of analogRead(A0). and the output is not the "voltage"!
Please, please, please, try this:
ok,omg only this much was needed.
08:31
PLEASE, PLEASE, PLEASE, try this:
void loop() {
analogReference (INTERNAL);
float voltage = (analogRead(A0)/1.1)*1024;
Serial.println (voltage);
delay(1000);
}
this will give you the reading at the input of A0, to get the value of the solar panel, multiply it by 5.7.
void loop() {
analogReference (INTERNAL);
float voltage = (analogRead(A0)/1.1)*1024;
Serial.print (“voltage at A0:”);
Serial.println(voltage);
Serial.print (“Solar panel voltage:”);
Serial.print(voltage*5.7);
delay(1000);
}
189.00
189.00
190.00
190.00
190.00
190.00
190.00
190.00
190.00
190.00
190.00
190.00
190.00
189.00
190.00
serial monitor readings from your first code
ok i will try the second one.
Solar panel voltage:4791482.00voltage at A0:841541.81
Solar panel voltage:4796788.00voltage at A0:841541.81
Solar panel voltage:4796788.00voltage at A0:843403.62
Solar panel voltage:4807400.50voltage at A0:843403.62
Solar panel voltage:4807400.50voltage at A0:841541.81
Solar panel voltage:4796788.00voltage at A0:839680.00
Solar panel voltage:4786176.00voltage at A0:837818.18
Solar panel voltage:4775563.50voltage at A0:837818.18
Solar panel voltage:4775563.50voltage at A0:839680.00
Solar panel voltage:4786176.00voltage at A0:839680.00
Sorry, wrong formula, refer to my answer on arduino.stackexchange.com/a/92331/40646 for the correct formula.
from new code
void loop() {
analogReference (INTERNAL);
float voltage = 1.1/1023*analogRead(A0);
Serial.print (“voltage at A0:”);
Serial.println(voltage);
Serial.print (“Solar panel voltage:”);
Serial.println(voltage*5.7);
delay(1000);
}
08:46
hi
it does not change if light falls on it
the reading should increase
A0:0.99
Solar panel voltage:5.65
voltage at A0:0.99
Solar panel voltage:5.65
voltage at A0:0.99
Solar panel voltage:5.67
voltage at A0:1.01
Solar panel voltage:5.74
voltage at A0:1.01
Solar panel voltage:5.77
voltage at A0:1.01
Solar panel voltage:5.76
voltage at A0:1.01
Solar panel voltage:5.76
voltage at A0:1.01
Solar panel voltage:5.76
voltage at A0:1.01
Solar panel voltage:5.76
voltage at A0:1.01
Solar panel voltage:5.75
voltage at A0:1.01
Solar panel voltage:5.76
voltage at A0:1.01
Solar panel voltage:5.74
You connect the solar panel to the 5V from Arduino too?
even if i cover the full panel, it should read 0v if full covered
no i made voltage divider
4.7k and 1k and from the mid took one pin to A0
I'm not asking you voltage divider, read my question
so your Arduino supply 5V whether your solar panel work or not working, you already get 5V, isn't it?
08:50
one side to voltage divider goes to 5v and the other one two GND and to the same point i have connected solar panel.
5v where?
where do i need to connect it ?solar?
this is probably a question too much for you if you don't have an electronic background, you need to have a load sharing circuit so that when solar panel is not sufficient, it switch to the 5V or vice versa.
i am electronic engineer,i have completed my project but i am badly stuck in here.sorry
as far as reading the value of your existing diagram, the code works as expected.
so what do you say
my connections are right or wrong?
your current circuit can't really measure the solar panel out unless 5V is disconnected.
but since your 5V is always connected, it always give you the 5V reading
08:58
ok
.27
voltage at A0:1.10
Solar panel voltage:6.27
voltage at A0:1.10
Solar panel voltage:6.27
voltage at A0:1.10
Solar panel voltage:6.27
voltage at A0:0.39
Solar panel voltage:2.25
voltage at A0:1.10
Solar panel voltage:6.27
voltage at A0:1.10
Solar panel voltage:6.27
voltage at A0:1.10
Solar panel voltage:6.27
voltage at A0:1.10
Solar panel voltage:6.27
I disconnected 5v from the panel. Now the +side goes to one end of voltage divider and -side goes to GND side of the divider.
is it ok to leave the two ends of the solar open like that?
I have no idea what you are trying to accomplish, so can't comment on that...
ok
you tell me where do i need to connect solar panel
just that
sorry
hardware/electronics is neither hardware nor arduino specific, it is a question belong to electronics.stackexchange.com
sorry?
where should i connect the solar? we are reading A0 from a voltage divider that's correct code is also correct but where should i connect the solar?
If you only want to measure the solar panel, not the 5v, you can separate it using a diode and connect the voltage divider to the solar panel.
09:18
ok
i will give it a try
10:12
it does not work
Solar panel voltage:4.64
voltage at A0:0.82
Solar panel voltage:4.65
voltage at A0:0.82
Solar panel voltage:4.65
voltage at A0:0.81
Solar panel voltage:4.64
voltage at A0:0.81
Solar panel voltage:4.64
voltage at A0:0.82
Solar panel voltage:4.65
voltage at A0:0.82
Solar panel voltage:4.65
voltage at A0:0.81
Solar panel voltage:4.64
tested with diode
for testing purposes i connected potentiometre in place of solar panel and it works perfectly
but i dont understand what is the issue with solar panel
int sensorValue = analogRead(A0); // Solar Panel Positive PIN connect to A0
float voltage = sensorValue * (5.0 / 1023.0); as per my research in order to read solar voltage constant voltage supply is required
and i have already wrote a program that can read constant battery voltage the issue with that is, the moment i add solar code to battery code, it starts behaving abnormally.
10:38
void loop() {
//REFS1 AND REFS0 to 1 1 -> internal 1.1V refference
ADMUX |= B11000000;
//We read A1 (MUX0)
ADMUX |= B00000001;
// Start AD conversion
ADCSRA |= B11000000;
// Detect end-of-conversion
while (bit_is_set(ADCSRA,ADSC));
float val = ADCL | (ADCH << 8);
val = val * 5.7; //Multiply by the inverse of the divider
Serial.println(val);
}
This code reads constant voltage
11:07
void setup(){
Serial.begin(9600);
}

void loop() {



//REFS1 AND REFS0 to 1 1 -> internal 1.1V refference
ADMUX |= B11000000;
//We read A1 (MUX0)
ADMUX |= B00000001;
//int sensor = analogRead(A1);
// Start AD conversion
ADCSRA |= B11000000;
// Detect end-of-conversion
while (bit_is_set(ADCSRA,ADSC));
float val = ADCL | (ADCH << 8);
val = val * 5.7; //Multiply by the inverse of the divider
Serial.println(val);


float voltage = val * analogRead(A0) / 1023;
voltage = ADCL | (ADCH << 8);
Serial.print ("voltage at A0:");
Now i would try it for attiny

  last day (16 days later) »