Arduino Mega_ADK ADC

Source: Internet
Author: User

[Csharp]
/*************************************** **************************
** Program name: Mega_ADK ADC
** Parameter count: None
** Function: Send the voltage value (mv) collected by AD through the serial port)
** Note: The target board is Maga adk and the mcu is ATmega 2560.
** Author: Zhao Lulu
** Version: v1.0
** Modification time: 2012.8.17
**************************************** **************************/
# Define adPin A0
Void setup ()
{
Serial. begin (115200); <span style = "white-space: pre"> </span> // set the baud rate
}
Void loop ()
{
Int n = analogRead (adPin); <span style = "white-space: pre"> </span> // read the value of the simulation port, because the accuracy of ATmega 2560 AD is 10 bits, the returned value range is 0 ~ 1023
N = n * 4.888; <span style = "white-space: pre"> </span> // converts the returned value to A millivolt value.
Serial. print ("The Voltage Value is (mv ):");
Serial. println (n, DEC); <span style = "white-space: pre"> </span> // DEC sets the output data format here, which can be omitted here, see http://kb.open.eefocus.com/index.php for details? Title = Serial
Delay (100 );
}
Note: Because the accuracy of ATmega 2560 AD is 10 bits, the returned value range is 0 ~ 1023, corresponding to 0 ~ 5 V, calculate the actual voltage based on the collection value, 5000 Gb/s 1024 ≈ 4.888, So multiply the acquisition value by 4.888 to get the actual voltage value (ml V ).
If you are a newbie, please correct me.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.