code for pulse generation using arduino uno

Hi,

Can someone please help me out with the code for pulse generation using arduino, where the pulse width vary with the voltage that is connected to a battery :confused: I Basically want to represent the battery's status based on the width of the pulse. like in, if the battery has 6v initially then the width of the pulse is displayed in the CRO and if the battery is charged then the increased width have to be displayed accordingly, really need halp with this :confused: Thank You in adance :slight_smile:

You don't need an arduino for this:-
http://www.falstad.com/circuit/e-555pulsemod.html

Thankyou for the reply ....Is there any way to make the arduino uno board read the variable pulsewidths from the 555 timer circuit ie interfacing the 555timer with the arduino uno board??
Please help

You can use the pulseIn() function to read the width of the pulse from 555 in microseconds. The reference has information on the puseIn() function.

What advantage do you expect to see in a pulse measurement vs an analogRead of the battery voltage?

some code to get started.

void setup() 
{
  Serial.begin(115200);
  Serial.println("Start ");
}

void loop() 
{
  int raw = analogRead(A0);
  uint8_t width = convert(raw);
  analogWrite(9, width);
  
  Serial.print(raw);
  Serial.print("\t");
  Serial.println(width);
  delay(100);
}

uint8_t convert(int val)
{
  return (1023 - val)*(1023 - val)/4096; // replace with a formula you like
}

check multimap() to make a non linear mapping of voltageIn to PulseOut.

CrossRoads:
What advantage do you expect to see in a pulse measurement vs an analogRead of the battery voltage?

It answers his homework question?